Compare commits
22 Commits
tags/Spide
...
jsd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e99fb1da7b | ||
|
|
a4156ea8c1 | ||
|
|
4e17e7d0b6 | ||
|
|
0b9f4a6066 | ||
|
|
88e2efb86c | ||
|
|
f70c006cd2 | ||
|
|
2d43318eeb | ||
|
|
464cfb0128 | ||
|
|
ccd9fea75c | ||
|
|
adbbf081d4 | ||
|
|
087895e0d4 | ||
|
|
f53236bbe5 | ||
|
|
4525a93346 | ||
|
|
92ce8e0953 | ||
|
|
4f506cbcbc | ||
|
|
53fed9d6ad | ||
|
|
a7fb2e53b5 | ||
|
|
cddacc3fc7 | ||
|
|
6f925ed79a | ||
|
|
91ff9d9174 | ||
|
|
cb5c11135f | ||
|
|
d02f29a398 |
Binary file not shown.
316
mozilla/js/src/Makefile.ref
Normal file
316
mozilla/js/src/Makefile.ref
Normal file
@@ -0,0 +1,316 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
#
|
||||
# JSRef GNUmake makefile.
|
||||
#
|
||||
|
||||
# Set os+release dependent make variables
|
||||
OS_ARCH := $(subst /,_,$(shell uname -s))
|
||||
|
||||
# Attempt to differentiate between SunOS 5.4 and x86 5.4
|
||||
OS_CPUARCH := $(shell uname -m)
|
||||
ifeq ($(OS_CPUARCH),i86pc)
|
||||
OS_RELEASE := $(shell uname -r)_$(OS_CPUARCH)
|
||||
else
|
||||
ifeq ($(OS_ARCH),AIX)
|
||||
OS_RELEASE := $(shell uname -v).$(shell uname -r)
|
||||
else
|
||||
OS_RELEASE := $(shell uname -r)
|
||||
endif
|
||||
endif
|
||||
|
||||
# Virtually all Linux versions are identical.
|
||||
# Any distinctions are handled in linux.h
|
||||
ifeq ($(OS_ARCH),Linux)
|
||||
OS_CONFIG := Linux_All
|
||||
else
|
||||
ifeq ($(OS_ARCH),dgux)
|
||||
OS_CONFIG := dgux
|
||||
else
|
||||
OS_CONFIG := $(OS_ARCH)$(OS_OBJTYPE)$(OS_RELEASE)
|
||||
endif
|
||||
endif
|
||||
|
||||
ASFLAGS =
|
||||
DEFINES =
|
||||
|
||||
#NS_USE_NATIVE = 1
|
||||
|
||||
include config/$(OS_CONFIG).mk
|
||||
|
||||
ifdef BUILD_OPT
|
||||
OPTIMIZER += -O
|
||||
DEFINES += -UDEBUG -DNDEBUG -UDEBUG_$(shell whoami)
|
||||
OBJDIR_TAG = _OPT
|
||||
else
|
||||
ifdef USE_MSVC
|
||||
OPTIMIZER = -Zi
|
||||
else
|
||||
OPTIMIZER = -g
|
||||
endif
|
||||
DEFINES += -DDEBUG -DDEBUG_$(shell whoami)
|
||||
OBJDIR_TAG = _DBG
|
||||
endif
|
||||
|
||||
#DEFINES += -DJS_THREADSAFE
|
||||
|
||||
ifdef JS_NO_THIN_LOCKS
|
||||
DEFINES += -DJS_USE_ONLY_NSPR_LOCKS
|
||||
endif
|
||||
|
||||
# Name of the binary code directories
|
||||
OBJDIR = $(OS_CONFIG)$(OBJDIR_TAG).OBJ
|
||||
VPATH = $(OBJDIR)
|
||||
|
||||
# Automatic make dependencies file
|
||||
DEPENDENCIES = $(OBJDIR)/.md
|
||||
|
||||
define MAKE_OBJDIR
|
||||
if test ! -d $(@D); then rm -rf $(@D); mkdir $(@D); fi
|
||||
endef
|
||||
|
||||
# Look in OBJDIR to find prcpucfg.h
|
||||
INCLUDES = -I$(OBJDIR)
|
||||
|
||||
#
|
||||
# XCFLAGS may be set in the environment or on the gmake command line
|
||||
#
|
||||
CFLAGS = $(OPTIMIZER) $(OS_CFLAGS) $(DEFINES) $(INCLUDES) \
|
||||
-DJSFILE $(XCFLAGS)
|
||||
LDFLAGS = -lm $(XLDFLAGS)
|
||||
|
||||
#
|
||||
# Ask perl what flags it was built with, so we can build js with similar flags
|
||||
# and link properly. Viva gmake.
|
||||
#
|
||||
ifdef PERLCONNECT
|
||||
DEFINES += -DPERLCONNECT
|
||||
|
||||
PERLCFLAGS := $(shell perl -MExtUtils::Embed -e ccopts)
|
||||
PERLLDFLAGS := $(shell perl -MExtUtils::Embed -e ldopts)
|
||||
|
||||
CFLAGS += $(PERLCFLAGS)
|
||||
LDFLAGS += $(PERLLDFLAGS)
|
||||
endif
|
||||
|
||||
# For purify
|
||||
PURE_CFLAGS = -DXP_UNIX $(OPTIMIZER) $(PURE_OS_CFLAGS) $(DEFINES) \
|
||||
$(INCLUDES) $(XCFLAGS)
|
||||
|
||||
#
|
||||
# JS file lists
|
||||
#
|
||||
JS_HFILES = \
|
||||
jsarray.h \
|
||||
jsatom.h \
|
||||
jsbool.h \
|
||||
jsconfig.h \
|
||||
jscntxt.h \
|
||||
jsdate.h \
|
||||
jsemit.h \
|
||||
jsexn.h \
|
||||
jsfun.h \
|
||||
jsgc.h \
|
||||
jsinterp.h \
|
||||
jslock.h \
|
||||
jsmath.h \
|
||||
jsnum.h \
|
||||
jsobj.h \
|
||||
jsopcode.h \
|
||||
jsparse.h \
|
||||
jsarena.h \
|
||||
jsclist.h \
|
||||
jsdtoa.h \
|
||||
jshash.h \
|
||||
jslong.h \
|
||||
jsmacos.h \
|
||||
jsosdep.h \
|
||||
jspcos.h \
|
||||
jsprintf.h \
|
||||
jstime.h \
|
||||
jstypes.h \
|
||||
jsprvtd.h \
|
||||
jspubtd.h \
|
||||
jsregexp.h \
|
||||
jsscan.h \
|
||||
jsscope.h \
|
||||
jsscript.h \
|
||||
jsstr.h \
|
||||
jsxdrapi.h \
|
||||
$(NULL)
|
||||
|
||||
API_HFILES = \
|
||||
jsapi.h \
|
||||
jsdbgapi.h \
|
||||
$(NULL)
|
||||
|
||||
HFILES = $(JS_HFILES) $(API_HFILES)
|
||||
|
||||
JS_CFILES = \
|
||||
jsapi.c \
|
||||
jsarray.c \
|
||||
jsatom.c \
|
||||
jsbool.c \
|
||||
jscntxt.c \
|
||||
jsdate.c \
|
||||
jsdbgapi.c \
|
||||
jsemit.c \
|
||||
jsexn.c \
|
||||
jsfun.c \
|
||||
jsgc.c \
|
||||
jsinterp.c \
|
||||
jslock.c \
|
||||
jsmath.c \
|
||||
jsnum.c \
|
||||
jsobj.c \
|
||||
jsopcode.c \
|
||||
jsparse.c \
|
||||
jsarena.c \
|
||||
jsdtoa.c \
|
||||
jshash.c \
|
||||
jslog2.c \
|
||||
jslong.c \
|
||||
jsprf.c \
|
||||
jsregexp.c \
|
||||
jsscan.c \
|
||||
jsscope.c \
|
||||
jsscript.c \
|
||||
jsstr.c \
|
||||
jsutil.c \
|
||||
jsxdrapi.c \
|
||||
prmjtime.c \
|
||||
$(NULL)
|
||||
|
||||
ifdef PERLCONNECT
|
||||
JS_CFILES += jsperl.c
|
||||
endif
|
||||
|
||||
LIB_CFILES = $(JS_CFILES)
|
||||
LIB_ASFILES := $(wildcard *_$(OS_ARCH).s)
|
||||
PROG_CFILES = js.c
|
||||
|
||||
ifdef USE_MSVC
|
||||
LIB_OBJS = $(addprefix $(OBJDIR)/, $(LIB_CFILES:.c=.obj))
|
||||
PROG_OBJS = $(addprefix $(OBJDIR)/, $(PROG_CFILES:.c=.obj))
|
||||
else
|
||||
LIB_OBJS = $(addprefix $(OBJDIR)/, $(LIB_CFILES:.c=.o))
|
||||
LIB_OBJS += $(addprefix $(OBJDIR)/, $(LIB_ASFILES:.s=.o))
|
||||
PROG_OBJS = $(addprefix $(OBJDIR)/, $(PROG_CFILES:.c=.o))
|
||||
endif
|
||||
|
||||
CFILES = $(LIB_CFILES) $(PROG_CFILES)
|
||||
OBJS = $(LIB_OBJS) $(PROG_OBJS)
|
||||
|
||||
ifdef USE_MSVC
|
||||
LIBRARY = $(OBJDIR)/js32.dll
|
||||
PROGRAM = $(OBJDIR)/js
|
||||
else
|
||||
LIBRARY = $(OBJDIR)/libjs.a
|
||||
PROGRAM = $(OBJDIR)/js
|
||||
endif
|
||||
|
||||
ifdef USE_MSVC
|
||||
TARGETS = $(LIBRARY) # $(PROGRAM) not supported for MSVC yet
|
||||
else
|
||||
TARGETS = $(LIBRARY) $(PROGRAM)
|
||||
endif
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJS)
|
||||
|
||||
clobber:
|
||||
rm -rf $(OBJS) $(TARGETS) $(DEPENDENCIES)
|
||||
|
||||
depend:
|
||||
gcc -MM $(CFLAGS) $(JS_CFILES)
|
||||
|
||||
$(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
|
||||
|
||||
# windows only
|
||||
$(OBJDIR)/%.obj: %.c
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CC) -Fo$(OBJDIR)/ -c $(CFLAGS) $*.c
|
||||
|
||||
ifeq ($(OS_ARCH),OS2)
|
||||
$(LIBRARY): $(LIB_OBJS)
|
||||
$(AR) $@ $? $(AR_OS2_SUFFIX)
|
||||
$(RANLIB) $@
|
||||
else
|
||||
ifdef USE_MSVC
|
||||
$(LIBRARY): $(LIB_OBJS)
|
||||
link.exe $(LIB_LINK_FLAGS) /base:0x61000000 \
|
||||
/out:"$@" /pdb:"$(OBJDIR)/js32.pdb" /implib:"$(OBJDIR)/js32.lib" $?
|
||||
else
|
||||
$(LIBRARY): $(LIB_OBJS)
|
||||
$(AR) rv $@ $?
|
||||
$(RANLIB) $@
|
||||
endif
|
||||
endif
|
||||
|
||||
#NSPR_LIBRARY = ../../dist/$(OBJDIR)/lib/libnspr21.so
|
||||
NSPR_LIBRARY =
|
||||
|
||||
$(PROGRAM): $(PROG_OBJS) $(LIBRARY)
|
||||
$(CC) -o $@ $(CFLAGS) $(PROG_OBJS) $(LIBRARY) $(NSPR_LIBRARY) $(LDFLAGS)
|
||||
|
||||
$(PROGRAM).pure: $(PROG_OBJS) $(LIBRARY)
|
||||
purify $(PUREFLAGS) \
|
||||
$(CC) -o $@ $(PURE_OS_CFLAGS) $(PROG_OBJS) $(LIBRARY) $(LDFLAGS)
|
||||
|
||||
$(HFILES) $(CFILES): $(OBJDIR)/jscpucfg.h
|
||||
|
||||
ifdef PREBUILT_CPUCFG
|
||||
$(OBJDIR)/jscpucfg.h: jscpucfg.h
|
||||
cp jscpucfg.h $(OBJDIR)
|
||||
else
|
||||
$(OBJDIR)/jscpucfg.h: $(OBJDIR)/jscpucfg
|
||||
rm -f $@
|
||||
$(OBJDIR)/jscpucfg > $@
|
||||
|
||||
$(OBJDIR)/jscpucfg: $(OBJDIR)/jscpucfg.o
|
||||
$(CC) -o $@ $(OBJDIR)/jscpucfg.o
|
||||
endif
|
||||
|
||||
#
|
||||
# Hardwire dependencies on jsopcode.tbl
|
||||
#
|
||||
jsopcode.h jsopcode.c: jsopcode.tbl
|
||||
|
||||
-include $(DEPENDENCIES)
|
||||
|
||||
TARNAME = jsref.tar
|
||||
TARFILES = files `cat files`
|
||||
|
||||
tar:
|
||||
tar cvf $(TARNAME) $(TARFILES)
|
||||
gzip $(TARNAME)
|
||||
|
||||
SUFFIXES: .i
|
||||
%.i: %.c
|
||||
$(CC) -C -E $(CFLAGS) $< > $*.i
|
||||
37
mozilla/js/src/config/AIX4.1.mk
Normal file
37
mozilla/js/src/config/AIX4.1.mk
Normal file
@@ -0,0 +1,37 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for AIX
|
||||
#
|
||||
|
||||
CC = xlC_r
|
||||
CCC = xlC_r
|
||||
|
||||
RANLIB = ranlib
|
||||
|
||||
#.c.o:
|
||||
# $(CC) -c -MD $*.d $(CFLAGS) $<
|
||||
ARCH := aix
|
||||
CPU_ARCH = rs6000
|
||||
GFX_ARCH = x
|
||||
INLINES = js_compare_and_swap:js_fast_lock1:js_fast_unlock1:js_lock_get_slot:js_lock_set_slot:js_lock_scope1
|
||||
|
||||
OS_CFLAGS = -qarch=com -qinline+$(INLINES) -DXP_UNIX -DAIX -DAIXV3 -DSYSV
|
||||
OS_LIBS = -lbsd -lsvld -lm
|
||||
#-lpthreads -lc_r
|
||||
|
||||
37
mozilla/js/src/config/AIX4.2.mk
Normal file
37
mozilla/js/src/config/AIX4.2.mk
Normal file
@@ -0,0 +1,37 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for AIX
|
||||
#
|
||||
|
||||
CC = xlC_r
|
||||
CCC = xlC_r
|
||||
|
||||
RANLIB = ranlib
|
||||
|
||||
#.c.o:
|
||||
# $(CC) -c -MD $*.d $(CFLAGS) $<
|
||||
ARCH := aix
|
||||
CPU_ARCH = rs6000
|
||||
GFX_ARCH = x
|
||||
INLINES = js_compare_and_swap:js_fast_lock1:js_fast_unlock1:js_lock_get_slot:js_lock_set_slot:js_lock_scope1
|
||||
|
||||
OS_CFLAGS = -qarch=com -qinline+$(INLINES) -DXP_UNIX -DAIX -DAIXV3 -DSYSV
|
||||
OS_LIBS = -lbsd -lsvld -lm
|
||||
#-lpthreads -lc_r
|
||||
|
||||
48
mozilla/js/src/config/HP-UXB.10.10.mk
Normal file
48
mozilla/js/src/config/HP-UXB.10.10.mk
Normal file
@@ -0,0 +1,48 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for HPUX
|
||||
#
|
||||
|
||||
CC = gcc -Wall -Wno-format
|
||||
CCC = g++ -Wall -Wno-format
|
||||
|
||||
RANLIB = echo
|
||||
|
||||
#.c.o:
|
||||
# $(CC) -c -MD $*.d $(CFLAGS) $<
|
||||
|
||||
CPU_ARCH = hppa
|
||||
GFX_ARCH = x
|
||||
|
||||
OS_CFLAGS = -DXP_UNIX -DHPUX -DSYSV -D_SVID_GETTOD
|
||||
OS_LIBS = -ldld
|
||||
|
||||
ifeq ($(OS_RELEASE),B.10)
|
||||
PLATFORM_FLAGS += -DHPUX10 -Dhpux10
|
||||
PORT_FLAGS += -DRW_NO_OVERLOAD_SCHAR -DHAVE_MODEL_H
|
||||
ifeq ($(OS_VERSION),.10)
|
||||
PLATFORM_FLAGS += -DHPUX10_10
|
||||
endif
|
||||
ifeq ($(OS_VERSION),.20)
|
||||
PLATFORM_FLAGS += -DHPUX10_20
|
||||
endif
|
||||
ifeq ($(OS_VERSION),.30)
|
||||
PLATFORM_FLAGS += -DHPUX10_30
|
||||
endif
|
||||
endif
|
||||
48
mozilla/js/src/config/HP-UXB.11.00.mk
Normal file
48
mozilla/js/src/config/HP-UXB.11.00.mk
Normal file
@@ -0,0 +1,48 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for HPUX
|
||||
#
|
||||
|
||||
CC = gcc -Wall -Wno-format
|
||||
CCC = g++ -Wall -Wno-format
|
||||
|
||||
RANLIB = echo
|
||||
|
||||
#.c.o:
|
||||
# $(CC) -c -MD $*.d $(CFLAGS) $<
|
||||
|
||||
CPU_ARCH = hppa
|
||||
GFX_ARCH = x
|
||||
|
||||
OS_CFLAGS = -DXP_UNIX -DHPUX -DSYSV -D_SVID_GETTOD
|
||||
OS_LIBS = -ldld
|
||||
|
||||
ifeq ($(OS_RELEASE),B.10)
|
||||
PLATFORM_FLAGS += -DHPUX10 -Dhpux10
|
||||
PORT_FLAGS += -DRW_NO_OVERLOAD_SCHAR -DHAVE_MODEL_H
|
||||
ifeq ($(OS_VERSION),.10)
|
||||
PLATFORM_FLAGS += -DHPUX10_10
|
||||
endif
|
||||
ifeq ($(OS_VERSION),.20)
|
||||
PLATFORM_FLAGS += -DHPUX10_20
|
||||
endif
|
||||
ifeq ($(OS_VERSION),.30)
|
||||
PLATFORM_FLAGS += -DHPUX10_30
|
||||
endif
|
||||
endif
|
||||
58
mozilla/js/src/config/IRIX.mk
Normal file
58
mozilla/js/src/config/IRIX.mk
Normal file
@@ -0,0 +1,58 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for IRIX
|
||||
#
|
||||
|
||||
CPU_ARCH = mips
|
||||
GFX_ARCH = x
|
||||
|
||||
RANLIB = /bin/true
|
||||
|
||||
#NS_USE_GCC = 1
|
||||
|
||||
ifdef NS_USE_GCC
|
||||
CC = gcc
|
||||
CCC = g++
|
||||
AS = $(CC) -x assembler-with-cpp
|
||||
ODD_CFLAGS = -Wall -Wno-format
|
||||
ifdef BUILD_OPT
|
||||
OPTIMIZER = -O6
|
||||
endif
|
||||
else
|
||||
ifeq ($(OS_RELEASE),6.2)
|
||||
CC = cc -32 -DIRIX6_2
|
||||
endif
|
||||
ifeq ($(OS_RELEASE),6.3)
|
||||
CC = cc -32 -DIRIX6_3
|
||||
endif
|
||||
CCC = CC
|
||||
ODD_CFLAGS = -fullwarn -xansi
|
||||
ifdef BUILD_OPT
|
||||
OPTIMIZER += -Olimit 4000
|
||||
endif
|
||||
endif
|
||||
|
||||
# For purify
|
||||
HAVE_PURIFY = 1
|
||||
PURE_OS_CFLAGS = $(ODD_CFLAGS) -DXP_UNIX -DSVR4 -DSW_THREADS -DIRIX
|
||||
|
||||
OS_CFLAGS = $(PURE_OS_CFLAGS) -MDupdate $(DEPENDENCIES)
|
||||
|
||||
BSDECHO = echo
|
||||
MKSHLIB = $(LD) -shared
|
||||
22
mozilla/js/src/config/IRIX5.3.mk
Normal file
22
mozilla/js/src/config/IRIX5.3.mk
Normal file
@@ -0,0 +1,22 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for IRIX5.3
|
||||
#
|
||||
|
||||
include config/IRIX.mk
|
||||
22
mozilla/js/src/config/IRIX6.1.mk
Normal file
22
mozilla/js/src/config/IRIX6.1.mk
Normal file
@@ -0,0 +1,22 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for IRIX6.3
|
||||
#
|
||||
|
||||
include config/IRIX.mk
|
||||
22
mozilla/js/src/config/IRIX6.2.mk
Normal file
22
mozilla/js/src/config/IRIX6.2.mk
Normal file
@@ -0,0 +1,22 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for IRIX6.2
|
||||
#
|
||||
|
||||
include config/IRIX.mk
|
||||
22
mozilla/js/src/config/IRIX6.3.mk
Normal file
22
mozilla/js/src/config/IRIX6.3.mk
Normal file
@@ -0,0 +1,22 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for IRIX6.3
|
||||
#
|
||||
|
||||
include config/IRIX.mk
|
||||
47
mozilla/js/src/config/Linux_All.mk
Normal file
47
mozilla/js/src/config/Linux_All.mk
Normal file
@@ -0,0 +1,47 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
#
|
||||
# Config for all versions of Linux
|
||||
#
|
||||
|
||||
CC = gcc -Wall -Wno-format
|
||||
CCC = g++ -Wall -Wno-format
|
||||
|
||||
RANLIB = echo
|
||||
|
||||
#.c.o:
|
||||
# $(CC) -c -MD $*.d $(CFLAGS) $<
|
||||
|
||||
CPU_ARCH = $(shell uname -m)
|
||||
ifeq (86,$(findstring 86,$(CPU_ARCH)))
|
||||
CPU_ARCH = x86
|
||||
endif
|
||||
GFX_ARCH = x
|
||||
|
||||
OS_CFLAGS = -DXP_UNIX -DSVR4 -DSYSV -D_BSD_SOURCE -DPOSIX_SOURCE -DLINUX
|
||||
OS_LIBS = -lm -lc
|
||||
|
||||
ASFLAGS += -x assembler-with-cpp
|
||||
|
||||
ifeq ($(CPU_ARCH),alpha)
|
||||
|
||||
# Ask the C compiler on alpha linux to let us work with denormalized
|
||||
# double values, which are required by the ECMA spec.
|
||||
|
||||
OS_CFLAGS += -mieee
|
||||
endif
|
||||
79
mozilla/js/src/config/SunOS4.1.4.mk
Normal file
79
mozilla/js/src/config/SunOS4.1.4.mk
Normal file
@@ -0,0 +1,79 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for SunOS4.1
|
||||
#
|
||||
|
||||
CC = gcc
|
||||
CCC = g++
|
||||
RANLIB = ranlib
|
||||
|
||||
#.c.o:
|
||||
# $(CC) -c -MD $*.d $(CFLAGS) $<
|
||||
|
||||
CPU_ARCH = sparc
|
||||
GFX_ARCH = x
|
||||
|
||||
# A pile of -D's to build xfe on sunos
|
||||
MOZ_CFLAGS = -DSTRINGS_ALIGNED -DNO_REGEX -DNO_ISDIR -DUSE_RE_COMP \
|
||||
-DNO_REGCOMP -DUSE_GETWD -DNO_MEMMOVE -DNO_ALLOCA \
|
||||
-DBOGUS_MB_MAX -DNO_CONST
|
||||
|
||||
# Purify doesn't like -MDupdate
|
||||
NOMD_OS_CFLAGS = -DXP_UNIX -Wall -Wno-format -DSW_THREADS -DSUNOS4 -DNEED_SYSCALL \
|
||||
$(MOZ_CFLAGS)
|
||||
|
||||
OS_CFLAGS = $(NOMD_OS_CFLAGS) -MDupdate $(DEPENDENCIES)
|
||||
OS_LIBS = -ldl -lm
|
||||
|
||||
MKSHLIB = $(LD) -L$(MOTIF)/lib
|
||||
|
||||
HAVE_PURIFY = 1
|
||||
MOTIF = /home/motif/usr
|
||||
MOTIFLIB = -L$(MOTIF)/lib -lXm
|
||||
INCLUDES += -I/usr/X11R5/include -I$(MOTIF)/include
|
||||
|
||||
NOSUCHFILE = /solaris-rm-f-sucks
|
||||
|
||||
LOCALE_MAP = $(DEPTH)/cmd/xfe/intl/sunos.lm
|
||||
|
||||
EN_LOCALE = en_US
|
||||
DE_LOCALE = de
|
||||
FR_LOCALE = fr
|
||||
JP_LOCALE = ja
|
||||
SJIS_LOCALE = ja_JP.SJIS
|
||||
KR_LOCALE = ko
|
||||
CN_LOCALE = zh
|
||||
TW_LOCALE = zh_TW
|
||||
I2_LOCALE = i2
|
||||
IT_LOCALE = it
|
||||
SV_LOCALE = sv
|
||||
ES_LOCALE = es
|
||||
NL_LOCALE = nl
|
||||
PT_LOCALE = pt
|
||||
|
||||
LOC_LIB_DIR = /usr/openwin/lib/locale
|
||||
|
||||
BSDECHO = echo
|
||||
|
||||
#
|
||||
# These defines are for building unix plugins
|
||||
#
|
||||
BUILD_UNIX_PLUGINS = 1
|
||||
DSO_LDOPTS =
|
||||
DSO_LDFLAGS =
|
||||
66
mozilla/js/src/config/SunOS5.3.mk
Normal file
66
mozilla/js/src/config/SunOS5.3.mk
Normal file
@@ -0,0 +1,66 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for SunOS5.3
|
||||
#
|
||||
|
||||
CC = gcc -Wall -Wno-format
|
||||
CCC = g++ -Wall -Wno-format
|
||||
|
||||
#CC = /opt/SUNWspro/SC3.0.1/bin/cc
|
||||
RANLIB = echo
|
||||
|
||||
#.c.o:
|
||||
# $(CC) -c -MD $*.d $(CFLAGS) $<
|
||||
|
||||
CPU_ARCH = sparc
|
||||
GFX_ARCH = x
|
||||
|
||||
OS_CFLAGS = -DXP_UNIX -DSVR4 -DSYSV -DSOLARIS
|
||||
OS_LIBS = -lsocket -lnsl -ldl
|
||||
|
||||
ASFLAGS += -P -L -K PIC -D_ASM -D__STDC__=0
|
||||
|
||||
HAVE_PURIFY = 1
|
||||
|
||||
NOSUCHFILE = /solaris-rm-f-sucks
|
||||
|
||||
ifndef JS_NO_ULTRA
|
||||
ULTRA_OPTIONS := -xarch=v8plus
|
||||
ULTRA_OPTIONSD := -DULTRA_SPARC
|
||||
else
|
||||
ULTRA_OPTIONS := -xarch=v8
|
||||
ULTRA_OPTIONSD :=
|
||||
endif
|
||||
|
||||
ifeq ($(OS_CPUARCH),sun4u)
|
||||
DEFINES += $(ULTRA_OPTIONSD)
|
||||
ifeq ($(findstring gcc,$(CC)),gcc)
|
||||
DEFINES += -Wa,$(ULTRA_OPTIONS),$(ULTRA_OPTIONSD)
|
||||
else
|
||||
ASFLAGS += $(ULTRA_OPTIONS) $(ULTRA_OPTIONSD)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(OS_CPUARCH),sun4m)
|
||||
ifeq ($(findstring gcc,$(CC)),gcc)
|
||||
DEFINES += -Wa,-xarch=v8
|
||||
else
|
||||
ASFLAGS += -xarch=v8
|
||||
endif
|
||||
endif
|
||||
67
mozilla/js/src/config/SunOS5.4.mk
Normal file
67
mozilla/js/src/config/SunOS5.4.mk
Normal file
@@ -0,0 +1,67 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for SunOS5.4
|
||||
#
|
||||
|
||||
ifdef NS_USE_NATIVE
|
||||
CC = cc
|
||||
CCC = CC
|
||||
else
|
||||
CC = gcc -Wall -Wno-format
|
||||
CCC = g++ -Wall -Wno-format
|
||||
endif
|
||||
|
||||
RANLIB = echo
|
||||
|
||||
CPU_ARCH = sparc
|
||||
GFX_ARCH = x
|
||||
|
||||
OS_CFLAGS = -DXP_UNIX -DSVR4 -DSYSV -D__svr4 -DSOLARIS
|
||||
OS_LIBS = -lsocket -lnsl -ldl
|
||||
|
||||
ASFLAGS += -P -L -K PIC -D_ASM -D__STDC__=0
|
||||
|
||||
HAVE_PURIFY = 1
|
||||
|
||||
NOSUCHFILE = /solaris-rm-f-sucks
|
||||
|
||||
ifndef JS_NO_ULTRA
|
||||
ULTRA_OPTIONS := -xarch=v8plus
|
||||
ULTRA_OPTIONSD := -DULTRA_SPARC
|
||||
else
|
||||
ULTRA_OPTIONS := -xarch=v8
|
||||
ULTRA_OPTIONSD :=
|
||||
endif
|
||||
|
||||
ifeq ($(OS_CPUARCH),sun4u)
|
||||
DEFINES += $(ULTRA_OPTIONSD)
|
||||
ifeq ($(findstring gcc,$(CC)),gcc)
|
||||
DEFINES += -Wa,$(ULTRA_OPTIONS),$(ULTRA_OPTIONSD)
|
||||
else
|
||||
ASFLAGS += $(ULTRA_OPTIONS) $(ULTRA_OPTIONSD)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(OS_CPUARCH),sun4m)
|
||||
ifeq ($(findstring gcc,$(CC)),gcc)
|
||||
DEFINES += -Wa,-xarch=v8
|
||||
else
|
||||
ASFLAGS += -xarch=v8
|
||||
endif
|
||||
endif
|
||||
71
mozilla/js/src/config/SunOS5.5.1.mk
Normal file
71
mozilla/js/src/config/SunOS5.5.1.mk
Normal file
@@ -0,0 +1,71 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for SunOS5.5
|
||||
#
|
||||
|
||||
AS = as
|
||||
ifndef NS_USE_NATIVE
|
||||
CC = gcc -Wall -Wno-format
|
||||
CCC = g++ -Wall
|
||||
else
|
||||
CC = cc
|
||||
CCC = CC
|
||||
endif
|
||||
|
||||
RANLIB = echo
|
||||
|
||||
#.c.o:
|
||||
# $(CC) -c -MD $*.d $(CFLAGS) $<
|
||||
|
||||
CPU_ARCH = sparc
|
||||
GFX_ARCH = x
|
||||
|
||||
OS_CFLAGS = -DXP_UNIX -DSVR4 -DSYSV -DSOLARIS -D_SVID_GETTOD
|
||||
OS_LIBS = -lsocket -lnsl -ldl
|
||||
|
||||
ASFLAGS += -P -L -K PIC -D_ASM -D__STDC__=0
|
||||
|
||||
HAVE_PURIFY = 1
|
||||
|
||||
NOSUCHFILE = /solaris-rm-f-sucks
|
||||
|
||||
ifndef JS_NO_ULTRA
|
||||
ULTRA_OPTIONS := -xarch=v8plus
|
||||
ULTRA_OPTIONSD := -DULTRA_SPARC
|
||||
else
|
||||
ULTRA_OPTIONS := -xarch=v8
|
||||
ULTRA_OPTIONSD :=
|
||||
endif
|
||||
|
||||
ifeq ($(OS_CPUARCH),sun4u)
|
||||
DEFINES += $(ULTRA_OPTIONSD)
|
||||
ifeq ($(findstring gcc,$(CC)),gcc)
|
||||
DEFINES += -Wa,$(ULTRA_OPTIONS),$(ULTRA_OPTIONSD)
|
||||
else
|
||||
ASFLAGS += $(ULTRA_OPTIONS) $(ULTRA_OPTIONSD)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(OS_CPUARCH),sun4m)
|
||||
ifeq ($(findstring gcc,$(CC)),gcc)
|
||||
DEFINES += -Wa,-xarch=v8
|
||||
else
|
||||
ASFLAGS += -xarch=v8
|
||||
endif
|
||||
endif
|
||||
62
mozilla/js/src/config/SunOS5.5.mk
Normal file
62
mozilla/js/src/config/SunOS5.5.mk
Normal file
@@ -0,0 +1,62 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for SunOS5.5
|
||||
#
|
||||
|
||||
AS = as
|
||||
CC = gcc -Wall -Wno-format
|
||||
CCC = g++ -Wall -Wno-format
|
||||
|
||||
#CC = /opt/SUNWspro/SC3.0.1/bin/cc
|
||||
RANLIB = echo
|
||||
|
||||
#.c.o:
|
||||
# $(CC) -c -MD $*.d $(CFLAGS) $<
|
||||
|
||||
CPU_ARCH = sparc
|
||||
GFX_ARCH = x
|
||||
|
||||
OS_CFLAGS = -DXP_UNIX -DSVR4 -DSYSV -DSOLARIS -D_SVID_GETTOD
|
||||
OS_LIBS = -lsocket -lnsl -ldl
|
||||
|
||||
ASFLAGS += -P -L -K PIC -D_ASM -D__STDC__=0
|
||||
|
||||
HAVE_PURIFY = 1
|
||||
|
||||
NOSUCHFILE = /solaris-rm-f-sucks
|
||||
|
||||
ifndef JS_NO_ULTRA
|
||||
ULTRA_OPTIONS := -xarch=v8plus -DULTRA_SPARC
|
||||
else
|
||||
ULTRA_OPTIONS := -xarch=v8
|
||||
endif
|
||||
|
||||
ifeq ($(OS_CPUARCH),sun4u)
|
||||
ASFLAGS += $(ULTRA_OPTIONS)
|
||||
ifeq ($(findstring gcc,$(CC)),gcc)
|
||||
DEFINES += -Wa,$(ULTRA_OPTIONS)
|
||||
endif
|
||||
else
|
||||
ifeq ($(OS_CPUARCH),sun4m)
|
||||
ASFLAGS += -xarch=v8
|
||||
ifeq ($(findstring gcc,$(CC)),gcc)
|
||||
DEFINES += -Wa,-xarch=v8
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
46
mozilla/js/src/config/WINNT4.0.mk
Normal file
46
mozilla/js/src/config/WINNT4.0.mk
Normal file
@@ -0,0 +1,46 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
#
|
||||
# Config for Windows NT using MS Visual C++ (version?)
|
||||
#
|
||||
|
||||
CC = cl
|
||||
|
||||
RANLIB = echo
|
||||
|
||||
#.c.o:
|
||||
# $(CC) -c -MD $*.d $(CFLAGS) $<
|
||||
|
||||
CPU_ARCH = x86 # XXX fixme
|
||||
GFX_ARCH = win32
|
||||
|
||||
OS_CFLAGS = -DXP_PC -DWIN32 -D_WINDOWS -D_WIN32
|
||||
OS_LIBS = -lm -lc
|
||||
|
||||
PREBUILT_CPUCFG = 1
|
||||
USE_MSVC = 1
|
||||
|
||||
LIB_LINK_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\
|
||||
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib oldnames.lib /nologo\
|
||||
/subsystem:windows /dll /incremental:yes /debug\
|
||||
/machine:I386
|
||||
|
||||
CAFEDIR = t:/cafe
|
||||
JCLASSPATH = $(CAFEDIR)/Java/Lib/classes.zip
|
||||
JAVAC = $(CAFEDIR)/Bin/sj.exe
|
||||
JAVAH = $(CAFEDIR)/Java/Bin/javah.exe
|
||||
JCFLAGS = -I$(CAFEDIR)/Java/Include -I$(CAFEDIR)/Java/Include/win32
|
||||
42
mozilla/js/src/config/dgux.mk
Normal file
42
mozilla/js/src/config/dgux.mk
Normal file
@@ -0,0 +1,42 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
|
||||
#
|
||||
# Config stuff for Data General DG/UX
|
||||
#
|
||||
|
||||
#
|
||||
# Initial DG/UX port by Marc Fraioli (fraioli@dg-rtp.dg.com)
|
||||
#
|
||||
|
||||
AS = as
|
||||
CC = gcc
|
||||
CCC = g++
|
||||
|
||||
RANLIB = echo
|
||||
|
||||
#
|
||||
# _DGUX_SOURCE is needed to turn on a lot of stuff in the headers if
|
||||
# you're not using DG's compiler. It shouldn't hurt if you are.
|
||||
#
|
||||
# _POSIX4A_DRAFT10_SOURCE is needed to pick up localtime_r, used in
|
||||
# prtime.c
|
||||
#
|
||||
OS_CFLAGS = -DXP_UNIX -DSVR4 -DSYSV -DDGUX -D_DGUX_SOURCE -D_POSIX4A_DRAFT10_SOURCE
|
||||
OS_LIBS = -lsocket -lnsl
|
||||
|
||||
NOSUCHFILE = /no-such-file
|
||||
@@ -24,14 +24,17 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "jstypes.h"
|
||||
#ifndef NSPR20
|
||||
#include "prarena.h"
|
||||
#include "jsarena.h"
|
||||
#else
|
||||
#include "plarena.h"
|
||||
/* Removed by JSIFY: #include "plarena.h"
|
||||
*/
|
||||
#include "jsarena.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "prlog.h"
|
||||
#include "prprf.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#include "jsprf.h"
|
||||
#include "jsapi.h"
|
||||
#include "jsatom.h"
|
||||
#include "jscntxt.h"
|
||||
@@ -108,6 +111,17 @@ static JSDJContext *_jsdjc;
|
||||
#endif /* JSDEBUGGER_JAVA_UI */
|
||||
#endif /* JSDEBUGGER */
|
||||
|
||||
static int reportWarnings;
|
||||
|
||||
typedef enum JSShellErrNum {
|
||||
#define MSG_DEF(name, number, count, exception, format) \
|
||||
name = number,
|
||||
#include "jsshell.msg"
|
||||
#undef MSG_DEF
|
||||
JSShellErr_Limit
|
||||
#undef MSGDEF
|
||||
} JSShellErrNum;
|
||||
|
||||
static void
|
||||
Process(JSContext *cx, JSObject *obj, char *filename)
|
||||
{
|
||||
@@ -128,19 +142,19 @@ Process(JSContext *cx, JSObject *obj, char *filename)
|
||||
if (isatty(fileno(ts->file))) {
|
||||
ts->flags |= TSF_INTERACTIVE;
|
||||
} else {
|
||||
/* Support the UNIX #! shell hack; gobble the first line if it starts
|
||||
* with '#'. TODO - this isn't quite compatible with sharp variables,
|
||||
* as a legal js program (using sharp variables) might start with '#'.
|
||||
* But that would require multi-character lookahead.
|
||||
*/
|
||||
char ch = fgetc(ts->file);
|
||||
if (ch == '#') {
|
||||
while((ch = fgetc(ts->file)) != EOF) {
|
||||
if(ch == '\n' || ch == '\r')
|
||||
break;
|
||||
}
|
||||
}
|
||||
ungetc(ch, ts->file);
|
||||
/* Support the UNIX #! shell hack; gobble the first line if it starts
|
||||
* with '#'. TODO - this isn't quite compatible with sharp variables,
|
||||
* as a legal js program (using sharp variables) might start with '#'.
|
||||
* But that would require multi-character lookahead.
|
||||
*/
|
||||
char ch = fgetc(ts->file);
|
||||
if (ch == '#') {
|
||||
while((ch = fgetc(ts->file)) != EOF) {
|
||||
if(ch == '\n' || ch == '\r')
|
||||
break;
|
||||
}
|
||||
}
|
||||
ungetc(ch, ts->file);
|
||||
}
|
||||
|
||||
do {
|
||||
@@ -156,6 +170,12 @@ Process(JSContext *cx, JSObject *obj, char *filename)
|
||||
}
|
||||
} while (ok && !(ts->flags & TSF_EOF) && CG_OFFSET(&cg) == 0);
|
||||
if (ok) {
|
||||
/*
|
||||
* Clear any pending exception, either from previous failed
|
||||
* compiles, or from the last round of execution.
|
||||
*/
|
||||
JS_ClearPendingException(cx);
|
||||
|
||||
script = js_NewScriptFromCG(cx, &cg, NULL);
|
||||
if (script) {
|
||||
if (JS_ExecuteScript(cx, obj, script, &result) &&
|
||||
@@ -165,6 +185,30 @@ Process(JSContext *cx, JSObject *obj, char *filename)
|
||||
if (str)
|
||||
printf("%s\n", JS_GetStringBytes(str));
|
||||
}
|
||||
|
||||
if (JS_IsExceptionPending(cx) &&
|
||||
JS_GetPendingException(cx, &result))
|
||||
{
|
||||
/*
|
||||
* Calling JS_ValueToString could cause another error (and
|
||||
* throw an associated exception) - so we disable the error
|
||||
* reporter so nothing gets reported, and we always clear
|
||||
* the pending exception... which might be different than
|
||||
* the one we just got in &result.
|
||||
*/
|
||||
JSErrorReporter older;
|
||||
older = JS_SetErrorReporter(cx, NULL);
|
||||
str = JS_ValueToString(cx, result);
|
||||
JS_SetErrorReporter(cx, older);
|
||||
|
||||
/* XXX non-i18nized strings... */
|
||||
if (str) {
|
||||
fprintf(stderr, "Uncaught JavaScript exception:\n%s\n",
|
||||
JS_GetStringBytes(str));
|
||||
} else {
|
||||
fprintf(stderr, "Uncaught JavaScript exception\n");
|
||||
}
|
||||
}
|
||||
JS_DestroyScript(cx, script);
|
||||
}
|
||||
}
|
||||
@@ -176,15 +220,15 @@ Process(JSContext *cx, JSObject *obj, char *filename)
|
||||
out:
|
||||
if (ts)
|
||||
(void) js_CloseTokenStream(cx, ts);
|
||||
PR_FreeArenaPool(&cx->codePool);
|
||||
PR_FreeArenaPool(&cx->tempPool);
|
||||
JS_FreeArenaPool(&cx->codePool);
|
||||
JS_FreeArenaPool(&cx->tempPool);
|
||||
}
|
||||
|
||||
static int
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "%s\n", JS_GetImplementationVersion());
|
||||
fprintf(stderr, "usage: js [-v version] [-f scriptfile] [scriptfile] [scriptarg...]\n");
|
||||
fprintf(stderr, "usage: js [-w] [-v version] [-f scriptfile] [scriptfile] [scriptarg...]\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -199,34 +243,37 @@ ProcessArgs(JSContext *cx, JSObject *obj, char **argv, int argc)
|
||||
JSObject *argsObj;
|
||||
|
||||
for (i=0; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
switch (argv[i][1]) {
|
||||
case 'v':
|
||||
if (i+1 == argc) {
|
||||
return usage();
|
||||
}
|
||||
JS_SetVersion(cx, atoi(argv[i+1]));
|
||||
i++;
|
||||
break;
|
||||
if (argv[i][0] == '-') {
|
||||
switch (argv[i][1]) {
|
||||
case 'v':
|
||||
if (i+1 == argc) {
|
||||
return usage();
|
||||
}
|
||||
JS_SetVersion(cx, atoi(argv[i+1]));
|
||||
i++;
|
||||
break;
|
||||
case 'w':
|
||||
reportWarnings++;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
if (i+1 == argc) {
|
||||
return usage();
|
||||
}
|
||||
filename = argv[i+1];
|
||||
/* "-f -" means read from stdin */
|
||||
if (filename[0] == '-' && filename[1] == '\0')
|
||||
filename = NULL;
|
||||
Process(cx, obj, filename);
|
||||
i++;
|
||||
break;
|
||||
default:
|
||||
return usage();
|
||||
}
|
||||
} else {
|
||||
filename = argv[i++];
|
||||
break;
|
||||
}
|
||||
case 'f':
|
||||
if (i+1 == argc) {
|
||||
return usage();
|
||||
}
|
||||
filename = argv[i+1];
|
||||
/* "-f -" means read from stdin */
|
||||
if (filename[0] == '-' && filename[1] == '\0')
|
||||
filename = NULL;
|
||||
Process(cx, obj, filename);
|
||||
i++;
|
||||
break;
|
||||
default:
|
||||
return usage();
|
||||
}
|
||||
} else {
|
||||
filename = argv[i++];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
length = argc - i;
|
||||
@@ -234,22 +281,23 @@ ProcessArgs(JSContext *cx, JSObject *obj, char **argv, int argc)
|
||||
p = vector;
|
||||
|
||||
if (vector == NULL)
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
while (i < argc) {
|
||||
JSString *str = JS_NewStringCopyZ(cx, argv[i]);
|
||||
if (str == NULL)
|
||||
return 1;
|
||||
*p++ = STRING_TO_JSVAL(str);
|
||||
i++;
|
||||
JSString *str = JS_NewStringCopyZ(cx, argv[i]);
|
||||
if (str == NULL)
|
||||
return 1;
|
||||
*p++ = STRING_TO_JSVAL(str);
|
||||
i++;
|
||||
}
|
||||
argsObj = JS_NewArrayObject(cx, length, vector);
|
||||
JS_free(cx, vector);
|
||||
if (argsObj == NULL)
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
if (!JS_DefineProperty(cx, obj, "arguments",
|
||||
OBJECT_TO_JSVAL(argsObj), NULL, NULL, 0))
|
||||
return 1;
|
||||
OBJECT_TO_JSVAL(argsObj), NULL, NULL, 0))
|
||||
return 1;
|
||||
|
||||
Process(cx, obj, filename);
|
||||
return 0;
|
||||
@@ -269,6 +317,9 @@ Version(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
static void
|
||||
my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report);
|
||||
|
||||
static const JSErrorFormatString *
|
||||
my_GetErrorMessage(void *userRef, const char *locale, const uintN errorNumber);
|
||||
|
||||
static JSBool
|
||||
Load(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
@@ -342,13 +393,13 @@ GC(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
preBytes = rt->gcBytes;
|
||||
#ifdef GC_MARK_DEBUG
|
||||
if (argc && JSVAL_IS_STRING(argv[0])) {
|
||||
char *name = JS_GetStringBytes(JSVAL_TO_STRING(argv[0]));
|
||||
FILE *file = fopen(name, "w");
|
||||
if (!file) {
|
||||
char *name = JS_GetStringBytes(JSVAL_TO_STRING(argv[0]));
|
||||
FILE *file = fopen(name, "w");
|
||||
if (!file) {
|
||||
fprintf(stderr, "gc: can't open %s: %s\n", strerror(errno));
|
||||
return JS_FALSE;
|
||||
}
|
||||
js_DumpGCHeap = file;
|
||||
}
|
||||
js_DumpGCHeap = file;
|
||||
} else {
|
||||
js_DumpGCHeap = stdout;
|
||||
}
|
||||
@@ -356,7 +407,7 @@ GC(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
js_ForceGC(cx);
|
||||
#ifdef GC_MARK_DEBUG
|
||||
if (js_DumpGCHeap != stdout)
|
||||
fclose(js_DumpGCHeap);
|
||||
fclose(js_DumpGCHeap);
|
||||
js_DumpGCHeap = NULL;
|
||||
#endif
|
||||
printf("before %lu, after %lu, break %08lx\n",
|
||||
@@ -427,7 +478,7 @@ Trap(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
int32 i;
|
||||
|
||||
if (argc == 0) {
|
||||
JS_ReportError(cx, "usage: trap [fun] [pc] expr");
|
||||
JS_ReportErrorNumber(cx, my_GetErrorMessage, NULL, JSSMSG_TRAP_USAGE);
|
||||
return JS_FALSE;
|
||||
}
|
||||
argc--;
|
||||
@@ -461,7 +512,7 @@ LineToPC(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
jsbytecode *pc;
|
||||
|
||||
if (argc == 0) {
|
||||
JS_ReportError(cx, "usage: line2pc [fun] line");
|
||||
JS_ReportErrorNumber(cx, my_GetErrorMessage, NULL, JSSMSG_LINE2PC_USAGE);
|
||||
return JS_FALSE;
|
||||
}
|
||||
script = cx->fp->down->script;
|
||||
@@ -496,7 +547,7 @@ PCToLine(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
static void
|
||||
SrcNotes(JSContext *cx, JSFunction *fun )
|
||||
{
|
||||
uintN offset, delta;
|
||||
uintN offset, delta, caseOff;
|
||||
jssrcnote *notes, *sn;
|
||||
JSSrcNoteType type;
|
||||
jsatomid atomIndex;
|
||||
@@ -522,8 +573,8 @@ SrcNotes(JSContext *cx, JSFunction *fun )
|
||||
(uintN) js_GetSrcNoteOffset(sn, 1),
|
||||
(uintN) js_GetSrcNoteOffset(sn, 2));
|
||||
break;
|
||||
case SRC_COMMA:
|
||||
case SRC_PCBASE:
|
||||
case SRC_PCDELTA:
|
||||
printf(" offset %u", (uintN) js_GetSrcNoteOffset(sn, 0));
|
||||
break;
|
||||
case SRC_LABEL:
|
||||
@@ -535,6 +586,12 @@ SrcNotes(JSContext *cx, JSFunction *fun )
|
||||
atom = js_GetAtom(cx, &fun->script->atomMap, atomIndex);
|
||||
printf(" atom %u (%s)", (uintN)atomIndex, ATOM_BYTES(atom));
|
||||
break;
|
||||
case SRC_SWITCH:
|
||||
printf(" length %u", (uintN) js_GetSrcNoteOffset(sn, 0));
|
||||
caseOff = (uintN) js_GetSrcNoteOffset(sn, 1);
|
||||
if (caseOff)
|
||||
printf(" first case offset %u", caseOff);
|
||||
break;
|
||||
case SRC_CATCH:
|
||||
delta = (uintN) js_GetSrcNoteOffset(sn, 0);
|
||||
if (delta)
|
||||
@@ -623,13 +680,16 @@ DisassWithSrc(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
|
||||
return JS_FALSE;
|
||||
|
||||
if (!fun->script || !fun->script->filename) {
|
||||
JS_ReportError(cx, "only works on JS scripts read from files");
|
||||
JS_ReportErrorNumber(cx, my_GetErrorMessage, NULL,
|
||||
JSSMSG_FILE_SCRIPTS_ONLY);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
file = fopen(fun->script->filename, "r");
|
||||
if (!file) {
|
||||
JS_ReportError(cx, "can't open %s: %s", fun->script->filename, strerror(errno));
|
||||
JS_ReportErrorNumber(cx, my_GetErrorMessage, NULL,
|
||||
JSSMSG_CANT_OPEN,
|
||||
fun->script->filename, strerror(errno));
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@@ -656,9 +716,10 @@ DisassWithSrc(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
|
||||
bupline = 0;
|
||||
while (line1 < line2) {
|
||||
if (!fgets(linebuf, LINE_BUF_LEN, file)) {
|
||||
JS_ReportError(cx, "unexpected EOF in %s",
|
||||
JS_ReportErrorNumber(cx, my_GetErrorMessage, NULL,
|
||||
JSSMSG_UNEXPECTED_EOF,
|
||||
fun->script->filename);
|
||||
goto bail;
|
||||
goto bail;
|
||||
}
|
||||
line1++;
|
||||
printf("%s %3u: %s", sep, line1, linebuf);
|
||||
@@ -676,6 +737,7 @@ DisassWithSrc(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
|
||||
fclose(file);
|
||||
}
|
||||
return JS_TRUE;
|
||||
#undef LINE_BUF_LEN
|
||||
}
|
||||
|
||||
static JSBool
|
||||
@@ -711,7 +773,7 @@ Tracing(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
}
|
||||
|
||||
int
|
||||
DumpAtom(PRHashEntry *he, int i, void *arg)
|
||||
DumpAtom(JSHashEntry *he, int i, void *arg)
|
||||
{
|
||||
FILE *fp = arg;
|
||||
JSAtom *atom = (JSAtom *)he;
|
||||
@@ -728,7 +790,7 @@ DumpAtom(PRHashEntry *he, int i, void *arg)
|
||||
}
|
||||
|
||||
int
|
||||
DumpSymbol(PRHashEntry *he, int i, void *arg)
|
||||
DumpSymbol(JSHashEntry *he, int i, void *arg)
|
||||
{
|
||||
FILE *fp = arg;
|
||||
JSSymbol *sym = (JSSymbol *)he;
|
||||
@@ -744,7 +806,7 @@ DumpSymbol(PRHashEntry *he, int i, void *arg)
|
||||
extern JS_FRIEND_DATA(JSScopeOps) js_list_scope_ops;
|
||||
|
||||
void
|
||||
DumpScope(JSContext *cx, JSObject *obj, PRHashEnumerator dump, FILE *fp)
|
||||
DumpScope(JSContext *cx, JSObject *obj, JSHashEnumerator dump, FILE *fp)
|
||||
{
|
||||
JSScope *scope;
|
||||
JSSymbol *sym;
|
||||
@@ -753,14 +815,14 @@ DumpScope(JSContext *cx, JSObject *obj, PRHashEnumerator dump, FILE *fp)
|
||||
fprintf(fp, "\n%s scope contents:\n", OBJ_GET_CLASS(cx, obj)->name);
|
||||
scope = (JSScope *)obj->map;
|
||||
if (!MAP_IS_NATIVE(&scope->map))
|
||||
return;
|
||||
return;
|
||||
if (scope->ops == &js_list_scope_ops) {
|
||||
for (sym = (JSSymbol *)scope->data, i = 0; sym;
|
||||
sym = (JSSymbol *)sym->entry.next, i++) {
|
||||
DumpSymbol(&sym->entry, i, fp);
|
||||
}
|
||||
} else {
|
||||
PR_HashTableDump(scope->data, dump, fp);
|
||||
JS_HashTableDump(scope->data, dump, fp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -786,11 +848,11 @@ DumpStats(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
bytes = JS_GetStringBytes(str);
|
||||
if (strcmp(bytes, "arena") == 0) {
|
||||
#ifdef ARENAMETER
|
||||
PR_DumpArenaStats(stdout);
|
||||
JS_DumpArenaStats(stdout);
|
||||
#endif
|
||||
} else if (strcmp(bytes, "atom") == 0) {
|
||||
printf("\natom table contents:\n");
|
||||
PR_HashTableDump(cx->runtime->atomState.table, DumpAtom, stdout);
|
||||
JS_HashTableDump(cx->runtime->atomState.table, DumpAtom, stdout);
|
||||
} else if (strcmp(bytes, "global") == 0) {
|
||||
DumpScope(cx, cx->globalObject, DumpSymbol, stdout);
|
||||
} else {
|
||||
@@ -807,7 +869,7 @@ DumpStats(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
if (!prop || !JSVAL_IS_OBJECT(value)) {
|
||||
fprintf(stderr, "js: invalid stats argument %s\n",
|
||||
bytes);
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
obj = JSVAL_TO_OBJECT(value);
|
||||
if (obj)
|
||||
@@ -830,7 +892,7 @@ DoExport(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
uintN attrs;
|
||||
|
||||
if (argc != 2) {
|
||||
JS_ReportError(cx, "usage: doexp obj id");
|
||||
JS_ReportErrorNumber(cx, my_GetErrorMessage, NULL, JSSMSG_DOEXP_USAGE);
|
||||
return JS_FALSE;
|
||||
}
|
||||
if (!JS_ValueToObject(cx, argv[0], &obj))
|
||||
@@ -878,10 +940,10 @@ ConvertArgs(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
}
|
||||
printf("b %u, c %x (%c), i %ld, u %lu, j %ld\n", b, c, (char)c, i, u, j);
|
||||
printf("d %g, I %g, s %s, S %s, obj %s, fun %s, v %s\n",
|
||||
d, I, s, JS_GetStringBytes(str),
|
||||
JS_GetStringBytes(JS_ValueToString(cx, OBJECT_TO_JSVAL(obj))),
|
||||
JS_GetStringBytes(JS_DecompileFunction(cx, fun, 4)),
|
||||
JS_GetStringBytes(JS_ValueToString(cx, v)));
|
||||
d, I, s, JS_GetStringBytes(str),
|
||||
JS_GetStringBytes(JS_ValueToString(cx, OBJECT_TO_JSVAL(obj))),
|
||||
JS_GetStringBytes(JS_DecompileFunction(cx, fun, 4)),
|
||||
JS_GetStringBytes(JS_ValueToString(cx, v)));
|
||||
return JS_TRUE;
|
||||
}
|
||||
#endif
|
||||
@@ -1027,6 +1089,63 @@ static JSPropertySpec its_props[] = {
|
||||
{0}
|
||||
};
|
||||
|
||||
#ifdef JSD_LOWLEVEL_SOURCE
|
||||
/*
|
||||
* This facilitates sending source to JSD (the debugger system) in the shell
|
||||
* where the source is loaded using the JSFILE hack in jsscan. The function
|
||||
* below is used as a callback for the jsdbgapi JS_SetSourceHandler hook.
|
||||
* A more normal embedding (e.g. mozilla) loads source itself and can send
|
||||
* source directly to JSD without using this hook scheme.
|
||||
*
|
||||
* XXX At some future point JSD will understand Unicode source and the
|
||||
* *very* ugly conversion below will be unnecessary.
|
||||
*/
|
||||
static void
|
||||
SendSourceToJSDebugger(const char *filename, uintN lineno,
|
||||
jschar *str, size_t length,
|
||||
void **listenerTSData, JSDContext* jsdc)
|
||||
{
|
||||
JSDSourceText *jsdsrc = (JSDSourceText *) *listenerTSData;
|
||||
|
||||
if (!jsdsrc) {
|
||||
if (!filename)
|
||||
filename = "typein";
|
||||
if (1 == lineno) {
|
||||
jsdsrc = JSD_NewSourceText(jsdc, filename);
|
||||
} else {
|
||||
jsdsrc = JSD_FindSourceForURL(jsdc, filename);
|
||||
if (jsdsrc && JSD_SOURCE_PARTIAL !=
|
||||
JSD_GetSourceStatus(jsdc, jsdsrc)) {
|
||||
jsdsrc = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (jsdsrc) {
|
||||
/* here we convert our Unicode into a C string to pass to JSD */
|
||||
#define JSD_BUF_SIZE 1024
|
||||
static char* buf = NULL;
|
||||
int remaining = length;
|
||||
|
||||
if (!buf)
|
||||
buf = malloc(JSD_BUF_SIZE);
|
||||
if (buf)
|
||||
{
|
||||
while (remaining && jsdsrc) {
|
||||
int bytes = JS_MIN(remaining, JSD_BUF_SIZE);
|
||||
int i;
|
||||
for (i = 0; i < bytes; i++)
|
||||
buf[i] = (const char) *(str++);
|
||||
jsdsrc = JSD_AppendSourceText(jsdc,jsdsrc,
|
||||
buf, bytes,
|
||||
JSD_SOURCE_PARTIAL);
|
||||
remaining -= bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
*listenerTSData = jsdsrc;
|
||||
}
|
||||
#endif /* JSD_LOWLEVEL_SOURCE */
|
||||
|
||||
static JSBool its_noisy; /* whether to be noisy when finalizing it */
|
||||
|
||||
static JSBool
|
||||
@@ -1120,28 +1239,78 @@ static JSClass its_class = {
|
||||
its_enumerate, its_resolve, its_convert, its_finalize
|
||||
};
|
||||
|
||||
JSErrorFormatString jsShell_ErrorFormatString[JSErr_Limit] = {
|
||||
#if JS_HAS_DFLT_MSG_STRINGS
|
||||
#define MSG_DEF(name, number, count, exception, format) \
|
||||
{ format, count } ,
|
||||
#else
|
||||
#define MSG_DEF(name, number, count, exception, format) \
|
||||
{ NULL, count } ,
|
||||
#endif
|
||||
#include "jsshell.msg"
|
||||
#undef MSG_DEF
|
||||
};
|
||||
|
||||
static const JSErrorFormatString *
|
||||
my_GetErrorMessage(void *userRef, const char *locale, const uintN errorNumber)
|
||||
{
|
||||
if ((errorNumber > 0) && (errorNumber < JSShellErr_Limit))
|
||||
return &jsShell_ErrorFormatString[errorNumber];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
|
||||
{
|
||||
int i, j, k, n;
|
||||
char *prefix = NULL, *tmp;
|
||||
|
||||
fputs("js: ", stderr);
|
||||
if (!report) {
|
||||
fprintf(stderr, "%s\n", message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (report->filename)
|
||||
fprintf(stderr, "%s, ", report->filename);
|
||||
if (report->lineno)
|
||||
fprintf(stderr, "line %u: ", report->lineno);
|
||||
fputs(message, stderr);
|
||||
if (!report->linebuf) {
|
||||
putc('\n', stderr);
|
||||
/*
|
||||
* Conditionally ignore reported warnings, and ignore error reports for
|
||||
* which a JavaScript exception has been thrown, except when we're in
|
||||
* a toplevel compile.
|
||||
*/
|
||||
if ((JSREPORT_IS_WARNING(report->flags) && !reportWarnings) ||
|
||||
(JSREPORT_IS_EXCEPTION(report->flags) && cx->interpLevel > 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(stderr, ":\n%s\n", report->linebuf);
|
||||
if (report->filename)
|
||||
prefix = JS_smprintf("%s:", report->filename);
|
||||
if (report->lineno) {
|
||||
tmp = prefix;
|
||||
prefix = JS_smprintf("%s%u: ", tmp ? tmp : "", report->lineno);
|
||||
JS_free(cx, tmp);
|
||||
}
|
||||
if (JSREPORT_IS_WARNING(report->flags)) {
|
||||
tmp = prefix;
|
||||
prefix = JS_smprintf("%swarning: ", tmp ? tmp : "");
|
||||
JS_free(cx, tmp);
|
||||
}
|
||||
|
||||
/* embedded newlines -- argh! */
|
||||
while ((tmp = strchr(message, '\n'))) {
|
||||
tmp++;
|
||||
if (prefix) fputs(prefix, stderr);
|
||||
fwrite(message, 1, tmp - message, stderr);
|
||||
message = tmp;
|
||||
}
|
||||
/* If there were no filename or lineno, the prefix might be empty */
|
||||
if (prefix) fputs(prefix, stderr);
|
||||
fputs(message, stderr);
|
||||
|
||||
if (!report->linebuf) {
|
||||
putc('\n', stderr);
|
||||
goto out;
|
||||
}
|
||||
|
||||
fprintf(stderr, ":\n%s%s\n%s", prefix, report->linebuf, prefix);
|
||||
n = report->tokenptr - report->linebuf;
|
||||
for (i = j = 0; i < n; i++) {
|
||||
if (report->linebuf[i] == '\t') {
|
||||
@@ -1153,6 +1322,8 @@ my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
|
||||
j++;
|
||||
}
|
||||
fputs("^\n", stderr);
|
||||
out:
|
||||
JS_free(cx, prefix);
|
||||
}
|
||||
|
||||
#if defined(SHELL_HACK) && defined(DEBUG) && defined(XP_UNIX)
|
||||
@@ -1230,7 +1401,7 @@ global_resolve(JSContext *cx, JSObject *obj, jsval id)
|
||||
ok = JS_TRUE;
|
||||
for (comp = strtok(path, ":"); comp; comp = strtok(NULL, ":")) {
|
||||
if (*comp != '\0') {
|
||||
full = PR_smprintf("%s/%s", comp, name);
|
||||
full = JS_smprintf("%s/%s", comp, name);
|
||||
if (!full) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
ok = JS_FALSE;
|
||||
@@ -1269,6 +1440,12 @@ main(int argc, char **argv)
|
||||
JSContext *cx;
|
||||
JSObject *glob, *it;
|
||||
int result;
|
||||
#ifdef LIVECONNECT
|
||||
JavaVM *java_vm = NULL;
|
||||
#endif
|
||||
#ifdef JSDEBUGGER_JAVA_UI
|
||||
JNIEnv *java_env;
|
||||
#endif
|
||||
|
||||
#ifdef XP_OS2
|
||||
/* these streams are normally line buffered on OS/2 and need a \n, *
|
||||
@@ -1282,10 +1459,10 @@ main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
version = JSVERSION_DEFAULT;
|
||||
#ifndef LIVECONNECT
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
#endif
|
||||
|
||||
rt = JS_NewRuntime(8L * 1024L * 1024L);
|
||||
if (!rt)
|
||||
return 1;
|
||||
@@ -1313,13 +1490,8 @@ main(int argc, char **argv)
|
||||
return 1;
|
||||
|
||||
#ifdef PERLCONNECT
|
||||
if (!js_InitPerlClass(cx, glob))
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
#ifdef LIVECONNECT
|
||||
if (!JSJ_SimpleInit(cx, glob, NULL, getenv("CLASSPATH")))
|
||||
return 1;
|
||||
if (!JS_InitPerlClass(cx, glob))
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
#ifdef JSDEBUGGER
|
||||
@@ -1330,13 +1502,19 @@ main(int argc, char **argv)
|
||||
if (!_jsdc)
|
||||
return 1;
|
||||
JSD_JSContextInUse(_jsdc, cx);
|
||||
|
||||
#ifdef JSD_LOWLEVEL_SOURCE
|
||||
JS_SetSourceHandler(rt, SendSourceToJSDebugger, _jsdc);
|
||||
#endif /* JSD_LOWLEVEL_SOURCE */
|
||||
#ifdef JSDEBUGGER_JAVA_UI
|
||||
_jsdjc = JSDJ_CreateContext();
|
||||
if (! _jsdjc)
|
||||
return 1;
|
||||
JSDJ_SetJSDContext(_jsdjc, _jsdc);
|
||||
JSDJ_CreateJavaVMAndStartDebugger(_jsdjc);
|
||||
java_env = JSDJ_CreateJavaVMAndStartDebugger(_jsdjc);
|
||||
#ifdef LIVECONNECT
|
||||
if (java_env)
|
||||
(*java_env)->GetJavaVM(java_env, &java_vm);
|
||||
#endif
|
||||
/*
|
||||
* XXX This would be the place to wait for the debugger to start.
|
||||
* Waiting would be nice in general, but especially when a js file
|
||||
@@ -1348,6 +1526,11 @@ main(int argc, char **argv)
|
||||
#endif /* JSDEBUGGER_C_UI */
|
||||
#endif /* JSDEBUGGER */
|
||||
|
||||
#ifdef LIVECONNECT
|
||||
if (!JSJ_SimpleInit(cx, glob, java_vm, getenv("CLASSPATH")))
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
result = ProcessArgs(cx, glob, argv, argc);
|
||||
|
||||
#ifdef JSDEBUGGER
|
||||
|
||||
3756
mozilla/js/src/js.mak
Normal file
3756
mozilla/js/src/js.mak
Normal file
File diff suppressed because it is too large
Load Diff
BIN
mozilla/js/src/js.mdp
Normal file
BIN
mozilla/js/src/js.mdp
Normal file
Binary file not shown.
194
mozilla/js/src/js.msg
Normal file
194
mozilla/js/src/js.msg
Normal file
@@ -0,0 +1,194 @@
|
||||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
This is the JavaScript error message file.
|
||||
|
||||
The format for each JS error message is:
|
||||
|
||||
MSG_DEF(<SYMBOLIC_NAME>, <ERROR_NUMBER>, <ARGUMENT_COUNT>, <EXCEPTION_NAME>,
|
||||
<FORMAT_STRING>)
|
||||
|
||||
where ;
|
||||
<SYMBOLIC_NAME> is a legal C identifer that will be used in the
|
||||
JS engine source.
|
||||
|
||||
<ERROR_NUMBER> is an unique integral value identifying this error.
|
||||
|
||||
<ARGUMENT_COUNT> is an integer literal specifying the total number of
|
||||
replaceable arguments in the following format string.
|
||||
|
||||
<EXCEPTION_NAME> is an exception index from the enum in jsexn.c;
|
||||
JSEXN_NONE for none. The given exception index will be raised by the
|
||||
engine when the corresponding error occurs.
|
||||
|
||||
<FORMAT_STRING> is a string literal, optionally containing sequences
|
||||
{X} where X is an integer representing the argument number that will
|
||||
be replaced with a string value when the error is reported.
|
||||
|
||||
e.g.
|
||||
|
||||
MSG_DEF(JSMSG_NOT_A_SUBSPECIES, 73, JSEXN_NONE, 2,
|
||||
"{0} is not a member of the {1} family")
|
||||
|
||||
can be used :
|
||||
|
||||
JS_ReportErrorNumber(JSMSG_NOT_A_SUBSPECIES, "Rhino", "Monkey");
|
||||
|
||||
to report :
|
||||
|
||||
"Rhino is not a member of the Monkey family"
|
||||
|
||||
*/
|
||||
|
||||
MSG_DEF(JSMSG_NOT_AN_ERROR, 0, 0, JSEXN_NONE, "<Error #0 is reserved>")
|
||||
MSG_DEF(JSMSG_NOT_DEFINED, 1, 1, JSEXN_REFERENCEERR, "{0} is not defined")
|
||||
MSG_DEF(JSMSG_NO_REG_EXPS, 2, 1, JSEXN_INTERNALERR, "sorry, regular expression are not supported")
|
||||
MSG_DEF(JSMSG_MORE_ARGS_NEEDED, 3, 3, JSEXN_NONE, "{0} requires more than {1} argument{2}")
|
||||
MSG_DEF(JSMSG_BAD_CHAR, 4, 1, JSEXN_NONE, "invalid format character {0}")
|
||||
MSG_DEF(JSMSG_BAD_TYPE, 5, 1, JSEXN_NONE, "unknown type {0}")
|
||||
MSG_DEF(JSMSG_CANT_LOCK, 6, 0, JSEXN_NONE, "can't lock memory")
|
||||
MSG_DEF(JSMSG_CANT_UNLOCK, 7, 0, JSEXN_NONE, "can't unlock memory")
|
||||
MSG_DEF(JSMSG_INCOMPATIBLE_PROTO, 8, 3, JSEXN_TARGETERR, "{0}.prototype.{1} called on incompatible {2}")
|
||||
MSG_DEF(JSMSG_NO_CONSTRUCTOR, 9, 1, JSEXN_NONE, "{0} has no constructor")
|
||||
MSG_DEF(JSMSG_CANT_ALIAS, 10, 3, JSEXN_NONE, "can't alias {0} to {1} in class {2}")
|
||||
MSG_DEF(JSMSG_NO_PROTO, 11, 1, JSEXN_INTERNALERR, "sorry, Array.prototype.{0} is not yet implemented")
|
||||
MSG_DEF(JSMSG_BAD_SORT_ARG, 12, 0, JSEXN_ARRAYERR, "invalid Array.prototype.sort argument")
|
||||
MSG_DEF(JSMSG_BAD_ATOMIC_NUMBER, 13, 1, JSEXN_INTERNALERR, "internal error: no index for atom {0}")
|
||||
MSG_DEF(JSMSG_TOO_MANY_LITERALS, 14, 0, JSEXN_INTERNALERR, "too many literals")
|
||||
MSG_DEF(JSMSG_CANT_WATCH, 15, 1, JSEXN_NONE, "can't watch non-native objects of class {0}")
|
||||
MSG_DEF(JSMSG_STACK_UNDERFLOW, 16, 2, JSEXN_INTERNALERR, "internal error compiling {0}: stack underflow at pc {1}")
|
||||
MSG_DEF(JSMSG_NEED_DIET, 17, 1, JSEXN_SYNTAXERR, "{0} too large")
|
||||
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}")
|
||||
MSG_DEF(JSMSG_NOT_FUNCTION, 22, 1, JSEXN_CALLERR, "{0} is not a function")
|
||||
MSG_DEF(JSMSG_NOT_CONSTRUCTOR, 23, 1, JSEXN_CONSTRUCTORERR, "{0} is not a constructor")
|
||||
MSG_DEF(JSMSG_STACK_OVERFLOW, 24, 1, JSEXN_NONE, "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_NONE, "too much recursion")
|
||||
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_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")
|
||||
MSG_DEF(JSMSG_CANT_CONVERT, 35, 1, JSEXN_TOPRIMITIVEERR, "can't convert {0} to an integer")
|
||||
MSG_DEF(JSMSG_CYCLIC_VALUE, 36, 1, JSEXN_ERR, "cyclic {0} value")
|
||||
MSG_DEF(JSMSG_PERMANENT, 37, 1, JSEXN_ERR, "{0} is permanent")
|
||||
MSG_DEF(JSMSG_CANT_CONVERT_TO, 38, 2, JSEXN_DEFAULTVALUEERR, "can't convert {0} to {1}")
|
||||
MSG_DEF(JSMSG_NO_PROPERTIES, 39, 1, JSEXN_TOOBJECTERR, "{0} has no properties")
|
||||
MSG_DEF(JSMSG_CANT_FIND_CLASS, 40, 1, JSEXN_NONE, "can't find class id {0}")
|
||||
MSG_DEF(JSMSG_CANT_XDR_CLASS, 41, 1, JSEXN_NONE, "can't XDR class {0}")
|
||||
MSG_DEF(JSMSG_BYTECODE_TOO_BIG, 42, 2, JSEXN_INTERNALERR, "bytecode {0} too large (limit {1})")
|
||||
MSG_DEF(JSMSG_UNKNOWN_FORMAT, 43, 1, JSEXN_INTERNALERR, "unknown bytecode format {0}")
|
||||
MSG_DEF(JSMSG_TOO_MANY_CON_ARGS, 44, 0, JSEXN_SYNTAXERR, "too many constructor arguments")
|
||||
MSG_DEF(JSMSG_TOO_MANY_FUN_ARGS, 45, 0, JSEXN_SYNTAXERR, "too many function arguments")
|
||||
MSG_DEF(JSMSG_BAD_QUANTIFIER, 46, 1, JSEXN_SYNTAXERR, "invalid quantifier {0}")
|
||||
MSG_DEF(JSMSG_MIN_TOO_BIG, 47, 1, JSEXN_SYNTAXERR, "overlarge minimum {0}")
|
||||
MSG_DEF(JSMSG_MAX_TOO_BIG, 48, 1, JSEXN_SYNTAXERR, "overlarge maximum {0}")
|
||||
MSG_DEF(JSMSG_OUT_OF_ORDER, 49, 1, JSEXN_SYNTAXERR, "maximum {0} less than minimum")
|
||||
MSG_DEF(JSMSG_ZERO_QUANTIFIER, 50, 1, JSEXN_SYNTAXERR, "zero quantifier {0}")
|
||||
MSG_DEF(JSMSG_UNTERM_QUANTIFIER, 51, 1, JSEXN_SYNTAXERR, "unterminated quantifier {0}")
|
||||
MSG_DEF(JSMSG_EMPTY_BEFORE_STAR, 52, 0, JSEXN_SYNTAXERR, "regular expression before * could be empty")
|
||||
MSG_DEF(JSMSG_EMPTY_BEFORE_PLUS, 53, 0, JSEXN_SYNTAXERR, "regular expression before + could be empty")
|
||||
MSG_DEF(JSMSG_MISSING_PAREN, 54, 1, JSEXN_SYNTAXERR, "unterminated parenthetical {0}")
|
||||
MSG_DEF(JSMSG_UNTERM_CLASS, 55, 1, JSEXN_SYNTAXERR, "unterminated character class {0}")
|
||||
MSG_DEF(JSMSG_TRAILING_SLASH, 56, 0, JSEXN_SYNTAXERR, "trailing \\ in regular expression")
|
||||
MSG_DEF(JSMSG_BAD_CLASS_RANGE, 57, 0, JSEXN_SYNTAXERR, "invalid range in character class")
|
||||
MSG_DEF(JSMSG_BAD_FLAG, 58, 1, JSEXN_SYNTAXERR, "invalid regular expression flag {0}")
|
||||
MSG_DEF(JSMSG_NO_INPUT, 59, 3, JSEXN_SYNTAXERR, "no input for /{0}/{1}{2}")
|
||||
MSG_DEF(JSMSG_CANT_OPEN, 60, 2, JSEXN_NONE, "can't open {0}: {1}")
|
||||
MSG_DEF(JSMSG_BAD_STRING_MASK, 61, 1, JSEXN_ERR, "invalid string escape mask {0}")
|
||||
MSG_DEF(JSMSG_NO_STRING_PROTO, 62, 1, JSEXN_INTERNALERR, "sorry, String.prototype.{0} is not yet implemented")
|
||||
MSG_DEF(JSMSG_END_OF_DATA, 63, 0, JSEXN_NONE, "unexpected end of data")
|
||||
MSG_DEF(JSMSG_SEEK_BEYOND_START, 64, 0, JSEXN_NONE, "illegal seek beyond start")
|
||||
MSG_DEF(JSMSG_SEEK_BEYOND_END, 65, 0, JSEXN_NONE, "illegal seek beyond end")
|
||||
MSG_DEF(JSMSG_END_SEEK, 66, 0, JSEXN_NONE, "illegal end-based seek")
|
||||
MSG_DEF(JSMSG_WHITHER_WHENCE, 67, 1, JSEXN_NONE, "unknown seek whence: {0}")
|
||||
MSG_DEF(JSMSG_BAD_JVAL_TYPE, 68, 1, JSEXN_NONE, "unknown jsval type {0} for XDR")
|
||||
MSG_DEF(JSMSG_PAREN_BEFORE_FORMAL, 69, 0, JSEXN_SYNTAXERR, "missing ( before formal parameters")
|
||||
MSG_DEF(JSMSG_MISSING_FORMAL, 70, 0, JSEXN_SYNTAXERR, "missing formal parameter")
|
||||
MSG_DEF(JSMSG_PAREN_AFTER_FORMAL, 71, 0, JSEXN_SYNTAXERR, "missing ) after formal parameters")
|
||||
MSG_DEF(JSMSG_CURLY_BEFORE_BODY, 72, 0, JSEXN_SYNTAXERR, "missing { before function body")
|
||||
MSG_DEF(JSMSG_CURLY_AFTER_BODY, 73, 0, JSEXN_SYNTAXERR, "missing } after function body")
|
||||
MSG_DEF(JSMSG_PAREN_BEFORE_COND, 74, 0, JSEXN_SYNTAXERR, "missing ( before condition")
|
||||
MSG_DEF(JSMSG_PAREN_AFTER_COND, 75, 0, JSEXN_SYNTAXERR, "missing ) after condition")
|
||||
MSG_DEF(JSMSG_NO_IMPORT_NAME, 76, 0, JSEXN_SYNTAXERR, "missing name in import statement")
|
||||
MSG_DEF(JSMSG_NAME_AFTER_DOT, 77, 0, JSEXN_SYNTAXERR, "missing name after . operator")
|
||||
MSG_DEF(JSMSG_BRACKET_IN_INDEX, 78, 0, JSEXN_SYNTAXERR, "missing ] in index expression")
|
||||
MSG_DEF(JSMSG_NO_EXPORT_NAME, 79, 0, JSEXN_SYNTAXERR, "missing name in export statement")
|
||||
MSG_DEF(JSMSG_PAREN_BEFORE_SWITCH, 80, 0, JSEXN_SYNTAXERR, "missing ( before switch expression")
|
||||
MSG_DEF(JSMSG_PAREN_AFTER_SWITCH, 81, 0, JSEXN_SYNTAXERR, "missing ) after switch expression")
|
||||
MSG_DEF(JSMSG_CURLY_BEFORE_SWITCH, 82, 0, JSEXN_SYNTAXERR, "missing { before switch body")
|
||||
MSG_DEF(JSMSG_COLON_AFTER_CASE, 83, 0, JSEXN_SYNTAXERR, "missing : after case label")
|
||||
MSG_DEF(JSMSG_WHILE_AFTER_DO, 84, 0, JSEXN_SYNTAXERR, "missing while after do-loop body")
|
||||
MSG_DEF(JSMSG_PAREN_AFTER_FOR, 85, 0, JSEXN_SYNTAXERR, "missing ( after for")
|
||||
MSG_DEF(JSMSG_SEMI_AFTER_FOR_INIT, 86, 0, JSEXN_SYNTAXERR, "missing ; after for-loop initializer")
|
||||
MSG_DEF(JSMSG_SEMI_AFTER_FOR_COND, 87, 0, JSEXN_SYNTAXERR, "missing ; after for-loop condition")
|
||||
MSG_DEF(JSMSG_PAREN_AFTER_FOR_CTRL, 88, 0, JSEXN_SYNTAXERR, "missing ) after for-loop control")
|
||||
MSG_DEF(JSMSG_CURLY_BEFORE_TRY, 89, 0, JSEXN_SYNTAXERR, "missing { before try block")
|
||||
MSG_DEF(JSMSG_CURLY_AFTER_TRY, 90, 0, JSEXN_SYNTAXERR, "missing } after try block")
|
||||
MSG_DEF(JSMSG_PAREN_BEFORE_CATCH, 91, 0, JSEXN_SYNTAXERR, "missing ( before catch")
|
||||
MSG_DEF(JSMSG_CATCH_IDENTIFIER, 92, 0, JSEXN_SYNTAXERR, "missing identifier in catch")
|
||||
MSG_DEF(JSMSG_PAREN_AFTER_CATCH, 93, 0, JSEXN_SYNTAXERR, "missing ) after catch")
|
||||
MSG_DEF(JSMSG_CURLY_BEFORE_CATCH, 94, 0, JSEXN_SYNTAXERR, "missing { before catch block")
|
||||
MSG_DEF(JSMSG_CURLY_AFTER_CATCH, 95, 0, JSEXN_SYNTAXERR, "missing } after catch block")
|
||||
MSG_DEF(JSMSG_CURLY_BEFORE_FINALLY, 96, 0, JSEXN_SYNTAXERR, "missing { before finally block")
|
||||
MSG_DEF(JSMSG_CURLY_AFTER_FINALLY, 97, 0, JSEXN_SYNTAXERR, "missing } after finally block")
|
||||
MSG_DEF(JSMSG_CATCH_OR_FINALLY, 98, 0, JSEXN_SYNTAXERR, "missing catch or finally after try")
|
||||
MSG_DEF(JSMSG_PAREN_BEFORE_WITH, 99, 0, JSEXN_SYNTAXERR, "missing ( before with-statement object")
|
||||
MSG_DEF(JSMSG_PAREN_AFTER_WITH, 100, 0, JSEXN_SYNTAXERR, "missing ) after with-statement object")
|
||||
MSG_DEF(JSMSG_CURLY_IN_COMPOUND, 101, 0, JSEXN_SYNTAXERR, "missing } in compound statement")
|
||||
MSG_DEF(JSMSG_NO_VARIABLE_NAME, 102, 0, JSEXN_SYNTAXERR, "missing variable name")
|
||||
MSG_DEF(JSMSG_COLON_IN_COND, 103, 0, JSEXN_SYNTAXERR, "missing : in conditional expression")
|
||||
MSG_DEF(JSMSG_PAREN_AFTER_ARGS, 104, 0, JSEXN_SYNTAXERR, "missing ) after argument list")
|
||||
MSG_DEF(JSMSG_BRACKET_AFTER_LIST, 105, 0, JSEXN_SYNTAXERR, "missing ] after element list")
|
||||
MSG_DEF(JSMSG_COLON_AFTER_ID, 106, 0, JSEXN_SYNTAXERR, "missing : after property id")
|
||||
MSG_DEF(JSMSG_CURLY_AFTER_LIST, 107, 0, JSEXN_SYNTAXERR, "missing } after property list")
|
||||
MSG_DEF(JSMSG_PAREN_IN_PAREN, 108, 0, JSEXN_SYNTAXERR, "missing ) in parenthetical")
|
||||
MSG_DEF(JSMSG_SEMI_BEFORE_STMNT, 109, 0, JSEXN_SYNTAXERR, "missing ; before statement")
|
||||
MSG_DEF(JSMSG_NO_RETURN_VALUE, 110, 0, JSEXN_NONE, "function does not always return a value")
|
||||
MSG_DEF(JSMSG_DUPLICATE_FORMAL, 111, 1, JSEXN_NONE, "duplicate formal argument {0}")
|
||||
MSG_DEF(JSMSG_EQUAL_AS_ASSIGN, 112, 1, JSEXN_NONE, "test for equality (==) mistyped as assignment (=)?{0}")
|
||||
MSG_DEF(JSMSG_BAD_IMPORT, 113, 0, JSEXN_SYNTAXERR, "invalid import expression")
|
||||
MSG_DEF(JSMSG_TOO_MANY_DEFAULTS, 114, 0, JSEXN_SYNTAXERR, "more than one switch default")
|
||||
MSG_DEF(JSMSG_TOO_MANY_CASES, 115, 0, JSEXN_INTERNALERR, "too many switch cases")
|
||||
MSG_DEF(JSMSG_BAD_SWITCH, 116, 0, JSEXN_SYNTAXERR, "invalid switch statement")
|
||||
MSG_DEF(JSMSG_BAD_FOR_LEFTSIDE, 117, 0, JSEXN_SYNTAXERR, "invalid for/in left-hand side")
|
||||
MSG_DEF(JSMSG_CATCH_AFTER_GENERAL, 118, 0, JSEXN_NONE, "catch clause after general catch")
|
||||
MSG_DEF(JSMSG_CATCH_WITHOUT_TRY, 119, 0, JSEXN_SYNTAXERR, "catch without try")
|
||||
MSG_DEF(JSMSG_FINALLY_WITHOUT_TRY, 120, 0, JSEXN_SYNTAXERR, "finally without try")
|
||||
MSG_DEF(JSMSG_LABEL_NOT_FOUND, 121, 0, JSEXN_SYNTAXERR, "label not found")
|
||||
MSG_DEF(JSMSG_TOUGH_BREAK, 122, 0, JSEXN_SYNTAXERR, "invalid break")
|
||||
MSG_DEF(JSMSG_BAD_CONTINUE, 123, 0, JSEXN_SYNTAXERR, "invalid continue")
|
||||
MSG_DEF(JSMSG_BAD_RETURN, 124, 0, JSEXN_SYNTAXERR, "invalid return")
|
||||
MSG_DEF(JSMSG_BAD_LABEL, 125, 0, JSEXN_SYNTAXERR, "invalid label")
|
||||
MSG_DEF(JSMSG_DUPLICATE_LABEL, 126, 0, JSEXN_SYNTAXERR, "duplicate label")
|
||||
MSG_DEF(JSMSG_VAR_HIDES_ARG, 127, 1, JSEXN_NONE, "variable {0} hides argument")
|
||||
MSG_DEF(JSMSG_BAD_VAR_INIT, 128, 0, JSEXN_SYNTAXERR, "invalid variable initialization")
|
||||
MSG_DEF(JSMSG_BAD_LEFTSIDE_OF_ASS, 129, 0, JSEXN_SYNTAXERR, "invalid assignment left-hand side")
|
||||
MSG_DEF(JSMSG_BAD_OPERAND, 130, 1, JSEXN_SYNTAXERR, "invalid {0} operand")
|
||||
MSG_DEF(JSMSG_BAD_PROP_ID, 131, 0, JSEXN_SYNTAXERR, "invalid property id")
|
||||
MSG_DEF(JSMSG_RESERVED_ID, 132, 1, JSEXN_SYNTAXERR, "{0} is a reserved identifier")
|
||||
MSG_DEF(JSMSG_SYNTAX_ERROR, 133, 0, JSEXN_SYNTAXERR, "syntax error")
|
||||
MSG_DEF(JSMSG_BAD_SHARP_VAR_DEF, 134, 0, JSEXN_SYNTAXERR, "invalid sharp variable definition")
|
||||
MSG_DEF(JSMSG_BAD_PROTOTYPE, 135, 1, JSEXN_ERR, "'prototype' property of {0} is not an object")
|
||||
@@ -17,25 +17,25 @@
|
||||
* in the importing module's import address table.
|
||||
*/
|
||||
|
||||
PR_IMPLEMENT(JSPropertyOp)
|
||||
IMPLEMENT(JSPropertyOp)
|
||||
js_GetArgumentAddress()
|
||||
{
|
||||
return ((void *)js_GetArgument);
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(JSPropertyOp)
|
||||
IMPLEMENT(JSPropertyOp)
|
||||
js_SetArgumentAddress()
|
||||
{
|
||||
return ((void *)js_SetArgument);
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(JSPropertyOp)
|
||||
IMPLEMENT(JSPropertyOp)
|
||||
js_GetLocalVariableAddress()
|
||||
{
|
||||
return ((void *)js_GetLocalVariable);
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(JSPropertyOp)
|
||||
IMPLEMENT(JSPropertyOp)
|
||||
js_SetLocalVariableAddress()
|
||||
{
|
||||
return ((void *)js_SetLocalVariable);
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
#ifndef jsaddr_h___
|
||||
#define jsaddr_h___
|
||||
|
||||
PR_EXTERN(JSPropertyOp)
|
||||
EXTERN(JSPropertyOp)
|
||||
js_GetArgumentAddress();
|
||||
|
||||
PR_EXTERN(JSPropertyOp)
|
||||
EXTERN(JSPropertyOp)
|
||||
js_SetArgumentAddress();
|
||||
|
||||
PR_EXTERN(JSPropertyOp)
|
||||
EXTERN(JSPropertyOp)
|
||||
js_GetLocalVariableAddress();
|
||||
|
||||
PR_EXTERN(JSPropertyOp)
|
||||
EXTERN(JSPropertyOp)
|
||||
js_SetLocalVariableAddress();
|
||||
|
||||
#endif /* jsaddr_h___ */
|
||||
|
||||
@@ -24,14 +24,18 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "jstypes.h"
|
||||
#ifndef NSPR20
|
||||
#include "prarena.h"
|
||||
#include "jsarena.h"
|
||||
#else
|
||||
#include "plarena.h"
|
||||
/* Removed by JSIFY: #include "plarena.h"
|
||||
*/
|
||||
#include "jsarena.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "prlog.h"
|
||||
#include "prclist.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#include "jsclist.h"
|
||||
#include "jsprf.h"
|
||||
#include "jsapi.h"
|
||||
#include "jsarray.h"
|
||||
#include "jsatom.h"
|
||||
@@ -40,6 +44,7 @@
|
||||
#include "jsconfig.h"
|
||||
#include "jsdate.h"
|
||||
#include "jsemit.h"
|
||||
#include "jsexn.h"
|
||||
#include "jsfun.h"
|
||||
#include "jsgc.h"
|
||||
#include "jsinterp.h"
|
||||
@@ -56,7 +61,7 @@
|
||||
#include "jsstr.h"
|
||||
|
||||
#if defined(JS_PARANOID_REQUEST) && defined(JS_THREADSAFE)
|
||||
#define CHECK_REQUEST(cx) PR_ASSERT(cx->requestDepth)
|
||||
#define CHECK_REQUEST(cx) JS_ASSERT(cx->requestDepth)
|
||||
#else
|
||||
#define CHECK_REQUEST(cx) ((void)0)
|
||||
#endif
|
||||
@@ -107,9 +112,9 @@ JS_ConvertArguments(JSContext *cx, uintN argc, jsval *argv, const char *format,
|
||||
i = 0;
|
||||
required = JS_TRUE;
|
||||
for (cp = format; *cp != '\0'; cp++) {
|
||||
if (isspace(*cp))
|
||||
if (isspace(*cp))
|
||||
continue;
|
||||
if (*cp == '/') {
|
||||
if (*cp == '/') {
|
||||
required = JS_FALSE;
|
||||
continue;
|
||||
}
|
||||
@@ -117,82 +122,88 @@ JS_ConvertArguments(JSContext *cx, uintN argc, jsval *argv, const char *format,
|
||||
if (required) {
|
||||
fun = js_ValueToFunction(cx, &argv[-2], JS_FALSE);
|
||||
if (fun) {
|
||||
JS_ReportError(cx,
|
||||
"%s requires more than %u argument%s",
|
||||
JS_GetFunctionName(fun),
|
||||
argc, (argc == 1) ? "" : "s");
|
||||
char numBuf[12];
|
||||
JS_snprintf(numBuf, sizeof numBuf, "%u", argc);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_MORE_ARGS_NEEDED,
|
||||
JS_GetFunctionName(fun), numBuf,
|
||||
(argc == 1) ? "" : "s");
|
||||
}
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
switch (*cp) {
|
||||
case 'b':
|
||||
switch (*cp) {
|
||||
case 'b':
|
||||
if (!js_ValueToBoolean(cx, argv[i], va_arg(ap, JSBool *)))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
break;
|
||||
case 'c':
|
||||
case 'c':
|
||||
if (!js_ValueToUint16(cx, argv[i], va_arg(ap, uint16 *)))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
break;
|
||||
case 'i':
|
||||
case 'i':
|
||||
if (!js_ValueToECMAInt32(cx, argv[i], va_arg(ap, int32 *)))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
break;
|
||||
case 'u':
|
||||
case 'u':
|
||||
if (!js_ValueToECMAUint32(cx, argv[i], va_arg(ap, uint32 *)))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
break;
|
||||
case 'j':
|
||||
case 'j':
|
||||
if (!js_ValueToInt32(cx, argv[i], va_arg(ap, int32 *)))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
break;
|
||||
case 'd':
|
||||
case 'd':
|
||||
if (!js_ValueToNumber(cx, argv[i], va_arg(ap, jsdouble *)))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
break;
|
||||
case 'I':
|
||||
case 'I':
|
||||
if (!js_ValueToNumber(cx, argv[i], &d))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
*va_arg(ap, jsdouble *) = js_DoubleToInteger(d);
|
||||
break;
|
||||
case 's':
|
||||
case 's':
|
||||
str = js_ValueToString(cx, argv[i]);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
argv[i] = STRING_TO_JSVAL(str);
|
||||
*va_arg(ap, char **) = JS_GetStringBytes(str);
|
||||
break;
|
||||
case 'S':
|
||||
case 'S':
|
||||
str = js_ValueToString(cx, argv[i]);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
argv[i] = STRING_TO_JSVAL(str);
|
||||
*va_arg(ap, JSString **) = str;
|
||||
break;
|
||||
case 'o':
|
||||
case 'o':
|
||||
if (!js_ValueToObject(cx, argv[i], &obj))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
argv[i] = OBJECT_TO_JSVAL(obj);
|
||||
*va_arg(ap, JSObject **) = obj;
|
||||
break;
|
||||
case 'f':
|
||||
case 'f':
|
||||
fun = js_ValueToFunction(cx, &argv[i], JS_FALSE);
|
||||
if (!fun)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
argv[i] = OBJECT_TO_JSVAL(fun->object);
|
||||
*va_arg(ap, JSFunction **) = fun;
|
||||
break;
|
||||
case 'v':
|
||||
case 'v':
|
||||
*va_arg(ap, jsval *) = argv[i];
|
||||
break;
|
||||
case '*':
|
||||
case '*':
|
||||
break;
|
||||
default:
|
||||
JS_ReportError(cx, "invalid format character %c", *cp);
|
||||
default: {
|
||||
char charBuf[2] = " ";
|
||||
charBuf[0] = *cp;
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_CHAR,
|
||||
charBuf);
|
||||
return JS_FALSE;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
va_end(ap);
|
||||
return JS_TRUE;
|
||||
@@ -201,7 +212,7 @@ JS_ConvertArguments(JSContext *cx, uintN argc, jsval *argv, const char *format,
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_ConvertValue(JSContext *cx, jsval v, JSType type, jsval *vp)
|
||||
{
|
||||
JSBool ok=JS_FALSE, b;
|
||||
JSBool ok = JS_FALSE, b;
|
||||
JSObject *obj;
|
||||
JSFunction *fun;
|
||||
JSString *str;
|
||||
@@ -243,10 +254,14 @@ JS_ConvertValue(JSContext *cx, jsval v, JSType type, jsval *vp)
|
||||
if (ok)
|
||||
*vp = BOOLEAN_TO_JSVAL(b);
|
||||
break;
|
||||
default:
|
||||
JS_ReportError(cx, "unknown type %d", (int)type);
|
||||
default: {
|
||||
char numBuf[12];
|
||||
JS_snprintf(numBuf, sizeof numBuf, "%d", (int)type);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_TYPE,
|
||||
numBuf);
|
||||
ok = JS_FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
@@ -334,16 +349,16 @@ JS_TypeOfValue(JSContext *cx, jsval v)
|
||||
type = JSTYPE_VOID;
|
||||
} else if (JSVAL_IS_OBJECT(v)) {
|
||||
obj = JSVAL_TO_OBJECT(v);
|
||||
if (obj &&
|
||||
(ops = obj->map->ops,
|
||||
if (obj &&
|
||||
(ops = obj->map->ops,
|
||||
ops == &js_ObjectOps
|
||||
? (clasp = OBJ_GET_CLASS(cx, obj),
|
||||
? (clasp = OBJ_GET_CLASS(cx, obj),
|
||||
clasp->call || clasp == &js_FunctionClass)
|
||||
: ops->call != 0)) {
|
||||
type = JSTYPE_FUNCTION;
|
||||
} else {
|
||||
type = JSTYPE_OBJECT;
|
||||
}
|
||||
: ops->call != 0)) {
|
||||
type = JSTYPE_FUNCTION;
|
||||
} else {
|
||||
type = JSTYPE_OBJECT;
|
||||
}
|
||||
} else if (JSVAL_IS_NUMBER(v)) {
|
||||
type = JSTYPE_NUMBER;
|
||||
} else if (JSVAL_IS_STRING(v)) {
|
||||
@@ -370,6 +385,22 @@ JS_NewRuntime(uint32 maxbytes)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
|
||||
#ifdef DEBUG
|
||||
JS_BEGIN_MACRO
|
||||
/*
|
||||
* This code asserts that the numbers associated with the error names in
|
||||
* jsmsg.def are monotonically increasing. It uses values for the error
|
||||
* names enumerated in jscntxt.c. It's not a compiletime check, but it's
|
||||
* better than nothing.
|
||||
*/
|
||||
int errorNumber = 0;
|
||||
#define MSG_DEF(name, number, count, exception, format) \
|
||||
JS_ASSERT(name == errorNumber++);
|
||||
#include "js.msg"
|
||||
#undef MSG_DEF
|
||||
JS_END_MACRO;
|
||||
#endif /* DEBUG */
|
||||
|
||||
if (!js_InitStringGlobals())
|
||||
return NULL;
|
||||
rt = malloc(sizeof(JSRuntime));
|
||||
@@ -392,9 +423,9 @@ JS_NewRuntime(uint32 maxbytes)
|
||||
js_NewLock(&rt->rtLock);
|
||||
#endif
|
||||
rt->propertyCache.empty = JS_TRUE;
|
||||
PR_INIT_CLIST(&rt->contextList);
|
||||
PR_INIT_CLIST(&rt->trapList);
|
||||
PR_INIT_CLIST(&rt->watchPointList);
|
||||
JS_INIT_CLIST(&rt->contextList);
|
||||
JS_INIT_CLIST(&rt->trapList);
|
||||
JS_INIT_CLIST(&rt->watchPointList);
|
||||
return rt;
|
||||
|
||||
bad:
|
||||
@@ -458,7 +489,7 @@ JS_EndRequest(JSContext *cx)
|
||||
if (!cx->requestDepth) {
|
||||
rt = cx->runtime;
|
||||
JS_LOCK_GC(rt);
|
||||
PR_ASSERT(rt->requestCount > 0);
|
||||
JS_ASSERT(rt->requestCount > 0);
|
||||
rt->requestCount--;
|
||||
JS_NOTIFY_REQUEST_DONE(rt);
|
||||
JS_UNLOCK_GC(rt);
|
||||
@@ -473,7 +504,7 @@ JS_YieldRequest(JSContext *cx)
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
|
||||
PR_ASSERT(rt->requestCount > 0);
|
||||
JS_ASSERT(rt->requestCount > 0);
|
||||
rt->requestCount--;
|
||||
JS_NOTIFY_REQUEST_DONE(rt);
|
||||
JS_UNLOCK_GC(rt);
|
||||
@@ -493,7 +524,7 @@ JS_SuspendRequest(JSContext *cx)
|
||||
if (!cx->requestDepth) {
|
||||
rt = cx->runtime;
|
||||
JS_LOCK_GC(rt);
|
||||
PR_ASSERT(rt->requestCount > 0);
|
||||
JS_ASSERT(rt->requestCount > 0);
|
||||
rt->requestCount--;
|
||||
JS_UNLOCK_GC(rt);
|
||||
}
|
||||
@@ -635,9 +666,9 @@ JS_InitStandardClasses(JSContext *cx, JSObject *obj)
|
||||
* (proposed ECMA v2.)
|
||||
*/
|
||||
if (!OBJ_DEFINE_PROPERTY(cx, obj,
|
||||
(jsid)cx->runtime->atomState.typeAtoms[JSTYPE_VOID],
|
||||
JSVAL_VOID, NULL, NULL, 0, NULL))
|
||||
return JS_FALSE;
|
||||
(jsid)cx->runtime->atomState.typeAtoms[JSTYPE_VOID],
|
||||
JSVAL_VOID, NULL, NULL, 0, NULL))
|
||||
return JS_FALSE;
|
||||
#endif
|
||||
|
||||
/* Initialize the function class first so constructors can be made. */
|
||||
@@ -667,6 +698,9 @@ JS_InitStandardClasses(JSContext *cx, JSObject *obj)
|
||||
#endif
|
||||
#if JS_HAS_SCRIPT_OBJECT
|
||||
js_InitScriptClass(cx, obj) &&
|
||||
#endif
|
||||
#if JS_HAS_ERROR_EXCEPTIONS
|
||||
js_InitExceptionClasses(cx, obj) &&
|
||||
#endif
|
||||
js_InitDateClass(cx, obj);
|
||||
}
|
||||
@@ -683,7 +717,7 @@ JS_malloc(JSContext *cx, size_t nbytes)
|
||||
{
|
||||
void *p;
|
||||
|
||||
#if defined(XP_OS2) || defined(XP_MAC)
|
||||
#if defined(XP_OS2) || defined(XP_MAC) || defined(AIX)
|
||||
if (nbytes == 0) /*DSR072897 - Windows allows this, OS/2 & Mac don't*/
|
||||
nbytes = 1;
|
||||
#endif
|
||||
@@ -763,9 +797,11 @@ JS_AddNamedRoot(JSContext *cx, void *rp, const char *name)
|
||||
#ifdef DEBUG
|
||||
|
||||
#ifndef NSPR20
|
||||
#include "prhash.h"
|
||||
#include "jshash.h"
|
||||
#else
|
||||
#include "plhash.h"
|
||||
/* Removed by JSIFY: #include "JShash.h"
|
||||
*/
|
||||
#include "jshash.h" /* Added by JSIFY */
|
||||
#endif
|
||||
|
||||
typedef struct NamedRootDumpArgs {
|
||||
@@ -773,8 +809,8 @@ typedef struct NamedRootDumpArgs {
|
||||
void *data;
|
||||
} NamedRootDumpArgs;
|
||||
|
||||
PR_STATIC_CALLBACK(intN)
|
||||
js_named_root_dumper(PRHashEntry *he, intN i, void *arg)
|
||||
STATIC_DLL_CALLBACK(intN)
|
||||
js_named_root_dumper(JSHashEntry *he, intN i, void *arg)
|
||||
{
|
||||
NamedRootDumpArgs *args = arg;
|
||||
|
||||
@@ -792,7 +828,7 @@ JS_DumpNamedRoots(JSRuntime *rt,
|
||||
|
||||
args.dump = dump;
|
||||
args.data = data;
|
||||
PR_HashTableEnumerateEntries(rt->gcRootsHash, js_named_root_dumper, &args);
|
||||
JS_HashTableEnumerateEntries(rt->gcRootsHash, js_named_root_dumper, &args);
|
||||
}
|
||||
|
||||
#endif /* DEBUG */
|
||||
@@ -805,7 +841,7 @@ JS_LockGCThing(JSContext *cx, void *thing)
|
||||
CHECK_REQUEST(cx);
|
||||
ok = js_LockGCThing(cx, thing);
|
||||
if (!ok)
|
||||
JS_ReportError(cx, "can't lock memory");
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_LOCK);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -817,7 +853,7 @@ JS_UnlockGCThing(JSContext *cx, void *thing)
|
||||
CHECK_REQUEST(cx);
|
||||
ok = js_UnlockGCThing(cx, thing);
|
||||
if (!ok)
|
||||
JS_ReportError(cx, "can't unlock memory");
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_UNLOCK);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -825,9 +861,9 @@ JS_PUBLIC_API(void)
|
||||
JS_GC(JSContext *cx)
|
||||
{
|
||||
if (!cx->fp)
|
||||
PR_FinishArenaPool(&cx->stackPool);
|
||||
PR_FinishArenaPool(&cx->codePool);
|
||||
PR_FinishArenaPool(&cx->tempPool);
|
||||
JS_FinishArenaPool(&cx->stackPool);
|
||||
JS_FinishArenaPool(&cx->codePool);
|
||||
JS_FinishArenaPool(&cx->tempPool);
|
||||
js_ForceGC(cx);
|
||||
}
|
||||
|
||||
@@ -871,12 +907,12 @@ JS_ValueToId(JSContext *cx, jsval v, jsid *idp)
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
if (JSVAL_IS_INT(v)) {
|
||||
*idp = v;
|
||||
*idp = v;
|
||||
} else {
|
||||
atom = js_ValueToStringAtom(cx, v);
|
||||
if (!atom)
|
||||
atom = js_ValueToStringAtom(cx, v);
|
||||
if (!atom)
|
||||
return JS_FALSE;
|
||||
*idp = (jsid)atom;
|
||||
*idp = (jsid)atom;
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
@@ -950,12 +986,12 @@ JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
|
||||
return NULL;
|
||||
|
||||
if (!constructor) {
|
||||
/* Lacking a constructor, name the prototype (e.g., Math). */
|
||||
named = OBJ_DEFINE_PROPERTY(cx, obj, (jsid)atom, OBJECT_TO_JSVAL(proto),
|
||||
/* Lacking a constructor, name the prototype (e.g., Math). */
|
||||
named = OBJ_DEFINE_PROPERTY(cx, obj, (jsid)atom, OBJECT_TO_JSVAL(proto),
|
||||
NULL, NULL, 0, NULL);
|
||||
if (!named)
|
||||
goto bad;
|
||||
ctor = proto;
|
||||
ctor = proto;
|
||||
} else {
|
||||
/* Define the constructor function in obj's scope. */
|
||||
fun = js_DefineFunction(cx, obj, atom, constructor, nargs, 0);
|
||||
@@ -974,7 +1010,7 @@ JS_InitClass(JSContext *cx, JSObject *obj, JSObject *parent_proto,
|
||||
if (OBJ_GET_CLASS(cx, ctor) == clasp) {
|
||||
/* XXXMLM - this fails in framesets that are writing over
|
||||
* themselves!
|
||||
* PR_ASSERT(!OBJ_GET_PROTO(cx, ctor));
|
||||
* JS_ASSERT(!OBJ_GET_PROTO(cx, ctor));
|
||||
*/
|
||||
OBJ_SET_PROTO(cx, ctor, proto);
|
||||
}
|
||||
@@ -1023,9 +1059,10 @@ JS_InstanceOf(JSContext *cx, JSObject *obj, JSClass *clasp, jsval *argv)
|
||||
if (argv) {
|
||||
fun = js_ValueToFunction(cx, &argv[-2], JS_FALSE);
|
||||
if (fun) {
|
||||
JS_ReportError(cx, "%s.prototype.%s called on incompatible %s",
|
||||
clasp->name, JS_GetFunctionName(fun),
|
||||
OBJ_GET_CLASS(cx, obj)->name);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_INCOMPATIBLE_PROTO,
|
||||
clasp->name, JS_GetFunctionName(fun),
|
||||
OBJ_GET_CLASS(cx, obj)->name);
|
||||
}
|
||||
}
|
||||
return JS_FALSE;
|
||||
@@ -1037,7 +1074,7 @@ JS_GetPrivate(JSContext *cx, JSObject *obj)
|
||||
jsval v;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
PR_ASSERT(OBJ_GET_CLASS(cx, obj)->flags & JSCLASS_HAS_PRIVATE);
|
||||
JS_ASSERT(OBJ_GET_CLASS(cx, obj)->flags & JSCLASS_HAS_PRIVATE);
|
||||
v = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
|
||||
if (!JSVAL_IS_INT(v))
|
||||
return NULL;
|
||||
@@ -1048,7 +1085,7 @@ JS_PUBLIC_API(JSBool)
|
||||
JS_SetPrivate(JSContext *cx, JSObject *obj, void *data)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
PR_ASSERT(OBJ_GET_CLASS(cx, obj)->flags & JSCLASS_HAS_PRIVATE);
|
||||
JS_ASSERT(OBJ_GET_CLASS(cx, obj)->flags & JSCLASS_HAS_PRIVATE);
|
||||
OBJ_SET_SLOT(cx, obj, JSSLOT_PRIVATE, PRIVATE_TO_JSVAL(data));
|
||||
return JS_TRUE;
|
||||
}
|
||||
@@ -1116,8 +1153,8 @@ JS_GetConstructor(JSContext *cx, JSObject *proto)
|
||||
if (!ok)
|
||||
return NULL;
|
||||
if (!JSVAL_IS_FUNCTION(cx, cval)) {
|
||||
JS_ReportError(cx, "%s has no constructor",
|
||||
OBJ_GET_CLASS(cx, proto)->name);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NO_CONSTRUCTOR,
|
||||
OBJ_GET_CLASS(cx, proto)->name);
|
||||
return NULL;
|
||||
}
|
||||
return JSVAL_TO_OBJECT(cval);
|
||||
@@ -1185,7 +1222,7 @@ JS_DefineObject(JSContext *cx, JSObject *obj, const char *name, JSClass *clasp,
|
||||
CHECK_REQUEST(cx);
|
||||
nobj = js_NewObject(cx, clasp, proto, obj);
|
||||
if (!nobj)
|
||||
return NULL;
|
||||
return NULL;
|
||||
if (!DefineProperty(cx, obj, name, OBJECT_TO_JSVAL(nobj), NULL, NULL, attrs,
|
||||
NULL)) {
|
||||
cx->newborn[GCX_OBJECT] = NULL;
|
||||
@@ -1203,17 +1240,17 @@ JS_DefineConstDoubles(JSContext *cx, JSObject *obj, JSConstDoubleSpec *cds)
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
for (ok = JS_TRUE; cds->name; cds++) {
|
||||
#if PR_ALIGN_OF_DOUBLE == 8
|
||||
#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;
|
||||
jsint i;
|
||||
|
||||
value = (JSDOUBLE_IS_INT(d, i) && INT_FITS_IN_JSVAL(i))
|
||||
? INT_TO_JSVAL(i)
|
||||
: DOUBLE_TO_JSVAL(&cds->dval);
|
||||
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)
|
||||
@@ -1331,8 +1368,8 @@ JS_AliasProperty(JSContext *cx, JSObject *obj, const char *name,
|
||||
}
|
||||
if (obj2 != obj || !OBJ_IS_NATIVE(obj2)) {
|
||||
OBJ_DROP_PROPERTY(cx, obj2, prop);
|
||||
JS_ReportError(cx, "can't alias %s to %s in class %s",
|
||||
alias, name, OBJ_GET_CLASS(cx, obj2)->name);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_ALIAS,
|
||||
alias, name, OBJ_GET_CLASS(cx, obj2)->name);
|
||||
return JS_FALSE;
|
||||
}
|
||||
atom = js_Atomize(cx, alias, strlen(alias), 0);
|
||||
@@ -1369,17 +1406,14 @@ LookupResult(JSContext *cx, JSObject *obj, JSObject *obj2, JSProperty *prop)
|
||||
return rval;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
|
||||
uintN *attrsp, JSBool *foundp)
|
||||
static JSBool
|
||||
GetPropertyAttributes(JSContext *cx, JSObject *obj, JSAtom *atom,
|
||||
uintN *attrsp, JSBool *foundp)
|
||||
{
|
||||
JSAtom *atom;
|
||||
JSObject *obj2;
|
||||
JSProperty *prop;
|
||||
JSBool ok;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
atom = js_Atomize(cx, name, strlen(name), 0);
|
||||
if (!atom)
|
||||
return JS_FALSE;
|
||||
if (!OBJ_LOOKUP_PROPERTY(cx, obj, (jsid)atom, &obj2, &prop))
|
||||
@@ -1397,17 +1431,14 @@ JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
|
||||
return ok;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_SetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
|
||||
uintN attrs, JSBool *foundp)
|
||||
static JSBool
|
||||
SetPropertyAttributes(JSContext *cx, JSObject *obj, JSAtom *atom,
|
||||
uintN attrs, JSBool *foundp)
|
||||
{
|
||||
JSAtom *atom;
|
||||
JSObject *obj2;
|
||||
JSProperty *prop;
|
||||
JSBool ok;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
atom = js_Atomize(cx, name, strlen(name), 0);
|
||||
if (!atom)
|
||||
return JS_FALSE;
|
||||
if (!OBJ_LOOKUP_PROPERTY(cx, obj, (jsid)atom, &obj2, &prop))
|
||||
@@ -1425,6 +1456,27 @@ JS_SetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_GetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
|
||||
uintN *attrsp, JSBool *foundp)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
return GetPropertyAttributes(cx, obj,
|
||||
js_Atomize(cx, name, strlen(name), 0),
|
||||
attrsp, foundp);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_SetPropertyAttributes(JSContext *cx, JSObject *obj, const char *name,
|
||||
uintN attrs, JSBool *foundp)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
return SetPropertyAttributes(cx, obj,
|
||||
js_Atomize(cx, name, strlen(name), 0),
|
||||
attrs, foundp);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp)
|
||||
{
|
||||
@@ -1435,7 +1487,7 @@ JS_LookupProperty(JSContext *cx, JSObject *obj, const char *name, jsval *vp)
|
||||
CHECK_REQUEST(cx);
|
||||
ok = LookupProperty(cx, obj, name, &obj2, &prop);
|
||||
if (ok)
|
||||
*vp = LookupResult(cx, obj, obj2, prop);
|
||||
*vp = LookupResult(cx, obj, obj2, prop);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -1496,6 +1548,28 @@ JS_DefineUCProperty(JSContext *cx, JSObject *obj,
|
||||
attrs, NULL);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_GetUCPropertyAttributes(JSContext *cx, JSObject *obj,
|
||||
const jschar *name, size_t namelen,
|
||||
uintN *attrsp, JSBool *foundp)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
return GetPropertyAttributes(cx, obj,
|
||||
js_AtomizeChars(cx, name, AUTO_NAMELEN(name,namelen), 0),
|
||||
attrsp, foundp);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_SetUCPropertyAttributes(JSContext *cx, JSObject *obj,
|
||||
const jschar *name, size_t namelen,
|
||||
uintN attrs, JSBool *foundp)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
return SetPropertyAttributes(cx, obj,
|
||||
js_AtomizeChars(cx, name, AUTO_NAMELEN(name,namelen), 0),
|
||||
attrs, foundp);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj,
|
||||
const jschar *name, size_t namelen,
|
||||
@@ -1509,7 +1583,7 @@ JS_DefineUCPropertyWithTinyId(JSContext *cx, JSObject *obj,
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
ok = DefineUCProperty(cx, obj, name, namelen, value, getter, setter, attrs,
|
||||
&prop);
|
||||
&prop);
|
||||
if (ok && prop) {
|
||||
if (OBJ_IS_NATIVE(obj)) {
|
||||
sprop = (JSScopeProperty *)prop;
|
||||
@@ -1533,7 +1607,7 @@ JS_LookupUCProperty(JSContext *cx, JSObject *obj,
|
||||
CHECK_REQUEST(cx);
|
||||
ok = LookupUCProperty(cx, obj, name, namelen, &obj2, &prop);
|
||||
if (ok)
|
||||
*vp = LookupResult(cx, obj, obj2, prop);
|
||||
*vp = LookupResult(cx, obj, obj2, prop);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -1641,9 +1715,11 @@ JS_AliasElement(JSContext *cx, JSObject *obj, const char *name, jsint alias)
|
||||
return JS_FALSE;
|
||||
}
|
||||
if (obj2 != obj || !OBJ_IS_NATIVE(obj2)) {
|
||||
char numBuf[12];
|
||||
OBJ_DROP_PROPERTY(cx, obj2, prop);
|
||||
JS_ReportError(cx, "can't alias %ld to %s in class %s",
|
||||
(long)alias, name, OBJ_GET_CLASS(cx, obj2)->name);
|
||||
JS_snprintf(numBuf, sizeof numBuf, "%ld", (long)alias);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_ALIAS,
|
||||
numBuf, name, OBJ_GET_CLASS(cx, obj2)->name);
|
||||
return JS_FALSE;
|
||||
}
|
||||
scope = (JSScope *) obj->map;
|
||||
@@ -1664,7 +1740,7 @@ JS_LookupElement(JSContext *cx, JSObject *obj, jsint index, jsval *vp)
|
||||
CHECK_REQUEST(cx);
|
||||
ok = OBJ_LOOKUP_PROPERTY(cx, obj, INT_TO_JSVAL(index), &obj2, &prop);
|
||||
if (ok)
|
||||
*vp = LookupResult(cx, obj, obj2, prop);
|
||||
*vp = LookupResult(cx, obj, obj2, prop);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -1734,10 +1810,10 @@ JS_Enumerate(JSContext *cx, JSObject *obj)
|
||||
|
||||
/* Get the number of properties to enumerate. */
|
||||
if (!OBJ_ENUMERATE(cx, obj, JSENUMERATE_INIT, &iter_state, &num_properties))
|
||||
goto error;
|
||||
goto error;
|
||||
if (!JSVAL_IS_INT(num_properties)) {
|
||||
PR_ASSERT(0);
|
||||
goto error;
|
||||
JS_ASSERT(0);
|
||||
goto error;
|
||||
}
|
||||
|
||||
n = JSVAL_TO_INT(num_properties);
|
||||
@@ -1762,9 +1838,9 @@ JS_Enumerate(JSContext *cx, JSObject *obj)
|
||||
|
||||
error:
|
||||
if (iter_state != JSVAL_NULL)
|
||||
OBJ_ENUMERATE(cx, obj, JSENUMERATE_DESTROY, &iter_state, 0);
|
||||
OBJ_ENUMERATE(cx, obj, JSENUMERATE_DESTROY, &iter_state, 0);
|
||||
if (ida)
|
||||
JS_DestroyIdArray(cx, ida);
|
||||
JS_DestroyIdArray(cx, ida);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1786,8 +1862,8 @@ JS_NewFunction(JSContext *cx, JSNative call, uintN nargs, uintN flags,
|
||||
|
||||
atom = NULL;
|
||||
if (name) {
|
||||
atom = js_Atomize(cx, name, strlen(name), 0);
|
||||
if (!atom)
|
||||
atom = js_Atomize(cx, name, strlen(name), 0);
|
||||
if (!atom)
|
||||
return NULL;
|
||||
}
|
||||
return js_NewFunction(cx, NULL, call, nargs, flags, parent, atom);
|
||||
@@ -1875,7 +1951,7 @@ CompileTokenStream(JSContext *cx, JSObject *obj, JSTokenStream *ts,
|
||||
lineno = ts->lineno;
|
||||
if (!js_CompileTokenStream(cx, obj, ts, &cg)) {
|
||||
script = NULL;
|
||||
goto out;
|
||||
goto out;
|
||||
}
|
||||
script = js_NewScriptFromCG(cx, &cg, NULL);
|
||||
if (!script)
|
||||
@@ -1946,10 +2022,10 @@ JS_CompileUCScriptForPrincipals(JSContext *cx, JSObject *obj,
|
||||
JSTokenStream *ts;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
mark = PR_ARENA_MARK(&cx->tempPool);
|
||||
mark = JS_ARENA_MARK(&cx->tempPool);
|
||||
ts = js_NewTokenStream(cx, chars, length, filename, lineno, principals);
|
||||
if (!ts)
|
||||
return NULL;
|
||||
return NULL;
|
||||
return CompileTokenStream(cx, obj, ts, mark);
|
||||
}
|
||||
|
||||
@@ -1961,7 +2037,7 @@ JS_CompileFile(JSContext *cx, JSObject *obj, const char *filename)
|
||||
JSTokenStream *ts;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
mark = PR_ARENA_MARK(&cx->tempPool);
|
||||
mark = JS_ARENA_MARK(&cx->tempPool);
|
||||
ts = js_NewFileTokenStream(cx, filename, stdin);
|
||||
if (!ts)
|
||||
return NULL;
|
||||
@@ -1977,10 +2053,10 @@ JS_NewScriptObject(JSContext *cx, JSScript *script)
|
||||
CHECK_REQUEST(cx);
|
||||
obj = js_NewObject(cx, &js_ScriptClass, NULL, NULL);
|
||||
if (!obj)
|
||||
return NULL;
|
||||
return NULL;
|
||||
if (script) {
|
||||
JS_SetPrivate(cx, obj, script);
|
||||
script->object = obj;
|
||||
JS_SetPrivate(cx, obj, script);
|
||||
script->object = obj;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
@@ -2061,7 +2137,7 @@ JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
|
||||
jsval junk;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
mark = PR_ARENA_MARK(&cx->tempPool);
|
||||
mark = JS_ARENA_MARK(&cx->tempPool);
|
||||
ts = js_NewTokenStream(cx, chars, length, filename, lineno, principals);
|
||||
if (!ts) {
|
||||
fun = NULL;
|
||||
@@ -2087,7 +2163,7 @@ JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
|
||||
(JSProperty **)&sprop)) {
|
||||
break;
|
||||
}
|
||||
PR_ASSERT(sprop);
|
||||
JS_ASSERT(sprop);
|
||||
sprop->id = INT_TO_JSVAL(i);
|
||||
OBJ_DROP_PROPERTY(cx, fun->object, (JSProperty *)sprop);
|
||||
}
|
||||
@@ -2103,8 +2179,8 @@ JS_CompileUCFunctionForPrincipals(JSContext *cx, JSObject *obj,
|
||||
}
|
||||
out:
|
||||
if (ts)
|
||||
js_CloseTokenStream(cx, ts);
|
||||
PR_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
js_CloseTokenStream(cx, ts);
|
||||
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
return fun;
|
||||
}
|
||||
|
||||
@@ -2431,7 +2507,30 @@ JS_ReportError(JSContext *cx, const char *format, ...)
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
va_start(ap, format);
|
||||
js_ReportErrorVA(cx, format, ap);
|
||||
js_ReportErrorVA(cx, JSREPORT_ERROR, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback,
|
||||
void *userRef, const uintN errorNumber, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
CHECK_REQUEST(cx);
|
||||
va_start(ap, errorNumber);
|
||||
js_ReportErrorNumberVA(cx, JSREPORT_ERROR, errorCallback, userRef,
|
||||
errorNumber, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
IMPLEMENT(void)
|
||||
JS_ReportWarning(JSContext *cx, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
js_ReportErrorVA(cx, JSREPORT_WARNING, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
@@ -2472,7 +2571,7 @@ JS_NewRegExpObject(JSContext *cx, char *bytes, size_t length, uintN flags)
|
||||
JS_free(cx, chars);
|
||||
return obj;
|
||||
#else
|
||||
JS_ReportError(cx, "sorry, regular expression are not supported");
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NO_REG_EXPS);
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
@@ -2484,7 +2583,7 @@ JS_NewUCRegExpObject(JSContext *cx, jschar *chars, size_t length, uintN flags)
|
||||
#if JS_HAS_REGEXPS
|
||||
return js_NewRegExpObject(cx, chars, length, flags);
|
||||
#else
|
||||
JS_ReportError(cx, "sorry, regular expression are not supported");
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NO_REG_EXPS);
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
@@ -2536,7 +2635,7 @@ JS_IsExceptionPending(JSContext *cx)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
#if JS_HAS_EXCEPTIONS
|
||||
return (JSBool) cx->fp->throwing;
|
||||
return (JSBool) cx->throwing;
|
||||
#else
|
||||
return JS_FALSE;
|
||||
#endif
|
||||
@@ -2547,9 +2646,9 @@ JS_GetPendingException(JSContext *cx, jsval *vp)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
#if JS_HAS_EXCEPTIONS
|
||||
if (!cx->fp->throwing)
|
||||
if (!cx->throwing)
|
||||
return JS_FALSE;
|
||||
*vp = cx->fp->exception;
|
||||
*vp = cx->exception;
|
||||
return JS_TRUE;
|
||||
#else
|
||||
return JS_FALSE;
|
||||
@@ -2561,8 +2660,8 @@ JS_SetPendingException(JSContext *cx, jsval v)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
#if JS_HAS_EXCEPTIONS
|
||||
cx->fp->throwing = JS_TRUE;
|
||||
cx->fp->exception = v;
|
||||
cx->throwing = JS_TRUE;
|
||||
cx->exception = v;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2571,7 +2670,7 @@ JS_ClearPendingException(JSContext *cx)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
#if JS_HAS_EXCEPTIONS
|
||||
cx->fp->throwing = JS_FALSE;
|
||||
cx->throwing = JS_FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <stddef.h>
|
||||
#include "jspubtd.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
* Type tags stored in the low bits of a jsval.
|
||||
@@ -37,11 +37,11 @@ PR_BEGIN_EXTERN_C
|
||||
|
||||
/* Type tag bitfield length and derived macros. */
|
||||
#define JSVAL_TAGBITS 3
|
||||
#define JSVAL_TAGMASK PR_BITMASK(JSVAL_TAGBITS)
|
||||
#define JSVAL_TAGMASK JS_BITMASK(JSVAL_TAGBITS)
|
||||
#define JSVAL_TAG(v) ((v) & JSVAL_TAGMASK)
|
||||
#define JSVAL_SETTAG(v,t) ((v) | (t))
|
||||
#define JSVAL_CLRTAG(v) ((v) & ~(jsval)JSVAL_TAGMASK)
|
||||
#define JSVAL_ALIGN PR_BIT(JSVAL_TAGBITS)
|
||||
#define JSVAL_ALIGN JS_BIT(JSVAL_TAGBITS)
|
||||
|
||||
/* Predicates for type testing. */
|
||||
#define JSVAL_IS_OBJECT(v) (JSVAL_TAG(v) == JSVAL_OBJECT)
|
||||
@@ -269,10 +269,10 @@ JS_NewContext(JSRuntime *rt, size_t stacksize);
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_DestroyContext(JSContext *cx);
|
||||
|
||||
PR_EXTERN(void*)
|
||||
EXTERN(void*)
|
||||
JS_GetContextPrivate(JSContext *cx);
|
||||
|
||||
PR_EXTERN(void)
|
||||
EXTERN(void)
|
||||
JS_SetContextPrivate(JSContext *cx, void *data);
|
||||
|
||||
extern JS_PUBLIC_API(JSRuntime *)
|
||||
@@ -381,7 +381,7 @@ struct JSClass {
|
||||
JSNative construct;
|
||||
JSXDRObjectOp xdrObject;
|
||||
JSHasInstanceOp hasInstance;
|
||||
prword spare[2];
|
||||
jsword spare[2];
|
||||
};
|
||||
|
||||
#define JSCLASS_HAS_PRIVATE 0x01 /* class instances have private slot */
|
||||
@@ -410,7 +410,7 @@ struct JSObjectOps {
|
||||
JSNative construct;
|
||||
JSXDRObjectOp xdrObject;
|
||||
JSHasInstanceOp hasInstance;
|
||||
prword spare[2];
|
||||
jsword spare[2];
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -493,8 +493,8 @@ 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);
|
||||
JSPropertySpec *ps, JSFunctionSpec *fs,
|
||||
JSPropertySpec *static_ps, JSFunctionSpec *static_fs);
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
extern JS_PUBLIC_API(JSClass *)
|
||||
@@ -515,7 +515,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);
|
||||
@@ -605,6 +605,29 @@ JS_DefineUCProperty(JSContext *cx, JSObject *obj,
|
||||
JSPropertyOp getter, JSPropertyOp setter,
|
||||
uintN attrs);
|
||||
|
||||
/*
|
||||
* Determine the attributes (JSPROP_* flags) of a property on a given object.
|
||||
*
|
||||
* If the object does not have a property by that name, *foundp will be
|
||||
* JS_FALSE and the value of *attrsp is undefined.
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_GetUCPropertyAttributes(JSContext *cx, JSObject *obj,
|
||||
const jschar *name, size_t namelen,
|
||||
uintN *attrsp, JSBool *foundp);
|
||||
|
||||
/*
|
||||
* Set the attributes of a property on a given object.
|
||||
*
|
||||
* If the object does not have a property by that name, *foundp will be
|
||||
* JS_FALSE and nothing will be altered.
|
||||
*/
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetUCPropertyAttributes(JSContext *cx, JSObject *obj,
|
||||
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,
|
||||
@@ -698,8 +721,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)
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
@@ -767,10 +790,10 @@ JS_CompileFunction(JSContext *cx, JSObject *obj, const char *name,
|
||||
|
||||
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,
|
||||
@@ -904,6 +927,19 @@ JS_CompareStrings(JSString *str1, JSString *str2);
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_ReportError(JSContext *cx, const char *format, ...);
|
||||
|
||||
/*
|
||||
* As above, but use an errorNumber for the format string
|
||||
*/
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_ReportErrorNumber(JSContext *cx, JSErrorCallback errorCallback,
|
||||
void *userRef, const uintN errorNumber, ...);
|
||||
|
||||
/*
|
||||
* As above, but report a warning instead (JSREPORT_IS_WARNING(report->flags)).
|
||||
*/
|
||||
EXTERN(void)
|
||||
JS_ReportWarning(JSContext *cx, const char *format, ...);
|
||||
|
||||
/*
|
||||
* Complain when out of memory.
|
||||
*/
|
||||
@@ -911,14 +947,38 @@ extern JS_PUBLIC_API(void)
|
||||
JS_ReportOutOfMemory(JSContext *cx);
|
||||
|
||||
struct JSErrorReport {
|
||||
const char *filename; /* source file name, URL, etc., or null */
|
||||
uintN lineno; /* source line number */
|
||||
const char *linebuf; /* offending source line without final '\n' */
|
||||
const char *tokenptr; /* pointer to error token in linebuf */
|
||||
const jschar *uclinebuf; /* unicode (original) line buffer */
|
||||
const jschar *uctokenptr;/* unicode (original) token pointer */
|
||||
const char *filename; /* source file name, URL, etc., or null */
|
||||
uintN lineno; /* source line number */
|
||||
const char *linebuf; /* offending source line without final \n */
|
||||
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 errorNumber; /* the error number, e.g. see js.msg */
|
||||
JSString *ucmessage; /* the (default) error message */
|
||||
JSString **messageArgs; /* arguments for the error message */
|
||||
};
|
||||
|
||||
/*
|
||||
* JSErrorReport flag values.
|
||||
*/
|
||||
|
||||
/* XXX need better classification system */
|
||||
#define JSREPORT_ERROR 0x0
|
||||
#define JSREPORT_WARNING 0x1 /* reported via JS_ReportWarning */
|
||||
|
||||
/*
|
||||
* If JSREPORT_EXCEPTION is set, then a JavaScript-catchable exception
|
||||
* has been thrown for this runtime error, and the host should ignore it.
|
||||
* Exception-aware hosts should also check for JS_IsPendingException if
|
||||
* JS_ExecuteScript returns failure, and signal or propagate the exception, as
|
||||
* appropriate.
|
||||
*/
|
||||
#define JSREPORT_EXCEPTION 0x2
|
||||
|
||||
#define JSREPORT_IS_WARNING(flags) (flags & JSREPORT_WARNING)
|
||||
#define JSREPORT_IS_EXCEPTION(flags) (flags & JSREPORT_EXCEPTION)
|
||||
|
||||
extern JS_PUBLIC_API(JSErrorReporter)
|
||||
JS_SetErrorReporter(JSContext *cx, JSErrorReporter er);
|
||||
|
||||
@@ -993,6 +1053,6 @@ extern JS_PUBLIC_API(JSBool)
|
||||
JS_IsAssigning(JSContext *cx);
|
||||
#endif
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsapi_h___ */
|
||||
|
||||
@@ -24,37 +24,46 @@
|
||||
#include "jsstddef.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "prarena.h"
|
||||
#include "prlog.h"
|
||||
#include "jstypes.h"
|
||||
#include "jsbit.h"
|
||||
#ifndef NSPR20
|
||||
#include "jsarena.h"
|
||||
#else
|
||||
/* Removed by JSIFY: #include "plarena.h"
|
||||
*/
|
||||
#include "jsarena.h" /* Added by JSIFY */
|
||||
#endif
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
extern js_CompareAndSwap(prword *, prword, prword);
|
||||
extern js_CompareAndSwap(jsword *, jsword, jsword);
|
||||
#endif
|
||||
|
||||
static PRArena *arena_freelist;
|
||||
static JSArena *arena_freelist;
|
||||
|
||||
#ifdef PR_ARENAMETER
|
||||
static PRArenaStats *arena_stats_list;
|
||||
#ifdef JS_ARENAMETER
|
||||
static JSArenaStats *arena_stats_list;
|
||||
|
||||
#define COUNT(pool,what) (pool)->stats.what++
|
||||
#else
|
||||
#define COUNT(pool,what) /* nothing */
|
||||
#endif
|
||||
|
||||
#define PR_ARENA_DEFAULT_ALIGN sizeof(double)
|
||||
#define JS_ARENA_DEFAULT_ALIGN sizeof(double)
|
||||
|
||||
PR_PUBLIC_API(void)
|
||||
PR_InitArenaPool(PRArenaPool *pool, const char *name, size_t size, size_t align)
|
||||
IMPLEMENT(void)
|
||||
JS_InitArenaPool(JSArenaPool *pool, const char *name, JSUint32 size, JSUint32 align)
|
||||
{
|
||||
if (align == 0)
|
||||
align = PR_ARENA_DEFAULT_ALIGN;
|
||||
pool->mask = PR_BITMASK(PR_CeilingLog2(align));
|
||||
align = JS_ARENA_DEFAULT_ALIGN;
|
||||
pool->mask = JS_BITMASK(JS_CeilingLog2(align));
|
||||
pool->first.next = NULL;
|
||||
pool->first.base = pool->first.avail = pool->first.limit =
|
||||
(pruword)PR_ARENA_ALIGN(pool, &pool->first + 1);
|
||||
(jsuword)JS_ARENA_ALIGN(pool, &pool->first + 1);
|
||||
pool->current = &pool->first;
|
||||
pool->arenasize = size;
|
||||
#ifdef PR_ARENAMETER
|
||||
#ifdef JS_ARENAMETER
|
||||
memset(&pool->stats, 0, sizeof pool->stats);
|
||||
pool->stats.name = strdup(name);
|
||||
pool->stats.next = arena_stats_list;
|
||||
@@ -62,17 +71,17 @@ PR_InitArenaPool(PRArenaPool *pool, const char *name, size_t size, size_t align)
|
||||
#endif
|
||||
}
|
||||
|
||||
PR_PUBLIC_API(void *)
|
||||
PR_ArenaAllocate(PRArenaPool *pool, size_t nb)
|
||||
IMPLEMENT(void *)
|
||||
JS_ArenaAllocate(JSArenaPool *pool, JSUint32 nb)
|
||||
{
|
||||
PRArena **ap, *a, *b;
|
||||
JSArena **ap, *a, *b;
|
||||
#ifdef JS_THREADSAFE
|
||||
PRArena *c;
|
||||
JSArena *c;
|
||||
#endif
|
||||
size_t sz;
|
||||
JSUint32 sz;
|
||||
void *p;
|
||||
|
||||
PR_ASSERT((nb & pool->mask) == 0);
|
||||
JS_ASSERT((nb & pool->mask) == 0);
|
||||
#if defined(XP_PC) && !defined(_WIN32)
|
||||
if (nb >= 60000U)
|
||||
return 0;
|
||||
@@ -87,8 +96,9 @@ PR_ArenaAllocate(PRArenaPool *pool, size_t nb)
|
||||
if (b->limit - b->base == pool->arenasize) {
|
||||
#ifdef JS_THREADSAFE
|
||||
do {
|
||||
c = b->next;
|
||||
} while (!js_CompareAndSwap((prword *)ap,(prword)b,(prword)c));
|
||||
b = *ap;
|
||||
c = b->next;
|
||||
} while (!js_CompareAndSwap((jsword *)ap,(jsword)b,(jsword)c));
|
||||
#else
|
||||
*ap = b->next;
|
||||
#endif
|
||||
@@ -99,30 +109,30 @@ PR_ArenaAllocate(PRArenaPool *pool, size_t nb)
|
||||
}
|
||||
ap = &b->next;
|
||||
}
|
||||
sz = PR_MAX(pool->arenasize, nb); /* allocate a new arena */
|
||||
sz = JS_MAX(pool->arenasize, nb); /* allocate a new arena */
|
||||
sz += sizeof *a + pool->mask; /* header and alignment slop */
|
||||
b = malloc(sz);
|
||||
if (!b)
|
||||
return 0;
|
||||
a = a->next = b;
|
||||
a->next = NULL;
|
||||
a->limit = (pruword)a + sz;
|
||||
PR_COUNT_ARENA(pool,++);
|
||||
a->limit = (jsuword)a + sz;
|
||||
JS_COUNT_ARENA(pool,++);
|
||||
COUNT(pool, nmallocs);
|
||||
claim:
|
||||
a->base = a->avail = (pruword)PR_ARENA_ALIGN(pool, a + 1);
|
||||
a->base = a->avail = (jsuword)JS_ARENA_ALIGN(pool, a + 1);
|
||||
}
|
||||
p = (void *)a->avail;
|
||||
a->avail += nb;
|
||||
return p;
|
||||
}
|
||||
|
||||
PR_PUBLIC_API(void *)
|
||||
PR_ArenaGrow(PRArenaPool *pool, void *p, size_t size, size_t incr)
|
||||
IMPLEMENT(void *)
|
||||
JS_ArenaGrow(JSArenaPool *pool, void *p, JSUint32 size, JSUint32 incr)
|
||||
{
|
||||
void *newp;
|
||||
|
||||
PR_ARENA_ALLOCATE(newp, pool, size + incr);
|
||||
JS_ARENA_ALLOCATE(newp, pool, size + incr);
|
||||
memcpy(newp, p, size);
|
||||
return newp;
|
||||
}
|
||||
@@ -132,11 +142,11 @@ PR_ArenaGrow(PRArenaPool *pool, void *p, size_t size, size_t incr)
|
||||
* Reset pool->current to point to head in case it pointed at a tail arena.
|
||||
*/
|
||||
static void
|
||||
FreeArenaList(PRArenaPool *pool, PRArena *head, PRBool reallyFree)
|
||||
FreeArenaList(JSArenaPool *pool, JSArena *head, JSBool reallyFree)
|
||||
{
|
||||
PRArena **ap, *a;
|
||||
JSArena **ap, *a;
|
||||
#ifdef JS_THREADSAFE
|
||||
PRArena *b;
|
||||
JSArena *b;
|
||||
#endif
|
||||
|
||||
ap = &head->next;
|
||||
@@ -146,9 +156,9 @@ FreeArenaList(PRArenaPool *pool, PRArena *head, PRBool reallyFree)
|
||||
|
||||
#ifdef DEBUG
|
||||
do {
|
||||
PR_ASSERT(a->base <= a->avail && a->avail <= a->limit);
|
||||
JS_ASSERT(a->base <= a->avail && a->avail <= a->limit);
|
||||
a->avail = a->base;
|
||||
PR_CLEAR_UNUSED(a);
|
||||
JS_CLEAR_UNUSED(a);
|
||||
} while ((a = a->next) != NULL);
|
||||
a = *ap;
|
||||
#endif
|
||||
@@ -156,8 +166,8 @@ FreeArenaList(PRArenaPool *pool, PRArena *head, PRBool reallyFree)
|
||||
if (reallyFree) {
|
||||
do {
|
||||
*ap = a->next;
|
||||
PR_CLEAR_ARENA(a);
|
||||
PR_COUNT_ARENA(pool,--);
|
||||
JS_CLEAR_ARENA(a);
|
||||
JS_COUNT_ARENA(pool,--);
|
||||
free(a);
|
||||
} while ((a = *ap) != NULL);
|
||||
} else {
|
||||
@@ -167,8 +177,8 @@ FreeArenaList(PRArenaPool *pool, PRArena *head, PRBool reallyFree)
|
||||
} while (*ap);
|
||||
#ifdef JS_THREADSAFE
|
||||
do {
|
||||
*ap = b = arena_freelist;
|
||||
} while (!js_CompareAndSwap((prword*)&arena_freelist,(prword)b,(prword)a));
|
||||
*ap = b = arena_freelist;
|
||||
} while (!js_CompareAndSwap((jsword*)&arena_freelist,(jsword)b,(jsword)a));
|
||||
#else
|
||||
*ap = arena_freelist;
|
||||
arena_freelist = a;
|
||||
@@ -179,34 +189,34 @@ FreeArenaList(PRArenaPool *pool, PRArena *head, PRBool reallyFree)
|
||||
pool->current = head;
|
||||
}
|
||||
|
||||
PR_PUBLIC_API(void)
|
||||
PR_ArenaRelease(PRArenaPool *pool, char *mark)
|
||||
IMPLEMENT(void)
|
||||
JS_ArenaRelease(JSArenaPool *pool, char *mark)
|
||||
{
|
||||
PRArena *a;
|
||||
JSArena *a;
|
||||
|
||||
for (a = pool->first.next; a; a = a->next) {
|
||||
if (PR_UPTRDIFF(mark, a) < PR_UPTRDIFF(a->avail, a)) {
|
||||
a->avail = (pruword)PR_ARENA_ALIGN(pool, mark);
|
||||
FreeArenaList(pool, a, PR_TRUE);
|
||||
if (JS_UPTRDIFF(mark, a) < JS_UPTRDIFF(a->avail, a)) {
|
||||
a->avail = (jsuword)JS_ARENA_ALIGN(pool, mark);
|
||||
FreeArenaList(pool, a, JS_TRUE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PR_PUBLIC_API(void)
|
||||
PR_FreeArenaPool(PRArenaPool *pool)
|
||||
IMPLEMENT(void)
|
||||
JS_FreeArenaPool(JSArenaPool *pool)
|
||||
{
|
||||
FreeArenaList(pool, &pool->first, PR_FALSE);
|
||||
FreeArenaList(pool, &pool->first, JS_FALSE);
|
||||
COUNT(pool, ndeallocs);
|
||||
}
|
||||
|
||||
PR_PUBLIC_API(void)
|
||||
PR_FinishArenaPool(PRArenaPool *pool)
|
||||
IMPLEMENT(void)
|
||||
JS_FinishArenaPool(JSArenaPool *pool)
|
||||
{
|
||||
FreeArenaList(pool, &pool->first, PR_TRUE);
|
||||
#ifdef PR_ARENAMETER
|
||||
FreeArenaList(pool, &pool->first, JS_TRUE);
|
||||
#ifdef JS_ARENAMETER
|
||||
{
|
||||
PRArenaStats *stats, **statsp;
|
||||
JSArenaStats *stats, **statsp;
|
||||
|
||||
if (pool->stats.name)
|
||||
free(pool->stats.name);
|
||||
@@ -221,30 +231,30 @@ PR_FinishArenaPool(PRArenaPool *pool)
|
||||
#endif
|
||||
}
|
||||
|
||||
PR_PUBLIC_API(void)
|
||||
PR_CompactArenaPool(PRArenaPool *pool)
|
||||
IMPLEMENT(void)
|
||||
JS_CompactArenaPool(JSArenaPool *pool)
|
||||
{
|
||||
#if 0 /* XP_MAC */
|
||||
PRArena *a = pool->first.next;
|
||||
JSArena *a = pool->first.next;
|
||||
|
||||
while (a) {
|
||||
reallocSmaller(a, a->avail - (pruword)a);
|
||||
reallocSmaller(a, a->avail - (jsuword)a);
|
||||
a->limit = a->avail;
|
||||
a = a->next;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
PR_PUBLIC_API(void)
|
||||
PR_ArenaFinish()
|
||||
IMPLEMENT(void)
|
||||
JS_ArenaFinish()
|
||||
{
|
||||
PRArena *a, *next;
|
||||
JSArena *a, *next;
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
while (arena_freelist) {
|
||||
a = arena_freelist;
|
||||
next = a->next;
|
||||
if (js_CompareAndSwap((prword*)&arena_freelist,(prword)a,(prword)next))
|
||||
if (js_CompareAndSwap((jsword*)&arena_freelist,(jsword)a,(jsword)next))
|
||||
free(a);
|
||||
}
|
||||
#else
|
||||
@@ -256,9 +266,9 @@ PR_ArenaFinish()
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef PR_ARENAMETER
|
||||
PR_PUBLIC_API(void)
|
||||
PR_ArenaCountAllocation(PRArenaPool *pool, size_t nb)
|
||||
#ifdef JS_ARENAMETER
|
||||
IMPLEMENT(void)
|
||||
JS_ArenaCountAllocation(JSArenaPool *pool, JSUint32 nb)
|
||||
{
|
||||
pool->stats.nallocs++;
|
||||
pool->stats.nbytes += nb;
|
||||
@@ -267,14 +277,14 @@ PR_ArenaCountAllocation(PRArenaPool *pool, size_t nb)
|
||||
pool->stats.variance += nb * nb;
|
||||
}
|
||||
|
||||
PR_PUBLIC_API(void)
|
||||
PR_ArenaCountInplaceGrowth(PRArenaPool *pool, size_t size, size_t incr)
|
||||
IMPLEMENT(void)
|
||||
JS_ArenaCountInplaceGrowth(JSArenaPool *pool, JSUint32 size, JSUint32 incr)
|
||||
{
|
||||
pool->stats.ninplace++;
|
||||
}
|
||||
|
||||
PR_PUBLIC_API(void)
|
||||
PR_ArenaCountGrowth(PRArenaPool *pool, size_t size, size_t incr)
|
||||
IMPLEMENT(void)
|
||||
JS_ArenaCountGrowth(JSArenaPool *pool, JSUint32 size, JSUint32 incr)
|
||||
{
|
||||
pool->stats.ngrows++;
|
||||
pool->stats.nbytes += incr;
|
||||
@@ -285,14 +295,14 @@ PR_ArenaCountGrowth(PRArenaPool *pool, size_t size, size_t incr)
|
||||
pool->stats.variance += size * size;
|
||||
}
|
||||
|
||||
PR_PUBLIC_API(void)
|
||||
PR_ArenaCountRelease(PRArenaPool *pool, char *mark)
|
||||
IMPLEMENT(void)
|
||||
JS_ArenaCountRelease(JSArenaPool *pool, char *mark)
|
||||
{
|
||||
pool->stats.nreleases++;
|
||||
}
|
||||
|
||||
PR_PUBLIC_API(void)
|
||||
PR_ArenaCountRetract(PRArenaPool *pool, char *mark)
|
||||
IMPLEMENT(void)
|
||||
JS_ArenaCountRetract(JSArenaPool *pool, char *mark)
|
||||
{
|
||||
pool->stats.nfastrels++;
|
||||
}
|
||||
@@ -300,10 +310,10 @@ PR_ArenaCountRetract(PRArenaPool *pool, char *mark)
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
PR_PUBLIC_API(void)
|
||||
PR_DumpArenaStats(FILE *fp)
|
||||
IMPLEMENT(void)
|
||||
JS_DumpArenaStats(FILE *fp)
|
||||
{
|
||||
PRArenaStats *stats;
|
||||
JSArenaStats *stats;
|
||||
double mean, variance;
|
||||
|
||||
for (stats = arena_stats_list; stats; stats = stats->next) {
|
||||
@@ -330,4 +340,4 @@ PR_DumpArenaStats(FILE *fp)
|
||||
fprintf(fp, " maximum allocation size: %u\n", stats->maxalloc);
|
||||
}
|
||||
}
|
||||
#endif /* PR_ARENAMETER */
|
||||
#endif /* JS_ARENAMETER */
|
||||
246
mozilla/js/src/jsarena.h
Normal file
246
mozilla/js/src/jsarena.h
Normal file
@@ -0,0 +1,246 @@
|
||||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef jsarena_h___
|
||||
#define jsarena_h___
|
||||
/*
|
||||
* Lifetime-based fast allocation, inspired by much prior art, including
|
||||
* "Fast Allocation and Deallocation of Memory Based on Object Lifetimes"
|
||||
* David R. Hanson, Software -- Practice and Experience, Vol. 20(1).
|
||||
*
|
||||
* Also supports LIFO allocation (JS_ARENA_MARK/JS_ARENA_RELEASE).
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "jstypes.h"
|
||||
#include "jscompat.h"
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
typedef struct JSArena JSArena;
|
||||
typedef struct JSArenaPool JSArenaPool;
|
||||
|
||||
struct JSArena {
|
||||
JSArena *next; /* next arena for this lifetime */
|
||||
jsuword base; /* aligned base address, follows this header */
|
||||
jsuword limit; /* one beyond last byte in arena */
|
||||
jsuword avail; /* points to next available byte */
|
||||
};
|
||||
|
||||
#ifdef JS_ARENAMETER
|
||||
typedef struct JSArenaStats JSArenaStats;
|
||||
|
||||
struct JSArenaStats {
|
||||
JSArenaStats *next; /* next in arenaStats list */
|
||||
char *name; /* name for debugging */
|
||||
uint32 narenas; /* number of arenas in pool */
|
||||
uint32 nallocs; /* number of JS_ARENA_ALLOCATE() calls */
|
||||
uint32 nreclaims; /* number of reclaims from freeArenas */
|
||||
uint32 nmallocs; /* number of malloc() calls */
|
||||
uint32 ndeallocs; /* number of lifetime deallocations */
|
||||
uint32 ngrows; /* number of JS_ARENA_GROW() calls */
|
||||
uint32 ninplace; /* number of in-place growths */
|
||||
uint32 nreleases; /* number of JS_ARENA_RELEASE() calls */
|
||||
uint32 nfastrels; /* number of "fast path" releases */
|
||||
size_t nbytes; /* total bytes allocated */
|
||||
size_t maxalloc; /* maximum allocation size in bytes */
|
||||
double variance; /* size variance accumulator */
|
||||
};
|
||||
#endif
|
||||
|
||||
struct JSArenaPool {
|
||||
JSArena first; /* first arena in pool list */
|
||||
JSArena *current; /* arena from which to allocate space */
|
||||
size_t arenasize; /* net exact size of a new arena */
|
||||
jsuword mask; /* alignment mask (power-of-2 - 1) */
|
||||
#ifdef JS_ARENAMETER
|
||||
JSArenaStats stats;
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
* If the including .c file uses only one power-of-2 alignment, it may define
|
||||
* JS_ARENA_CONST_ALIGN_MASK to the alignment mask and save a few instructions
|
||||
* per ALLOCATE and GROW.
|
||||
*/
|
||||
#ifdef JS_ARENA_CONST_ALIGN_MASK
|
||||
#define JS_ARENA_ALIGN(pool, n) (((jsuword)(n) + JS_ARENA_CONST_ALIGN_MASK) \
|
||||
& ~JS_ARENA_CONST_ALIGN_MASK)
|
||||
|
||||
#define JS_INIT_ARENA_POOL(pool, name, size) \
|
||||
JS_InitArenaPool(pool, name, size, JS_ARENA_CONST_ALIGN_MASK + 1)
|
||||
#else
|
||||
#define JS_ARENA_ALIGN(pool, n) (((jsuword)(n) + (pool)->mask) & ~(pool)->mask)
|
||||
#endif
|
||||
|
||||
#define JS_ARENA_ALLOCATE(p, pool, nb) \
|
||||
JS_BEGIN_MACRO \
|
||||
JSArena *_a = (pool)->current; \
|
||||
size_t _nb = JS_ARENA_ALIGN(pool, nb); \
|
||||
jsuword _p = _a->avail; \
|
||||
jsuword _q = _p + _nb; \
|
||||
if (_q > _a->limit) \
|
||||
_p = (jsuword)JS_ArenaAllocate(pool, _nb); \
|
||||
else \
|
||||
_a->avail = _q; \
|
||||
p = (void *)_p; \
|
||||
JS_ArenaCountAllocation(pool, nb); \
|
||||
JS_END_MACRO
|
||||
|
||||
#define JS_ARENA_GROW(p, pool, size, incr) \
|
||||
JS_BEGIN_MACRO \
|
||||
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 { \
|
||||
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))
|
||||
|
||||
#ifdef DEBUG
|
||||
#define free_PATTERN 0xDA
|
||||
#define JS_CLEAR_UNUSED(a) (JS_ASSERT((a)->avail <= (a)->limit), \
|
||||
memset((void*)(a)->avail, free_PATTERN, \
|
||||
(a)->limit - (a)->avail))
|
||||
#define JS_CLEAR_ARENA(a) memset((void*)(a), free_PATTERN, \
|
||||
(a)->limit - (jsuword)(a))
|
||||
#else
|
||||
#define JS_CLEAR_UNUSED(a) /* nothing */
|
||||
#define JS_CLEAR_ARENA(a) /* nothing */
|
||||
#endif
|
||||
|
||||
#define JS_ARENA_RELEASE(pool, mark) \
|
||||
JS_BEGIN_MACRO \
|
||||
char *_m = (char *)(mark); \
|
||||
JSArena *_a = (pool)->current; \
|
||||
if (JS_UPTRDIFF(_m, _a) <= JS_UPTRDIFF(_a->avail, _a)) { \
|
||||
_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
|
||||
#define JS_COUNT_ARENA(pool,op) ((pool)->stats.narenas op)
|
||||
#else
|
||||
#define JS_COUNT_ARENA(pool,op)
|
||||
#endif
|
||||
|
||||
#define JS_ARENA_DESTROY(pool, a, pnext) \
|
||||
JS_BEGIN_MACRO \
|
||||
JS_COUNT_ARENA(pool,--); \
|
||||
if ((pool)->current == (a)) (pool)->current = &(pool)->first; \
|
||||
*(pnext) = (a)->next; \
|
||||
JS_CLEAR_ARENA(a); \
|
||||
free(a); \
|
||||
(a) = NULL; \
|
||||
JS_END_MACRO
|
||||
|
||||
/*
|
||||
* Initialize an arena pool with the given name for debugging and metering,
|
||||
* with a minimum size per arena of size bytes.
|
||||
*/
|
||||
EXTERN(void)
|
||||
JS_InitArenaPool(JSArenaPool *pool, const char *name, JSUint32 size,
|
||||
JSUint32 align);
|
||||
|
||||
/*
|
||||
* Free the arenas in pool. The user may continue to allocate from pool
|
||||
* after calling this function. There is no need to call JS_InitArenaPool()
|
||||
* again unless JS_FinishArenaPool(pool) has been called.
|
||||
*/
|
||||
EXTERN(void)
|
||||
JS_FreeArenaPool(JSArenaPool *pool);
|
||||
|
||||
/*
|
||||
* Free the arenas in pool and finish using it altogether.
|
||||
*/
|
||||
EXTERN(void)
|
||||
JS_FinishArenaPool(JSArenaPool *pool);
|
||||
|
||||
/*
|
||||
* Compact all of the arenas in a pool so that no space is wasted.
|
||||
*/
|
||||
EXTERN(void)
|
||||
JS_CompactArenaPool(JSArenaPool *pool);
|
||||
|
||||
/*
|
||||
* Finish using arenas, freeing all memory associated with them.
|
||||
*/
|
||||
EXTERN(void)
|
||||
JS_ArenaFinish(void);
|
||||
|
||||
/*
|
||||
* Friend functions used by the JS_ARENA_*() macros.
|
||||
*/
|
||||
EXTERN(void *)
|
||||
JS_ArenaAllocate(JSArenaPool *pool, JSUint32 nb);
|
||||
|
||||
EXTERN(void *)
|
||||
JS_ArenaGrow(JSArenaPool *pool, void *p, JSUint32 size, JSUint32 incr);
|
||||
|
||||
EXTERN(void)
|
||||
JS_ArenaRelease(JSArenaPool *pool, char *mark);
|
||||
|
||||
#ifdef JS_ARENAMETER
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
EXTERN(void)
|
||||
JS_ArenaCountAllocation(JSArenaPool *pool, JSUint32 nb);
|
||||
|
||||
EXTERN(void)
|
||||
JS_ArenaCountInplaceGrowth(JSArenaPool *pool, JSUint32 size, JSUint32 incr);
|
||||
|
||||
EXTERN(void)
|
||||
JS_ArenaCountGrowth(JSArenaPool *pool, JSUint32 size, JSUint32incr);
|
||||
|
||||
EXTERN(void)
|
||||
JS_ArenaCountRelease(JSArenaPool *pool, char *mark);
|
||||
|
||||
EXTERN(void)
|
||||
JS_ArenaCountRetract(JSArenaPool *pool, char *mark);
|
||||
|
||||
EXTERN(void)
|
||||
JS_DumpArenaStats(FILE *fp);
|
||||
|
||||
#else /* !JS_ARENAMETER */
|
||||
|
||||
#define JS_ArenaCountAllocation(ap, nb) /* nothing */
|
||||
#define JS_ArenaCountInplaceGrowth(ap, size, incr) /* nothing */
|
||||
#define JS_ArenaCountGrowth(ap, size, incr) /* nothing */
|
||||
#define JS_ArenaCountRelease(ap, mark) /* nothing */
|
||||
#define JS_ArenaCountRetract(ap, mark) /* nothing */
|
||||
|
||||
#endif /* !JS_ARENAMETER */
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsarena_h___ */
|
||||
@@ -22,9 +22,9 @@
|
||||
#include "jsstddef.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "prlog.h"
|
||||
#include "prprf.h"
|
||||
#include "jstypes.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#include "jsapi.h"
|
||||
#include "jsarray.h"
|
||||
#include "jsatom.h"
|
||||
@@ -66,11 +66,11 @@ IdIsIndex(jsid id, jsuint *indexp)
|
||||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
jsint i;
|
||||
i = JSVAL_TO_INT(id);
|
||||
if (i < 0)
|
||||
return JS_FALSE;
|
||||
*indexp = (jsuint)i;
|
||||
return JS_TRUE;
|
||||
i = JSVAL_TO_INT(id);
|
||||
if (i < 0)
|
||||
return JS_FALSE;
|
||||
*indexp = (jsuint)i;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/* It must be a string. */
|
||||
@@ -78,26 +78,26 @@ IdIsIndex(jsid id, jsuint *indexp)
|
||||
cp = str->chars;
|
||||
if (JS7_ISDEC(*cp) && str->length < sizeof(MAXSTR)) {
|
||||
jsuint index = JS7_UNDEC(*cp++);
|
||||
jsuint oldIndex = 0;
|
||||
jsint c;
|
||||
if (index != 0) {
|
||||
while (JS7_ISDEC(*cp)) {
|
||||
oldIndex = index;
|
||||
c = JS7_UNDEC(*cp);
|
||||
index = 10*index + c;
|
||||
cp++;
|
||||
jsuint oldIndex = 0;
|
||||
jsint c;
|
||||
if (index != 0) {
|
||||
while (JS7_ISDEC(*cp)) {
|
||||
oldIndex = index;
|
||||
c = JS7_UNDEC(*cp);
|
||||
index = 10*index + c;
|
||||
cp++;
|
||||
}
|
||||
}
|
||||
/* Make sure all characters were consumed and that it couldn't
|
||||
* have overflowed.
|
||||
*/
|
||||
if (*cp == 0 &&
|
||||
(oldIndex < (MAXINDEX / 10) ||
|
||||
(oldIndex == (MAXINDEX / 10) && c < (MAXINDEX % 10))))
|
||||
{
|
||||
*indexp = index;
|
||||
return JS_TRUE;
|
||||
}
|
||||
}
|
||||
/* Make sure all characters were consumed and that it couldn't
|
||||
* have overflowed.
|
||||
*/
|
||||
if (*cp == 0 &&
|
||||
(oldIndex < (MAXINDEX / 10) ||
|
||||
(oldIndex == (MAXINDEX / 10) && c < (MAXINDEX % 10))))
|
||||
{
|
||||
*indexp = index;
|
||||
return JS_TRUE;
|
||||
}
|
||||
}
|
||||
return JS_FALSE;
|
||||
}
|
||||
@@ -116,18 +116,18 @@ ValueIsLength(JSContext *cx, jsval v, jsuint *lengthp)
|
||||
* javascript.
|
||||
*/
|
||||
if (JSVAL_IS_INT(v)) {
|
||||
i = JSVAL_TO_INT(v);
|
||||
/* jsuint cast does ToUint32 */
|
||||
i = JSVAL_TO_INT(v);
|
||||
/* jsuint cast does ToUint32 */
|
||||
if (lengthp)
|
||||
*lengthp = (jsuint) i;
|
||||
return JS_TRUE;
|
||||
*lengthp = (jsuint) i;
|
||||
return JS_TRUE;
|
||||
}
|
||||
if (JSVAL_IS_DOUBLE(v)) {
|
||||
/*
|
||||
/*
|
||||
* XXXmccabe I'd love to add another check here, against
|
||||
* js_DoubleToInteger(d) != d), so that ValueIsLength matches
|
||||
* IdIsIndex, but it doesn't seem to follow from ECMA.
|
||||
* (seems to be appropriate for IdIsIndex, though).
|
||||
* js_DoubleToInteger(d) != d), so that ValueIsLength matches
|
||||
* IdIsIndex, but it doesn't seem to follow from ECMA.
|
||||
* (seems to be appropriate for IdIsIndex, though).
|
||||
*/
|
||||
return js_ValueToECMAUint32(cx, v, (uint32 *)lengthp);
|
||||
}
|
||||
@@ -142,10 +142,10 @@ ValueToIndex(JSContext *cx, jsval v, jsuint *lengthp)
|
||||
|
||||
if (JSVAL_IS_INT(v)) {
|
||||
i = JSVAL_TO_INT(v);
|
||||
/* jsuint cast does ToUint32. */
|
||||
/* jsuint cast does ToUint32. */
|
||||
if (lengthp)
|
||||
*lengthp = (jsuint)i;
|
||||
return JS_TRUE;
|
||||
*lengthp = (jsuint)i;
|
||||
return JS_TRUE;
|
||||
}
|
||||
return js_ValueToECMAUint32(cx, v, (uint32 *)lengthp);
|
||||
}
|
||||
@@ -165,10 +165,10 @@ js_GetLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp)
|
||||
* called during init time.
|
||||
*/
|
||||
if (JSVAL_IS_INT(v)) {
|
||||
i = JSVAL_TO_INT(v);
|
||||
/* jsuint cast does ToUint32. */
|
||||
*lengthp = (jsuint)i;
|
||||
return JS_TRUE;
|
||||
i = JSVAL_TO_INT(v);
|
||||
/* jsuint cast does ToUint32. */
|
||||
*lengthp = (jsuint)i;
|
||||
return JS_TRUE;
|
||||
}
|
||||
return js_ValueToECMAUint32(cx, v, (uint32 *)lengthp);
|
||||
}
|
||||
@@ -177,8 +177,8 @@ static JSBool
|
||||
IndexToValue(JSContext *cx, jsuint length, jsval *vp)
|
||||
{
|
||||
if (length <= JSVAL_INT_MAX) {
|
||||
*vp = INT_TO_JSVAL(length);
|
||||
return JS_TRUE;
|
||||
*vp = INT_TO_JSVAL(length);
|
||||
return JS_TRUE;
|
||||
}
|
||||
return js_NewDoubleValue(cx, (jsdouble)length, vp);
|
||||
}
|
||||
@@ -198,7 +198,7 @@ IndexToId(JSContext *cx, jsuint length, jsid *idp)
|
||||
atom = js_AtomizeString(cx, str, 0);
|
||||
if (!atom)
|
||||
return JS_FALSE;
|
||||
*idp = (jsid)atom;
|
||||
*idp = (jsid)atom;
|
||||
|
||||
}
|
||||
return JS_TRUE;
|
||||
@@ -211,7 +211,7 @@ js_SetLengthProperty(JSContext *cx, JSObject *obj, jsuint length)
|
||||
jsid id;
|
||||
|
||||
if (!IndexToValue(cx, length, &v))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
id = (jsid) cx->runtime->atomState.lengthAtom;
|
||||
return OBJ_SET_PROPERTY(cx, obj, id, &v);
|
||||
}
|
||||
@@ -229,7 +229,7 @@ js_HasLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp)
|
||||
ok = OBJ_GET_PROPERTY(cx, obj, id, &v);
|
||||
JS_SetErrorReporter(cx, older);
|
||||
if (!ok)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
return ValueIsLength(cx, v, lengthp);
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ array_addProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
if (!(IdIsIndex(id, &index)))
|
||||
return JS_TRUE;
|
||||
if (!js_GetLengthProperty(cx, obj, &length))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
if (index >= length) {
|
||||
length = index + 1;
|
||||
return js_SetLengthProperty(cx, obj, length);
|
||||
@@ -320,7 +320,7 @@ array_join_sub(JSContext *cx, JSObject *obj, JSString *sep, JSBool literalize,
|
||||
size_t nchars, growth, seplen;
|
||||
const jschar *sepstr;
|
||||
JSString *str;
|
||||
PRHashEntry *he;
|
||||
JSHashEntry *he;
|
||||
|
||||
ok = js_GetLengthProperty(cx, obj, &length);
|
||||
if (!ok)
|
||||
@@ -358,7 +358,7 @@ array_join_sub(JSContext *cx, JSObject *obj, JSString *sep, JSBool literalize,
|
||||
nchars = js_strlen(chars);
|
||||
chars = realloc((ochars = chars), nchars * sizeof(jschar) + growth);
|
||||
if (!chars) {
|
||||
free(ochars);
|
||||
free(ochars);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
@@ -495,8 +495,7 @@ array_join(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
static JSBool
|
||||
array_nyi(JSContext *cx, const char *what)
|
||||
{
|
||||
JS_ReportError(cx, "sorry, Array.prototype.%s is not yet implemented",
|
||||
what);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NO_PROTO, what);
|
||||
return JS_FALSE;
|
||||
}
|
||||
#endif
|
||||
@@ -509,7 +508,7 @@ InitArrayObject(JSContext *cx, JSObject *obj, jsuint length, jsval *vector)
|
||||
jsuint index;
|
||||
|
||||
if (!IndexToValue(cx, length, &v))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
id = (jsid) cx->runtime->atomState.lengthAtom;
|
||||
if (!js_DefineProperty(cx, obj, id, v,
|
||||
array_length_getter, array_length_setter,
|
||||
@@ -553,9 +552,9 @@ array_reverse(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
return JS_FALSE;
|
||||
if (!OBJ_GET_PROPERTY(cx, obj, id2, &v2))
|
||||
return JS_FALSE;
|
||||
if (!OBJ_SET_PROPERTY(cx, obj, id, &v2))
|
||||
if (!OBJ_SET_PROPERTY(cx, obj, id, &v2))
|
||||
return JS_FALSE;
|
||||
if (!OBJ_SET_PROPERTY(cx, obj, id2, &v))
|
||||
if (!OBJ_SET_PROPERTY(cx, obj, id2, &v))
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@@ -608,7 +607,7 @@ js_qsort_r(QSortArgs *qa, int lo, int hi)
|
||||
}
|
||||
}
|
||||
|
||||
PRBool
|
||||
JSBool
|
||||
js_qsort(void *vec, size_t nel, size_t elsize, JSComparator cmp, void *arg)
|
||||
{
|
||||
void *pivot;
|
||||
@@ -616,7 +615,7 @@ js_qsort(void *vec, size_t nel, size_t elsize, JSComparator cmp, void *arg)
|
||||
|
||||
pivot = malloc(elsize);
|
||||
if (!pivot)
|
||||
return PR_FALSE;
|
||||
return JS_FALSE;
|
||||
qa.vec = vec;
|
||||
qa.elsize = elsize;
|
||||
qa.pivot = pivot;
|
||||
@@ -624,7 +623,7 @@ js_qsort(void *vec, size_t nel, size_t elsize, JSComparator cmp, void *arg)
|
||||
qa.arg = arg;
|
||||
js_qsort_r(&qa, 0, (int)(nel - 1));
|
||||
free(pivot);
|
||||
return PR_TRUE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
typedef struct CompareArgs {
|
||||
@@ -666,20 +665,20 @@ sort_compare(const void *a, const void *b, void *arg)
|
||||
fval, 2, argv, &rval);
|
||||
if (ok) {
|
||||
ok = js_ValueToNumber(cx, rval, &cmp);
|
||||
/* Clamp cmp to -1, 0, 1. */
|
||||
if (JSDOUBLE_IS_NaN(cmp)) {
|
||||
/* XXX report some kind of error here? ECMA talks about
|
||||
* 'consistent compare functions' that don't return NaN, but is
|
||||
* silent about what the result should be. So we currently
|
||||
* ignore it.
|
||||
*/
|
||||
cmp = 0;
|
||||
} else if (cmp != 0) {
|
||||
cmp = cmp > 0 ? 1 : -1;
|
||||
}
|
||||
} else {
|
||||
/* Clamp cmp to -1, 0, 1. */
|
||||
if (JSDOUBLE_IS_NaN(cmp)) {
|
||||
/* XXX report some kind of error here? ECMA talks about
|
||||
* 'consistent compare functions' that don't return NaN, but is
|
||||
* silent about what the result should be. So we currently
|
||||
* ignore it.
|
||||
*/
|
||||
cmp = 0;
|
||||
} else if (cmp != 0) {
|
||||
cmp = cmp > 0 ? 1 : -1;
|
||||
}
|
||||
} else {
|
||||
ca->status = ok;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (int)cmp;
|
||||
}
|
||||
@@ -699,7 +698,8 @@ array_sort(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
|
||||
if (argc > 0) {
|
||||
if (JSVAL_IS_PRIMITIVE(argv[0])) {
|
||||
JS_ReportError(cx, "invalid Array.prototype.sort argument");
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_BAD_SORT_ARG);
|
||||
return JS_FALSE;
|
||||
}
|
||||
fval = argv[0];
|
||||
@@ -708,7 +708,7 @@ array_sort(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
}
|
||||
|
||||
if (!js_GetLengthProperty(cx, obj, &len))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
vec = JS_malloc(cx, (size_t) len * sizeof(jsval));
|
||||
if (!vec)
|
||||
return JS_FALSE;
|
||||
@@ -828,7 +828,7 @@ array_pop(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
jsval junk;
|
||||
|
||||
if (!js_GetLengthProperty(cx, obj, &index))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
if (index > 0) {
|
||||
index--;
|
||||
if (!IndexToId(cx, index, &id))
|
||||
@@ -856,7 +856,7 @@ array_shift(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
jsval v, junk;
|
||||
|
||||
if (!js_GetLengthProperty(cx, obj, &length))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
if (length > 0) {
|
||||
length--;
|
||||
id = JSVAL_ZERO;
|
||||
@@ -906,8 +906,8 @@ array_unshift(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
if (argc > 0) {
|
||||
/* Slide up the array to make room for argc at the bottom. */
|
||||
if (length > 0) {
|
||||
last = length;
|
||||
while (last--) {
|
||||
last = length;
|
||||
while (last--) {
|
||||
if (!IndexToId(cx, last, &id))
|
||||
return JS_FALSE;
|
||||
if (!IndexToId(cx, last + argc, &id2))
|
||||
@@ -916,7 +916,7 @@ array_unshift(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
return JS_FALSE;
|
||||
if (!OBJ_SET_PROPERTY(cx, obj, id2, &v))
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Copy from argv to the bottom of the array. */
|
||||
@@ -1036,10 +1036,10 @@ array_splice(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
|
||||
/* Find the direction (up or down) to copy and make way for argv. */
|
||||
if (argc > count) {
|
||||
delta = (jsuint)argc - count;
|
||||
last = length;
|
||||
/* (uint) end could be 0, so can't use vanilla >= test */
|
||||
while (last-- > end) {
|
||||
delta = (jsuint)argc - count;
|
||||
last = length;
|
||||
/* (uint) end could be 0, so can't use vanilla >= test */
|
||||
while (last-- > end) {
|
||||
if (!IndexToId(cx, last, &id))
|
||||
return JS_FALSE;
|
||||
if (!IndexToId(cx, last + delta, &id2))
|
||||
@@ -1049,9 +1049,9 @@ array_splice(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
if (!OBJ_SET_PROPERTY(cx, obj, id2, &v))
|
||||
return JS_FALSE;
|
||||
}
|
||||
length += delta;
|
||||
length += delta;
|
||||
} else if (argc < count) {
|
||||
delta = count - (jsuint)argc;
|
||||
delta = count - (jsuint)argc;
|
||||
for (last = end; last < length; last++) {
|
||||
if (!IndexToId(cx, last, &id))
|
||||
return JS_FALSE;
|
||||
@@ -1062,7 +1062,7 @@ array_splice(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
if (!OBJ_SET_PROPERTY(cx, obj, id2, &v))
|
||||
return JS_FALSE;
|
||||
}
|
||||
length -= delta;
|
||||
length -= delta;
|
||||
}
|
||||
|
||||
/* Copy from argv into the hole to complete the splice. */
|
||||
@@ -1103,19 +1103,19 @@ array_concat(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
|
||||
/* XXXmccabe Might make sense to recast all of this as a do-while. */
|
||||
if (js_HasLengthProperty(cx, obj, &length)) {
|
||||
for (slot = 0; slot < length; slot++) {
|
||||
if (!IndexToId(cx, slot, &id))
|
||||
return JS_FALSE;
|
||||
if (!OBJ_GET_PROPERTY(cx, obj, id, &v))
|
||||
return JS_FALSE;
|
||||
if (!OBJ_SET_PROPERTY(cx, nobj, id, &v))
|
||||
return JS_FALSE;
|
||||
}
|
||||
for (slot = 0; slot < length; slot++) {
|
||||
if (!IndexToId(cx, slot, &id))
|
||||
return JS_FALSE;
|
||||
if (!OBJ_GET_PROPERTY(cx, obj, id, &v))
|
||||
return JS_FALSE;
|
||||
if (!OBJ_SET_PROPERTY(cx, nobj, id, &v))
|
||||
return JS_FALSE;
|
||||
}
|
||||
} else {
|
||||
length = 1;
|
||||
v = OBJECT_TO_JSVAL(obj);
|
||||
if (!OBJ_SET_PROPERTY(cx, nobj, JSVAL_ZERO, &v))
|
||||
return JS_FALSE;
|
||||
length = 1;
|
||||
v = OBJECT_TO_JSVAL(obj);
|
||||
if (!OBJ_SET_PROPERTY(cx, nobj, JSVAL_ZERO, &v))
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
@@ -1246,8 +1246,8 @@ Array(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
|
||||
/* If called without new, replace obj with a new Array object. */
|
||||
if (!cx->fp->constructing) {
|
||||
obj = js_NewObject(cx, &js_ArrayClass, NULL, NULL);
|
||||
if (!obj)
|
||||
obj = js_NewObject(cx, &js_ArrayClass, NULL, NULL);
|
||||
if (!obj)
|
||||
return JS_FALSE;
|
||||
*rval = OBJECT_TO_JSVAL(obj);
|
||||
}
|
||||
@@ -1261,7 +1261,7 @@ Array(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
/*
|
||||
* Only use 1 arg as first element for version 1.2; for any other
|
||||
* version (including 1.3), follow ECMA and use it as a length.
|
||||
*/
|
||||
*/
|
||||
vector = NULL;
|
||||
} else {
|
||||
length = (jsuint) argc;
|
||||
@@ -1276,11 +1276,11 @@ js_InitArrayClass(JSContext *cx, JSObject *obj)
|
||||
JSObject *proto;
|
||||
|
||||
proto = JS_InitClass(cx, obj, NULL, &js_ArrayClass, Array, 1,
|
||||
NULL, array_methods, NULL, NULL);
|
||||
NULL, array_methods, NULL, NULL);
|
||||
|
||||
/* Initialize the Array prototype object so it gets a length property. */
|
||||
if (!proto || !InitArrayObject(cx, proto, 0, NULL))
|
||||
return NULL;
|
||||
return NULL;
|
||||
return proto;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "jsprvtd.h"
|
||||
#include "jspubtd.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
extern JSClass js_ArrayClass;
|
||||
|
||||
@@ -48,9 +48,9 @@ js_HasLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
|
||||
*/
|
||||
typedef int (*JSComparator)(const void *a, const void *b, void *arg);
|
||||
|
||||
extern PRBool
|
||||
extern JSBool
|
||||
js_qsort(void *vec, size_t nel, size_t elsize, JSComparator cmp, void *arg);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsarray_h___ */
|
||||
|
||||
@@ -22,13 +22,17 @@
|
||||
#include "jsstddef.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "prlog.h"
|
||||
#include "jstypes.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#ifndef NSPR20
|
||||
#include "prhash.h"
|
||||
#include "jshash.h"
|
||||
#else
|
||||
#include "plhash.h"
|
||||
/* Removed by JSIFY: #include "JShash.h"
|
||||
*/
|
||||
#include "jshash.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "jsprf.h"
|
||||
#include "jsapi.h"
|
||||
#include "jsatom.h"
|
||||
#include "jscntxt.h"
|
||||
@@ -79,12 +83,12 @@ char js_toSource_str[] = "toSource";
|
||||
char js_toString_str[] = "toString";
|
||||
char js_valueOf_str[] = "valueOf";
|
||||
|
||||
#define HASH_OBJECT(o) ((PRHashNumber)(o) >> JSVAL_TAGBITS)
|
||||
#define HASH_INT(i) ((PRHashNumber)(i))
|
||||
#define HASH_DOUBLE(dp) ((PRHashNumber)(((uint32*)(dp))[0] ^ ((uint32*)(dp))[1]))
|
||||
#define HASH_BOOLEAN(b) ((PRHashNumber)(b))
|
||||
#define HASH_OBJECT(o) ((JSHashNumber)(o) >> JSVAL_TAGBITS)
|
||||
#define HASH_INT(i) ((JSHashNumber)(i))
|
||||
#define HASH_DOUBLE(dp) ((JSHashNumber)(((uint32*)(dp))[0] ^ ((uint32*)(dp))[1]))
|
||||
#define HASH_BOOLEAN(b) ((JSHashNumber)(b))
|
||||
|
||||
PR_STATIC_CALLBACK(PRHashNumber)
|
||||
STATIC_DLL_CALLBACK(JSHashNumber)
|
||||
js_hash_atom_key(const void *key)
|
||||
{
|
||||
jsval v;
|
||||
@@ -104,10 +108,10 @@ js_hash_atom_key(const void *key)
|
||||
return HASH_OBJECT(JSVAL_TO_OBJECT(v));
|
||||
if (JSVAL_IS_BOOLEAN(v))
|
||||
return HASH_BOOLEAN(JSVAL_TO_BOOLEAN(v));
|
||||
return (PRHashNumber)v;
|
||||
return (JSHashNumber)v;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(intN)
|
||||
STATIC_DLL_CALLBACK(intN)
|
||||
js_compare_atom_keys(const void *k1, const void *k2)
|
||||
{
|
||||
jsval v1, v2;
|
||||
@@ -116,39 +120,39 @@ js_compare_atom_keys(const void *k1, const void *k2)
|
||||
if (JSVAL_IS_STRING(v1) && JSVAL_IS_STRING(v2))
|
||||
return !js_CompareStrings(JSVAL_TO_STRING(v1), JSVAL_TO_STRING(v2));
|
||||
if (JSVAL_IS_DOUBLE(v1) && JSVAL_IS_DOUBLE(v2)) {
|
||||
double d1 = *JSVAL_TO_DOUBLE(v1);
|
||||
double d2 = *JSVAL_TO_DOUBLE(v2);
|
||||
double d1 = *JSVAL_TO_DOUBLE(v1);
|
||||
double d2 = *JSVAL_TO_DOUBLE(v2);
|
||||
if (JSDOUBLE_IS_NaN(d1))
|
||||
return JSDOUBLE_IS_NaN(d2);
|
||||
#ifdef XP_PC
|
||||
/* XXX MSVC miscompiles such that (NaN == 0) */
|
||||
if (JSDOUBLE_IS_NaN(d2))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
#endif
|
||||
return d1 == d2;
|
||||
}
|
||||
return v1 == v2;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(int)
|
||||
STATIC_DLL_CALLBACK(int)
|
||||
js_compare_stub(const void *v1, const void *v2)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(void *)
|
||||
STATIC_DLL_CALLBACK(void *)
|
||||
js_alloc_atom_space(void *priv, size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
STATIC_DLL_CALLBACK(void)
|
||||
js_free_atom_space(void *priv, void *item)
|
||||
{
|
||||
free(item);
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(PRHashEntry *)
|
||||
STATIC_DLL_CALLBACK(JSHashEntry *)
|
||||
js_alloc_atom(void *priv, const void *key)
|
||||
{
|
||||
JSAtomState *state = priv;
|
||||
@@ -168,8 +172,8 @@ js_alloc_atom(void *priv, const void *key)
|
||||
return &atom->entry;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
js_free_atom(void *priv, PRHashEntry *he, uintN flag)
|
||||
STATIC_DLL_CALLBACK(void)
|
||||
js_free_atom(void *priv, JSHashEntry *he, uintN flag)
|
||||
{
|
||||
if (flag != HT_FREE_ENTRY)
|
||||
return;
|
||||
@@ -179,7 +183,7 @@ js_free_atom(void *priv, PRHashEntry *he, uintN flag)
|
||||
free(he);
|
||||
}
|
||||
|
||||
static PRHashAllocOps atom_alloc_ops = {
|
||||
static JSHashAllocOps atom_alloc_ops = {
|
||||
js_alloc_atom_space, js_free_atom_space,
|
||||
js_alloc_atom, js_free_atom
|
||||
};
|
||||
@@ -193,7 +197,7 @@ js_InitAtomState(JSContext *cx, JSAtomState *state)
|
||||
|
||||
state->runtime = cx->runtime;
|
||||
state->number = 0;
|
||||
state->table = PR_NewHashTable(JS_ATOM_HASH_SIZE, js_hash_atom_key,
|
||||
state->table = JS_NewHashTable(JS_ATOM_HASH_SIZE, js_hash_atom_key,
|
||||
js_compare_atom_keys, js_compare_stub,
|
||||
&atom_alloc_ops, state);
|
||||
if (!state->table) {
|
||||
@@ -212,7 +216,7 @@ js_InitAtomState(JSContext *cx, JSAtomState *state)
|
||||
} \
|
||||
}
|
||||
|
||||
PR_ASSERT(sizeof js_type_str / sizeof js_type_str[0] == JSTYPE_LIMIT);
|
||||
JS_ASSERT(sizeof js_type_str / sizeof js_type_str[0] == JSTYPE_LIMIT);
|
||||
for (i = 0; i < JSTYPE_LIMIT; i++)
|
||||
FROB(typeAtoms[i], js_type_str[i]);
|
||||
|
||||
@@ -251,7 +255,7 @@ void
|
||||
js_FreeAtomState(JSContext *cx, JSAtomState *state)
|
||||
{
|
||||
state->runtime = NULL;
|
||||
PR_HashTableDestroy(state->table);
|
||||
JS_HashTableDestroy(state->table);
|
||||
state->table = NULL;
|
||||
state->number = 0;
|
||||
#ifdef JS_THREADSAFE
|
||||
@@ -264,8 +268,8 @@ typedef struct MarkArgs {
|
||||
JSGCThingMarker mark;
|
||||
} MarkArgs;
|
||||
|
||||
PR_STATIC_CALLBACK(intN)
|
||||
js_atom_marker(PRHashEntry *he, intN i, void *arg)
|
||||
STATIC_DLL_CALLBACK(intN)
|
||||
js_atom_marker(JSHashEntry *he, intN i, void *arg)
|
||||
{
|
||||
JSAtom *atom;
|
||||
jsval key;
|
||||
@@ -290,11 +294,11 @@ js_MarkAtomState(JSAtomState *state, JSGCThingMarker mark)
|
||||
|
||||
args.runtime = state->runtime;
|
||||
args.mark = mark;
|
||||
PR_HashTableEnumerateEntries(state->table, js_atom_marker, &args);
|
||||
JS_HashTableEnumerateEntries(state->table, js_atom_marker, &args);
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(intN)
|
||||
js_atom_sweeper(PRHashEntry *he, intN i, void *arg)
|
||||
STATIC_DLL_CALLBACK(intN)
|
||||
js_atom_sweeper(JSHashEntry *he, intN i, void *arg)
|
||||
{
|
||||
JSAtom *atom;
|
||||
|
||||
@@ -303,7 +307,7 @@ js_atom_sweeper(PRHashEntry *he, intN i, void *arg)
|
||||
atom->flags &= ~ATOM_MARK;
|
||||
return HT_ENUMERATE_NEXT;
|
||||
}
|
||||
PR_ASSERT((atom->flags & ATOM_PINNED) == 0);
|
||||
JS_ASSERT((atom->flags & ATOM_PINNED) == 0);
|
||||
atom->entry.key = NULL;
|
||||
atom->flags = 0;
|
||||
return HT_ENUMERATE_REMOVE;
|
||||
@@ -312,11 +316,11 @@ js_atom_sweeper(PRHashEntry *he, intN i, void *arg)
|
||||
void
|
||||
js_SweepAtomState(JSAtomState *state)
|
||||
{
|
||||
PR_HashTableEnumerateEntries(state->table, js_atom_sweeper, NULL);
|
||||
JS_HashTableEnumerateEntries(state->table, js_atom_sweeper, NULL);
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(intN)
|
||||
js_atom_unpinner(PRHashEntry *he, intN i, void *arg)
|
||||
STATIC_DLL_CALLBACK(intN)
|
||||
js_atom_unpinner(JSHashEntry *he, intN i, void *arg)
|
||||
{
|
||||
JSAtom *atom;
|
||||
|
||||
@@ -328,23 +332,23 @@ js_atom_unpinner(PRHashEntry *he, intN i, void *arg)
|
||||
void
|
||||
js_UnpinPinnedAtoms(JSAtomState *state)
|
||||
{
|
||||
PR_HashTableEnumerateEntries(state->table, js_atom_unpinner, NULL);
|
||||
JS_HashTableEnumerateEntries(state->table, js_atom_unpinner, NULL);
|
||||
}
|
||||
|
||||
static JSAtom *
|
||||
js_AtomizeHashedKey(JSContext *cx, jsval key, PRHashNumber keyHash, uintN flags)
|
||||
js_AtomizeHashedKey(JSContext *cx, jsval key, JSHashNumber keyHash, uintN flags)
|
||||
{
|
||||
JSAtomState *state;
|
||||
PRHashTable *table;
|
||||
PRHashEntry *he, **hep;
|
||||
JSHashTable *table;
|
||||
JSHashEntry *he, **hep;
|
||||
JSAtom *atom;
|
||||
|
||||
state = &cx->runtime->atomState;
|
||||
JS_LOCK(&state->lock,cx);
|
||||
table = state->table;
|
||||
hep = PR_HashTableRawLookup(table, keyHash, (void *)key);
|
||||
hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
|
||||
if ((he = *hep) == NULL) {
|
||||
he = PR_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL);
|
||||
he = JS_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL);
|
||||
if (!he) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
atom = NULL;
|
||||
@@ -363,7 +367,7 @@ JSAtom *
|
||||
js_AtomizeObject(JSContext *cx, JSObject *obj, uintN flags)
|
||||
{
|
||||
jsval key;
|
||||
PRHashNumber keyHash;
|
||||
JSHashNumber keyHash;
|
||||
|
||||
/* XXX must be set in the following order or MSVC1.52 will crash */
|
||||
keyHash = HASH_OBJECT(obj);
|
||||
@@ -375,7 +379,7 @@ JSAtom *
|
||||
js_AtomizeBoolean(JSContext *cx, JSBool b, uintN flags)
|
||||
{
|
||||
jsval key;
|
||||
PRHashNumber keyHash;
|
||||
JSHashNumber keyHash;
|
||||
|
||||
key = BOOLEAN_TO_JSVAL(b);
|
||||
keyHash = HASH_BOOLEAN(b);
|
||||
@@ -386,7 +390,7 @@ JSAtom *
|
||||
js_AtomizeInt(JSContext *cx, jsint i, uintN flags)
|
||||
{
|
||||
jsval key;
|
||||
PRHashNumber keyHash;
|
||||
JSHashNumber keyHash;
|
||||
|
||||
key = INT_TO_JSVAL(i);
|
||||
keyHash = HASH_INT(i);
|
||||
@@ -397,19 +401,19 @@ JSAtom *
|
||||
js_AtomizeDouble(JSContext *cx, jsdouble d, uintN flags)
|
||||
{
|
||||
jsdouble *dp;
|
||||
PRHashNumber keyHash;
|
||||
JSHashNumber keyHash;
|
||||
jsval key;
|
||||
JSAtomState *state;
|
||||
PRHashTable *table;
|
||||
PRHashEntry *he, **hep;
|
||||
JSHashTable *table;
|
||||
JSHashEntry *he, **hep;
|
||||
JSAtom *atom;
|
||||
|
||||
#if PR_ALIGN_OF_DOUBLE == 8
|
||||
#if JS_ALIGN_OF_DOUBLE == 8
|
||||
dp = &d;
|
||||
#else
|
||||
char alignbuf[16];
|
||||
|
||||
dp = (jsdouble *)&alignbuf[8 - ((pruword)&alignbuf & 7)];
|
||||
dp = (jsdouble *)&alignbuf[8 - ((jsuword)&alignbuf & 7)];
|
||||
*dp = d;
|
||||
#endif
|
||||
|
||||
@@ -418,7 +422,7 @@ js_AtomizeDouble(JSContext *cx, jsdouble d, uintN flags)
|
||||
state = &cx->runtime->atomState;
|
||||
JS_LOCK(&state->lock,cx);
|
||||
table = state->table;
|
||||
hep = PR_HashTableRawLookup(table, keyHash, (void *)key);
|
||||
hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
|
||||
if ((he = *hep) == NULL) {
|
||||
#ifdef JS_THREADSAFE
|
||||
uint32 gen = state->tablegen;
|
||||
@@ -429,14 +433,14 @@ js_AtomizeDouble(JSContext *cx, jsdouble d, uintN flags)
|
||||
JS_LOCK(&state->lock,cx);
|
||||
#ifdef JS_THREADSAFE
|
||||
if (state->tablegen != gen) {
|
||||
hep = PR_HashTableRawLookup(table, keyHash, (void *)key);
|
||||
hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
|
||||
if ((he = *hep) != NULL) {
|
||||
atom = (JSAtom *)he;
|
||||
goto out;
|
||||
atom = (JSAtom *)he;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
he = PR_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL);
|
||||
he = JS_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL);
|
||||
if (!he) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
atom = NULL;
|
||||
@@ -454,11 +458,11 @@ out:
|
||||
JSAtom *
|
||||
js_AtomizeString(JSContext *cx, JSString *str, uintN flags)
|
||||
{
|
||||
PRHashNumber keyHash;
|
||||
JSHashNumber keyHash;
|
||||
jsval key;
|
||||
JSAtomState *state;
|
||||
PRHashTable *table;
|
||||
PRHashEntry *he, **hep;
|
||||
JSHashTable *table;
|
||||
JSHashEntry *he, **hep;
|
||||
JSAtom *atom;
|
||||
|
||||
keyHash = js_HashString(str);
|
||||
@@ -466,7 +470,7 @@ js_AtomizeString(JSContext *cx, JSString *str, uintN flags)
|
||||
state = &cx->runtime->atomState;
|
||||
JS_LOCK(&state->lock,cx);
|
||||
table = state->table;
|
||||
hep = PR_HashTableRawLookup(table, keyHash, (void *)key);
|
||||
hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
|
||||
if ((he = *hep) == NULL) {
|
||||
if (flags & ATOM_TMPSTR) {
|
||||
#ifdef JS_THREADSAFE
|
||||
@@ -486,7 +490,7 @@ js_AtomizeString(JSContext *cx, JSString *str, uintN flags)
|
||||
JS_LOCK(&state->lock,cx);
|
||||
#ifdef JS_THREADSAFE
|
||||
if (state->tablegen != gen) {
|
||||
hep = PR_HashTableRawLookup(table, keyHash, (void *)key);
|
||||
hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
|
||||
if ((he = *hep) != NULL) {
|
||||
atom = (JSAtom *)he;
|
||||
goto out;
|
||||
@@ -494,7 +498,7 @@ js_AtomizeString(JSContext *cx, JSString *str, uintN flags)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
he = PR_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL);
|
||||
he = JS_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL);
|
||||
if (!he) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
atom = NULL;
|
||||
@@ -515,14 +519,14 @@ js_Atomize(JSContext *cx, const char *bytes, size_t length, uintN flags)
|
||||
jschar *chars;
|
||||
JSString *str;
|
||||
JSAtom *atom;
|
||||
#if PR_ALIGN_OF_DOUBLE == 8
|
||||
#if JS_ALIGN_OF_DOUBLE == 8
|
||||
union { jsdouble d; JSString s; } u;
|
||||
|
||||
str = &u.s;
|
||||
#else
|
||||
char alignbuf[16];
|
||||
|
||||
str = (JSString *)&alignbuf[8 - ((pruword)&alignbuf & 7)];
|
||||
str = (JSString *)&alignbuf[8 - ((jsuword)&alignbuf & 7)];
|
||||
#endif
|
||||
|
||||
chars = js_InflateString(cx, bytes, length);
|
||||
@@ -540,14 +544,14 @@ JS_FRIEND_API(JSAtom *)
|
||||
js_AtomizeChars(JSContext *cx, const jschar *chars, size_t length, uintN flags)
|
||||
{
|
||||
JSString *str;
|
||||
#if PR_ALIGN_OF_DOUBLE == 8
|
||||
#if JS_ALIGN_OF_DOUBLE == 8
|
||||
union { jsdouble d; JSString s; } u;
|
||||
|
||||
str = &u.s;
|
||||
#else
|
||||
char alignbuf[16];
|
||||
|
||||
str = (JSString *)&alignbuf[8 - ((pruword)&alignbuf & 7)];
|
||||
str = (JSString *)&alignbuf[8 - ((jsuword)&alignbuf & 7)];
|
||||
#endif
|
||||
|
||||
str->chars = (jschar *)chars;
|
||||
@@ -568,7 +572,7 @@ js_AtomizeValue(JSContext *cx, jsval value, uintN flags)
|
||||
return js_AtomizeObject(cx, JSVAL_TO_OBJECT(value), flags);
|
||||
if (JSVAL_IS_BOOLEAN(value))
|
||||
return js_AtomizeBoolean(cx, JSVAL_TO_BOOLEAN(value), flags);
|
||||
return js_AtomizeHashedKey(cx, value, (PRHashNumber)value, flags);
|
||||
return js_AtomizeHashedKey(cx, value, (JSHashNumber)value, flags);
|
||||
}
|
||||
|
||||
JSAtom *
|
||||
@@ -589,7 +593,7 @@ js_IndexAtom(JSContext *cx, JSAtom *atom, JSAtomList *al)
|
||||
|
||||
ATOM_LIST_SEARCH(ale, al, atom);
|
||||
if (!ale) {
|
||||
PR_ARENA_ALLOCATE(ale, &cx->tempPool, sizeof(JSAtomListElement));
|
||||
JS_ARENA_ALLOCATE(ale, &cx->tempPool, sizeof(JSAtomListElement));
|
||||
if (!ale) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return NULL;
|
||||
@@ -607,13 +611,16 @@ js_GetAtom(JSContext *cx, JSAtomMap *map, jsatomid i)
|
||||
{
|
||||
JSAtom *atom;
|
||||
|
||||
PR_ASSERT(map->vector && i < map->length);
|
||||
JS_ASSERT(map->vector && i < map->length);
|
||||
if (!map->vector || i >= map->length) {
|
||||
JS_ReportError(cx, "internal error: no index for atom %ld", (long)i);
|
||||
char numBuf[12];
|
||||
JS_snprintf(numBuf, sizeof numBuf, "%lu", (unsigned long)i);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_BAD_ATOMIC_NUMBER, numBuf);
|
||||
return NULL;
|
||||
}
|
||||
atom = map->vector[i];
|
||||
PR_ASSERT(atom);
|
||||
JS_ASSERT(atom);
|
||||
return atom;
|
||||
}
|
||||
|
||||
@@ -633,7 +640,8 @@ js_InitAtomMap(JSContext *cx, JSAtomMap *map, JSAtomList *al)
|
||||
|
||||
count = al->count;
|
||||
if (count >= ATOM_INDEX_LIMIT) {
|
||||
JS_ReportError(cx, "too many literals");
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_TOO_MANY_LITERALS);
|
||||
return JS_FALSE;
|
||||
}
|
||||
vector = JS_malloc(cx, (size_t) count * sizeof *vector);
|
||||
@@ -641,7 +649,7 @@ js_InitAtomMap(JSContext *cx, JSAtomMap *map, JSAtomList *al)
|
||||
return JS_FALSE;
|
||||
|
||||
do {
|
||||
vector[ale->index] = ale->atom;
|
||||
vector[ale->index] = ale->atom;
|
||||
next = ale->next;
|
||||
ale->next = NULL;
|
||||
} while ((ale = next) != NULL);
|
||||
|
||||
@@ -22,11 +22,13 @@
|
||||
* JS atom table.
|
||||
*/
|
||||
#include <stddef.h>
|
||||
#include "prtypes.h"
|
||||
#include "jstypes.h"
|
||||
#ifndef NSPR20
|
||||
#include "prhash.h"
|
||||
#include "jshash.h"
|
||||
#else
|
||||
#include "plhash.h"
|
||||
/* Removed by JSIFY: #include "JShash.h"
|
||||
*/
|
||||
#include "jshash.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "jsapi.h"
|
||||
#include "jsprvtd.h"
|
||||
@@ -36,7 +38,7 @@
|
||||
#include "jslock.h"
|
||||
#endif
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
#define ATOM_NOCOPY 0x01 /* don't copy atom string bytes */
|
||||
#define ATOM_TMPSTR 0x02 /* internal, to avoid extra string */
|
||||
@@ -44,7 +46,7 @@ PR_BEGIN_EXTERN_C
|
||||
#define ATOM_PINNED 0x08 /* atom is pinned against GC */
|
||||
|
||||
struct JSAtom {
|
||||
PRHashEntry entry; /* key is jsval, value keyword info */
|
||||
JSHashEntry entry; /* key is jsval, value keyword info */
|
||||
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 */
|
||||
@@ -77,19 +79,19 @@ struct JSAtomList {
|
||||
#define ATOM_LIST_INIT(al) ((al)->list = NULL, (al)->count = 0)
|
||||
|
||||
#define ATOM_LIST_SEARCH(_ale,_al,_atom) \
|
||||
PR_BEGIN_MACRO \
|
||||
JSAtomListElement **_alep = &(_al)->list; \
|
||||
while ((_ale = *_alep) != NULL) { \
|
||||
if (_ale->atom == (_atom)) { \
|
||||
/* Hit, move atom's element to the front of the list. */ \
|
||||
*_alep = _ale->next; \
|
||||
_ale->next = (_al)->list; \
|
||||
(_al)->list = _ale; \
|
||||
break; \
|
||||
} \
|
||||
_alep = &_ale->next; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
JS_BEGIN_MACRO \
|
||||
JSAtomListElement **_alep = &(_al)->list; \
|
||||
while ((_ale = *_alep) != NULL) { \
|
||||
if (_ale->atom == (_atom)) { \
|
||||
/* Hit, move atom's element to the front of the list. */ \
|
||||
*_alep = _ale->next; \
|
||||
_ale->next = (_al)->list; \
|
||||
(_al)->list = _ale; \
|
||||
break; \
|
||||
} \
|
||||
_alep = &_ale->next; \
|
||||
} \
|
||||
JS_END_MACRO
|
||||
|
||||
struct JSAtomMap {
|
||||
JSAtom **vector; /* array of ptrs to indexed atoms */
|
||||
@@ -98,7 +100,7 @@ struct JSAtomMap {
|
||||
|
||||
struct JSAtomState {
|
||||
JSRuntime *runtime; /* runtime that owns us */
|
||||
PRHashTable *table; /* hash table containing all atoms */
|
||||
JSHashTable *table; /* hash table containing all atoms */
|
||||
jsatomid number; /* one beyond greatest atom number */
|
||||
|
||||
/* Type names and value literals. */
|
||||
@@ -271,6 +273,6 @@ js_InitAtomMap(JSContext *cx, JSAtomMap *map, JSAtomList *al);
|
||||
extern JS_FRIEND_API(void)
|
||||
js_FreeAtomMap(JSContext *cx, JSAtomMap *map);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsatom_h___ */
|
||||
|
||||
@@ -16,41 +16,41 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef prbit_h___
|
||||
#define prbit_h___
|
||||
#ifndef jsbit_h___
|
||||
#define jsbit_h___
|
||||
|
||||
#include "prtypes.h"
|
||||
PR_BEGIN_EXTERN_C
|
||||
#include "jstypes.h"
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
** A prbitmap_t is a long integer that can be used for bitmaps
|
||||
** A jsbitmap_t is a long integer that can be used for bitmaps
|
||||
*/
|
||||
typedef unsigned long prbitmap_t;
|
||||
typedef unsigned long jsbitmap_t;
|
||||
|
||||
#define PR_TEST_BIT(_map,_bit) \
|
||||
((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] & (1L << ((_bit) & (PR_BITS_PER_LONG-1))))
|
||||
#define PR_SET_BIT(_map,_bit) \
|
||||
((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] |= (1L << ((_bit) & (PR_BITS_PER_LONG-1))))
|
||||
#define PR_CLEAR_BIT(_map,_bit) \
|
||||
((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] &= ~(1L << ((_bit) & (PR_BITS_PER_LONG-1))))
|
||||
#define JS_TEST_BIT(_map,_bit) \
|
||||
((_map)[(_bit)>>JS_BITS_PER_LONG_LOG2] & (1L << ((_bit) & (JS_BITS_PER_LONG-1))))
|
||||
#define JS_SET_BIT(_map,_bit) \
|
||||
((_map)[(_bit)>>JS_BITS_PER_LONG_LOG2] |= (1L << ((_bit) & (JS_BITS_PER_LONG-1))))
|
||||
#define JS_CLEAR_BIT(_map,_bit) \
|
||||
((_map)[(_bit)>>JS_BITS_PER_LONG_LOG2] &= ~(1L << ((_bit) & (JS_BITS_PER_LONG-1))))
|
||||
|
||||
/*
|
||||
** Compute the log of the least power of 2 greater than or equal to n
|
||||
*/
|
||||
PR_EXTERN(PRIntn) PR_CeilingLog2(PRUint32 i);
|
||||
EXTERN(JSIntn) JS_CeilingLog2(JSUint32 i);
|
||||
|
||||
/*
|
||||
** Compute the log of the greatest power of 2 less than or equal to n
|
||||
*/
|
||||
PR_EXTERN(PRIntn) PR_FloorLog2(PRUint32 i);
|
||||
EXTERN(JSIntn) JS_FloorLog2(JSUint32 i);
|
||||
|
||||
/*
|
||||
** Macro version of PR_CeilingLog2: Compute the log of the least power of
|
||||
** Macro version of JS_CeilingLog2: Compute the log of the least power of
|
||||
** 2 greater than or equal to _n. The result is returned in _log2.
|
||||
*/
|
||||
#define PR_CEILING_LOG2(_log2,_n) \
|
||||
PR_BEGIN_MACRO \
|
||||
PRUint32 j_ = (PRUint32)(_n); \
|
||||
#define JS_CEILING_LOG2(_log2,_n) \
|
||||
JS_BEGIN_MACRO \
|
||||
JSUint32 j_ = (JSUint32)(_n); \
|
||||
(_log2) = 0; \
|
||||
if ((j_) & ((j_)-1)) \
|
||||
(_log2) += 1; \
|
||||
@@ -64,17 +64,17 @@ PR_EXTERN(PRIntn) PR_FloorLog2(PRUint32 i);
|
||||
(_log2) += 2, (j_) >>= 2; \
|
||||
if ((j_) >> 1) \
|
||||
(_log2) += 1; \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
/*
|
||||
** Macro version of PR_FloorLog2: Compute the log of the greatest power of
|
||||
** Macro version of JS_FloorLog2: Compute the log of the greatest power of
|
||||
** 2 less than or equal to _n. The result is returned in _log2.
|
||||
**
|
||||
** This is equivalent to finding the highest set bit in the word.
|
||||
*/
|
||||
#define PR_FLOOR_LOG2(_log2,_n) \
|
||||
PR_BEGIN_MACRO \
|
||||
PRUint32 j_ = (PRUint32)(_n); \
|
||||
#define JS_FLOOR_LOG2(_log2,_n) \
|
||||
JS_BEGIN_MACRO \
|
||||
JSUint32 j_ = (JSUint32)(_n); \
|
||||
(_log2) = 0; \
|
||||
if ((j_) >> 16) \
|
||||
(_log2) += 16, (j_) >>= 16; \
|
||||
@@ -86,7 +86,7 @@ PR_EXTERN(PRIntn) PR_FloorLog2(PRUint32 i);
|
||||
(_log2) += 2, (j_) >>= 2; \
|
||||
if ((j_) >> 1) \
|
||||
(_log2) += 1; \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
PR_END_EXTERN_C
|
||||
#endif /* prbit_h___ */
|
||||
JS_END_EXTERN_C
|
||||
#endif /* jsbit_h___ */
|
||||
@@ -20,8 +20,9 @@
|
||||
* JS boolean implementation.
|
||||
*/
|
||||
#include "jsstddef.h"
|
||||
#include "prtypes.h"
|
||||
#include "prlog.h"
|
||||
#include "jstypes.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#include "jsapi.h"
|
||||
#include "jsatom.h"
|
||||
#include "jsbool.h"
|
||||
@@ -41,7 +42,7 @@ static JSClass boolean_class = {
|
||||
};
|
||||
|
||||
#if JS_HAS_TOSOURCE
|
||||
#include "prprf.h"
|
||||
#include "jsprf.h"
|
||||
|
||||
static JSBool
|
||||
bool_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
@@ -56,7 +57,7 @@ bool_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
v = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
|
||||
if (!JSVAL_IS_BOOLEAN(v))
|
||||
return js_obj_toSource(cx, obj, argc, argv, rval);
|
||||
PR_snprintf(buf, sizeof buf, "(new %s(%s))",
|
||||
JS_snprintf(buf, sizeof buf, "(new %s(%s))",
|
||||
boolean_class.name,
|
||||
js_boolean_str[JSVAL_TO_BOOLEAN(v) ? 1 : 0]);
|
||||
str = JS_NewStringCopyZ(cx, buf);
|
||||
@@ -182,7 +183,7 @@ js_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp)
|
||||
return JS_TRUE;
|
||||
}
|
||||
if (JSVAL_IS_OBJECT(v)) {
|
||||
if (cx->version == JSVERSION_1_2) {
|
||||
if (!JSVERSION_IS_ECMA(cx->version)) {
|
||||
if (!OBJ_DEFAULT_VALUE(cx, JSVAL_TO_OBJECT(v), JSTYPE_BOOLEAN, &v))
|
||||
return JS_FALSE;
|
||||
if (!JSVAL_IS_BOOLEAN(v))
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
* JS boolean interface.
|
||||
*/
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
extern JSObject *
|
||||
js_InitBooleanClass(JSContext *cx, JSObject *obj);
|
||||
@@ -36,6 +36,6 @@ js_BooleanToString(JSContext *cx, JSBool b);
|
||||
extern JSBool
|
||||
js_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsbool_h___ */
|
||||
|
||||
@@ -16,106 +16,106 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef prclist_h___
|
||||
#define prclist_h___
|
||||
#ifndef jsclist_h___
|
||||
#define jsclist_h___
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "jstypes.h"
|
||||
|
||||
typedef struct PRCListStr PRCList;
|
||||
typedef struct JSCListStr JSCList;
|
||||
|
||||
/*
|
||||
** Circular linked list
|
||||
*/
|
||||
struct PRCListStr {
|
||||
PRCList *next;
|
||||
PRCList *prev;
|
||||
struct JSCListStr {
|
||||
JSCList *next;
|
||||
JSCList *prev;
|
||||
};
|
||||
|
||||
/*
|
||||
** Insert element "_e" into the list, before "_l".
|
||||
*/
|
||||
#define PR_INSERT_BEFORE(_e,_l) \
|
||||
PR_BEGIN_MACRO \
|
||||
#define JS_INSERT_BEFORE(_e,_l) \
|
||||
JS_BEGIN_MACRO \
|
||||
(_e)->next = (_l); \
|
||||
(_e)->prev = (_l)->prev; \
|
||||
(_l)->prev->next = (_e); \
|
||||
(_l)->prev = (_e); \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
/*
|
||||
** Insert element "_e" into the list, after "_l".
|
||||
*/
|
||||
#define PR_INSERT_AFTER(_e,_l) \
|
||||
PR_BEGIN_MACRO \
|
||||
#define JS_INSERT_AFTER(_e,_l) \
|
||||
JS_BEGIN_MACRO \
|
||||
(_e)->next = (_l)->next; \
|
||||
(_e)->prev = (_l); \
|
||||
(_l)->next->prev = (_e); \
|
||||
(_l)->next = (_e); \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
/*
|
||||
** Return the element following element "_e"
|
||||
*/
|
||||
#define PR_NEXT_LINK(_e) \
|
||||
#define JS_NEXT_LINK(_e) \
|
||||
((_e)->next)
|
||||
/*
|
||||
** Return the element preceding element "_e"
|
||||
*/
|
||||
#define PR_PREV_LINK(_e) \
|
||||
#define JS_PREV_LINK(_e) \
|
||||
((_e)->prev)
|
||||
|
||||
/*
|
||||
** Append an element "_e" to the end of the list "_l"
|
||||
*/
|
||||
#define PR_APPEND_LINK(_e,_l) PR_INSERT_BEFORE(_e,_l)
|
||||
#define JS_APPEND_LINK(_e,_l) JS_INSERT_BEFORE(_e,_l)
|
||||
|
||||
/*
|
||||
** Insert an element "_e" at the head of the list "_l"
|
||||
*/
|
||||
#define PR_INSERT_LINK(_e,_l) PR_INSERT_AFTER(_e,_l)
|
||||
#define JS_INSERT_LINK(_e,_l) JS_INSERT_AFTER(_e,_l)
|
||||
|
||||
/* Return the head/tail of the list */
|
||||
#define PR_LIST_HEAD(_l) (_l)->next
|
||||
#define PR_LIST_TAIL(_l) (_l)->prev
|
||||
#define JS_LIST_HEAD(_l) (_l)->next
|
||||
#define JS_LIST_TAIL(_l) (_l)->prev
|
||||
|
||||
/*
|
||||
** Remove the element "_e" from it's circular list.
|
||||
*/
|
||||
#define PR_REMOVE_LINK(_e) \
|
||||
PR_BEGIN_MACRO \
|
||||
#define JS_REMOVE_LINK(_e) \
|
||||
JS_BEGIN_MACRO \
|
||||
(_e)->prev->next = (_e)->next; \
|
||||
(_e)->next->prev = (_e)->prev; \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
/*
|
||||
** Remove the element "_e" from it's circular list. Also initializes the
|
||||
** linkage.
|
||||
*/
|
||||
#define PR_REMOVE_AND_INIT_LINK(_e) \
|
||||
PR_BEGIN_MACRO \
|
||||
#define JS_REMOVE_AND_INIT_LINK(_e) \
|
||||
JS_BEGIN_MACRO \
|
||||
(_e)->prev->next = (_e)->next; \
|
||||
(_e)->next->prev = (_e)->prev; \
|
||||
(_e)->next = (_e); \
|
||||
(_e)->prev = (_e); \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
/*
|
||||
** Return non-zero if the given circular list "_l" is empty, zero if the
|
||||
** circular list is not empty
|
||||
*/
|
||||
#define PR_CLIST_IS_EMPTY(_l) \
|
||||
#define JS_CLIST_IS_EMPTY(_l) \
|
||||
((_l)->next == (_l))
|
||||
|
||||
/*
|
||||
** Initialize a circular list
|
||||
*/
|
||||
#define PR_INIT_CLIST(_l) \
|
||||
PR_BEGIN_MACRO \
|
||||
#define JS_INIT_CLIST(_l) \
|
||||
JS_BEGIN_MACRO \
|
||||
(_l)->next = (_l); \
|
||||
(_l)->prev = (_l); \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
#define PR_INIT_STATIC_CLIST(_l) \
|
||||
#define JS_INIT_STATIC_CLIST(_l) \
|
||||
{(_l), (_l)}
|
||||
|
||||
#endif /* prclist_h___ */
|
||||
#endif /* jsclist_h___ */
|
||||
@@ -23,19 +23,23 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "jstypes.h"
|
||||
#ifndef NSPR20
|
||||
#include "prarena.h"
|
||||
#include "jsarena.h"
|
||||
#else
|
||||
#include "plarena.h"
|
||||
/* Removed by JSIFY: #include "plarena.h"
|
||||
*/
|
||||
#include "jsarena.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "prlog.h"
|
||||
#include "prclist.h"
|
||||
#include "prprf.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#include "jsclist.h"
|
||||
#include "jsprf.h"
|
||||
#include "jsatom.h"
|
||||
#include "jscntxt.h"
|
||||
#include "jsconfig.h"
|
||||
#include "jsdbgapi.h"
|
||||
#include "jsexn.h"
|
||||
#include "jsgc.h"
|
||||
#include "jslock.h"
|
||||
#include "jsobj.h"
|
||||
@@ -43,14 +47,6 @@
|
||||
#include "jsscan.h"
|
||||
#include "jsscript.h"
|
||||
|
||||
JSInterpreterHooks *js_InterpreterHooks = NULL;
|
||||
|
||||
JS_FRIEND_API(void)
|
||||
js_SetInterpreterHooks(JSInterpreterHooks *hooks)
|
||||
{
|
||||
js_InterpreterHooks = hooks;
|
||||
}
|
||||
|
||||
JSContext *
|
||||
js_NewContext(JSRuntime *rt, size_t stacksize)
|
||||
{
|
||||
@@ -65,7 +61,7 @@ js_NewContext(JSRuntime *rt, size_t stacksize)
|
||||
#ifdef JS_THREADSAFE
|
||||
js_InitContextForLocking(cx);
|
||||
#endif
|
||||
if (rt->contextList.next == (PRCList *)&rt->contextList) {
|
||||
if (rt->contextList.next == (JSCList *)&rt->contextList) {
|
||||
/* First context on this runtime: initialize atoms and keywords. */
|
||||
if (!js_InitAtomState(cx, &rt->atomState) ||
|
||||
!js_InitScanner(cx)) {
|
||||
@@ -74,14 +70,14 @@ js_NewContext(JSRuntime *rt, size_t stacksize)
|
||||
}
|
||||
}
|
||||
/* Atomicly append cx to rt's context list. */
|
||||
JS_LOCK_RUNTIME_VOID(rt, PR_APPEND_LINK(&cx->links, &rt->contextList));
|
||||
JS_LOCK_RUNTIME_VOID(rt, JS_APPEND_LINK(&cx->links, &rt->contextList));
|
||||
|
||||
cx->version = JSVERSION_DEFAULT;
|
||||
cx->jsop_eq = JSOP_EQ;
|
||||
cx->jsop_ne = JSOP_NE;
|
||||
PR_InitArenaPool(&cx->stackPool, "stack", stacksize, sizeof(jsval));
|
||||
PR_InitArenaPool(&cx->codePool, "code", 1024, sizeof(jsbytecode));
|
||||
PR_InitArenaPool(&cx->tempPool, "temp", 1024, sizeof(jsdouble));
|
||||
JS_InitArenaPool(&cx->stackPool, "stack", stacksize, sizeof(jsval));
|
||||
JS_InitArenaPool(&cx->codePool, "code", 1024, sizeof(jsbytecode));
|
||||
JS_InitArenaPool(&cx->tempPool, "temp", 1024, sizeof(jsdouble));
|
||||
|
||||
#if JS_HAS_REGEXPS
|
||||
if (!js_InitRegExpStatics(cx, &cx->regExpStatics)) {
|
||||
@@ -102,15 +98,10 @@ js_DestroyContext(JSContext *cx)
|
||||
|
||||
/* Remove cx from context list first. */
|
||||
JS_LOCK_RUNTIME(rt);
|
||||
PR_REMOVE_LINK(&cx->links);
|
||||
rtempty = (rt->contextList.next == (PRCList *)&rt->contextList);
|
||||
JS_REMOVE_LINK(&cx->links);
|
||||
rtempty = (rt->contextList.next == (JSCList *)&rt->contextList);
|
||||
JS_UNLOCK_RUNTIME(rt);
|
||||
|
||||
if (js_InterpreterHooks && js_InterpreterHooks->destroyContext) {
|
||||
/* This is a stub, but in case it removes roots, call it now. */
|
||||
js_InterpreterHooks->destroyContext(cx);
|
||||
}
|
||||
|
||||
if (rtempty) {
|
||||
/* Unpin all pinned atoms before final GC. */
|
||||
js_UnpinPinnedAtoms(&rt->atomState);
|
||||
@@ -147,9 +138,9 @@ js_DestroyContext(JSContext *cx)
|
||||
}
|
||||
|
||||
/* Free the stuff hanging off of cx. */
|
||||
PR_FinishArenaPool(&cx->stackPool);
|
||||
PR_FinishArenaPool(&cx->codePool);
|
||||
PR_FinishArenaPool(&cx->tempPool);
|
||||
JS_FinishArenaPool(&cx->stackPool);
|
||||
JS_FinishArenaPool(&cx->codePool);
|
||||
JS_FinishArenaPool(&cx->tempPool);
|
||||
if (cx->lastMessage)
|
||||
free(cx->lastMessage);
|
||||
free(cx);
|
||||
@@ -172,7 +163,7 @@ js_ContextIterator(JSRuntime *rt, JSContext **iterp)
|
||||
}
|
||||
|
||||
void
|
||||
js_ReportErrorVA(JSContext *cx, const char *format, va_list ap)
|
||||
js_ReportErrorVA(JSContext *cx, uintN flags, const char *format, va_list ap)
|
||||
{
|
||||
JSStackFrame *fp;
|
||||
JSErrorReport report, *reportp;
|
||||
@@ -185,11 +176,13 @@ js_ReportErrorVA(JSContext *cx, const char *format, va_list ap)
|
||||
/* XXX should fetch line somehow */
|
||||
report.linebuf = NULL;
|
||||
report.tokenptr = NULL;
|
||||
report.flags = flags;
|
||||
reportp = &report;
|
||||
} else {
|
||||
/* XXXshaver still fill out report here for flags? */
|
||||
reportp = NULL;
|
||||
}
|
||||
last = PR_vsmprintf(format, ap);
|
||||
last = JS_vsmprintf(format, ap);
|
||||
if (!last)
|
||||
return;
|
||||
|
||||
@@ -197,6 +190,163 @@ js_ReportErrorVA(JSContext *cx, const char *format, va_list ap)
|
||||
free(last);
|
||||
}
|
||||
|
||||
/*
|
||||
* The arguments from ap need to be packaged up into an array and stored
|
||||
* into the report struct.
|
||||
*
|
||||
* The format string addressed by the error number may contain operands
|
||||
* identified by the format {N}, where N is a decimal digit. Each of these
|
||||
* is to be replaced by the Nth argument from the va_list. The complete
|
||||
* message is placed into reportp->ucmessage converted to a JSString.
|
||||
*
|
||||
* returns true/false if the expansion succeeds (can fail for memory errors)
|
||||
*/
|
||||
JSBool
|
||||
js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
|
||||
void *userRef, const uintN errorNumber,
|
||||
char **messagep, JSErrorReport *reportp, va_list ap)
|
||||
{
|
||||
const JSErrorFormatString *fmtData;
|
||||
int i;
|
||||
int argCount;
|
||||
|
||||
*messagep = NULL;
|
||||
if (callback) {
|
||||
fmtData = (*callback)(userRef, "Mountain View", errorNumber);
|
||||
if (fmtData != NULL) {
|
||||
argCount = fmtData->argCount;
|
||||
if (argCount > 0) {
|
||||
/*
|
||||
* Gather the arguments into a char * array, the
|
||||
* messageArgs field is supposed to be an array of
|
||||
* JSString's and we'll convert them later.
|
||||
*/
|
||||
reportp->messageArgs = malloc(sizeof(char *) * argCount);
|
||||
if (!reportp->messageArgs)
|
||||
return JS_FALSE;
|
||||
for (i = 0; i < argCount; i++)
|
||||
reportp->messageArgs[i] = (JSString *) va_arg(ap, char *);
|
||||
}
|
||||
/*
|
||||
* Parse the error format, substituting the argument X
|
||||
* for {X} in the format.
|
||||
*/
|
||||
if (argCount > 0) {
|
||||
if (fmtData->format) {
|
||||
const char *fmt, *arg;
|
||||
char *out;
|
||||
int expandedArgs = 0;
|
||||
int expandedLength
|
||||
= strlen(fmtData->format)
|
||||
- (3 * argCount); /* exclude the {n} */
|
||||
|
||||
for (i = 0; i < argCount; i++) {
|
||||
expandedLength
|
||||
+= strlen((char *)reportp->messageArgs[i]);
|
||||
}
|
||||
*messagep = out = malloc(expandedLength + 1);
|
||||
if (!out) {
|
||||
if (reportp->messageArgs) {
|
||||
free(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 = (char *)reportp->messageArgs[d];
|
||||
strcpy(out, arg);
|
||||
out += strlen(arg);
|
||||
fmt += 3;
|
||||
expandedArgs++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
*out++ = *fmt++;
|
||||
}
|
||||
JS_ASSERT(expandedArgs == argCount);
|
||||
*out = '\0';
|
||||
}
|
||||
/*
|
||||
* Now convert all the arguments to JSStrings.
|
||||
*/
|
||||
for (i = 0; i < argCount; i++) {
|
||||
reportp->messageArgs[i] =
|
||||
JS_NewStringCopyZ(cx, (char *)reportp->messageArgs[i]);
|
||||
}
|
||||
} else {
|
||||
*messagep = JS_strdup(cx, fmtData->format);
|
||||
}
|
||||
/*
|
||||
* And finally convert the message.
|
||||
*/
|
||||
reportp->ucmessage = JS_NewStringCopyZ(cx, *messagep);
|
||||
}
|
||||
}
|
||||
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 *)malloc(nbytes);
|
||||
JS_snprintf(*messagep, nbytes, defaultErrorMessage, errorNumber);
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
js_ReportErrorNumberVA(JSContext *cx, uintN flags, JSErrorCallback callback,
|
||||
void *userRef, const uintN errorNumber, va_list ap)
|
||||
{
|
||||
JSStackFrame *fp;
|
||||
JSErrorReport report;
|
||||
char *message;
|
||||
|
||||
report.messageArgs = NULL;
|
||||
report.ucmessage = NULL;
|
||||
message = NULL;
|
||||
|
||||
fp = cx->fp;
|
||||
if (fp && fp->script && fp->pc) {
|
||||
report.filename = fp->script->filename;
|
||||
report.lineno = js_PCToLineNumber(fp->script, fp->pc);
|
||||
} else {
|
||||
report.filename = NULL;
|
||||
report.lineno = 0;
|
||||
}
|
||||
|
||||
/* XXX should fetch line somehow */
|
||||
report.linebuf = NULL;
|
||||
report.tokenptr = NULL;
|
||||
report.flags = flags;
|
||||
report.errorNumber = errorNumber;
|
||||
|
||||
if (!js_ExpandErrorArguments(cx, callback, userRef, errorNumber,
|
||||
&message, &report, ap))
|
||||
return;
|
||||
|
||||
#if JS_HAS_ERROR_EXCEPTIONS
|
||||
/*
|
||||
* Check the error report, and set a JavaScript-catchable exception
|
||||
* if the error is defined to have an associated exception. If an
|
||||
* exception is thrown, then the JSREPORT_EXCEPTION flag will be set
|
||||
* on the error report, and exception-aware hosts should ignore it.
|
||||
*/
|
||||
js_ErrorToException(cx, &report, message);
|
||||
#endif
|
||||
|
||||
js_ReportErrorAgain(cx, message, &report);
|
||||
|
||||
if (message)
|
||||
free(message);
|
||||
if (report.messageArgs)
|
||||
free(report.messageArgs);
|
||||
}
|
||||
|
||||
JS_FRIEND_API(void)
|
||||
js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *reportp)
|
||||
{
|
||||
@@ -217,7 +367,7 @@ js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *reportp)
|
||||
void
|
||||
js_ReportIsNotDefined(JSContext *cx, const char *name)
|
||||
{
|
||||
JS_ReportError(cx, "%s is not defined", name);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NOT_DEFINED, name);
|
||||
}
|
||||
|
||||
#if defined DEBUG && defined XP_UNIX
|
||||
@@ -225,3 +375,26 @@ js_ReportIsNotDefined(JSContext *cx, const char *name)
|
||||
void js_traceon(JSContext *cx) { cx->tracefp = stderr; }
|
||||
void js_traceoff(JSContext *cx) { cx->tracefp = NULL; }
|
||||
#endif
|
||||
|
||||
|
||||
JSErrorFormatString js_ErrorFormatString[JSErr_Limit] = {
|
||||
#if JS_HAS_DFLT_MSG_STRINGS
|
||||
#define MSG_DEF(name, number, count, exception, format) \
|
||||
{ format, count } ,
|
||||
#else
|
||||
#define MSG_DEF(name, number, count, exception, format) \
|
||||
{ NULL, count } ,
|
||||
#endif
|
||||
#include "js.msg"
|
||||
#undef MSG_DEF
|
||||
};
|
||||
|
||||
const JSErrorFormatString *
|
||||
js_GetErrorMessage(void *userRef, const char *locale, const uintN errorNumber)
|
||||
{
|
||||
if ((errorNumber > 0) && (errorNumber < JSErr_Limit))
|
||||
return &js_ErrorFormatString[errorNumber];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,12 +22,14 @@
|
||||
* JS execution context.
|
||||
*/
|
||||
#ifndef NSPR20
|
||||
#include "prarena.h"
|
||||
#include "jsarena.h"
|
||||
#else
|
||||
#include "plarena.h"
|
||||
/* Removed by JSIFY: #include "plarena.h"
|
||||
*/
|
||||
#include "jsarena.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "prclist.h"
|
||||
#include "prlong.h"
|
||||
#include "jsclist.h"
|
||||
#include "jslong.h"
|
||||
#include "jsatom.h"
|
||||
#include "jsgc.h"
|
||||
#include "jsinterp.h"
|
||||
@@ -36,13 +38,13 @@
|
||||
#include "jspubtd.h"
|
||||
#include "jsregexp.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
struct JSRuntime {
|
||||
/* Garbage collector state, used by jsgc.c. */
|
||||
PRArenaPool gcArenaPool;
|
||||
PRArenaPool gcFlagsPool;
|
||||
PRHashTable *gcRootsHash;
|
||||
JSArenaPool gcArenaPool;
|
||||
JSArenaPool gcFlagsPool;
|
||||
JSHashTable *gcRootsHash;
|
||||
JSGCThing *gcFreeList;
|
||||
uint32 gcBytes;
|
||||
uint32 gcLastBytes;
|
||||
@@ -75,7 +77,7 @@ struct JSRuntime {
|
||||
JSString *emptyString;
|
||||
|
||||
/* List of active contexts sharing this runtime. */
|
||||
PRCList contextList;
|
||||
JSCList contextList;
|
||||
|
||||
/* These are used for debugging -- see jsprvtd.h and jsdbgapi.h. */
|
||||
JSTrapHandler interruptHandler;
|
||||
@@ -86,13 +88,19 @@ struct JSRuntime {
|
||||
void *destroyScriptHookData;
|
||||
JSTrapHandler debuggerHandler;
|
||||
void *debuggerHandlerData;
|
||||
JSSourceHandler sourceHandler;
|
||||
void *sourceHandlerData;
|
||||
JSInterpreterHook executeHook;
|
||||
void *executeHookData;
|
||||
JSInterpreterHook callHook;
|
||||
void *callHookData;
|
||||
|
||||
/* More debugging state, see jsdbgapi.c. */
|
||||
PRCList trapList;
|
||||
PRCList watchPointList;
|
||||
JSCList trapList;
|
||||
JSCList watchPointList;
|
||||
|
||||
/* Weak links to properties, indexed by quickened get/set opcodes. */
|
||||
/* XXX must come after PRCLists or MSVC alignment bug bites empty lists */
|
||||
/* XXX must come after JSCLists or MSVC alignment bug bites empty lists */
|
||||
JSPropertyCache propertyCache;
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
@@ -108,7 +116,7 @@ struct JSRuntime {
|
||||
};
|
||||
|
||||
struct JSContext {
|
||||
PRCList links;
|
||||
JSCList links;
|
||||
|
||||
/* Interpreter activation count. */
|
||||
uintN interpLevel;
|
||||
@@ -122,12 +130,12 @@ struct JSContext {
|
||||
JSRuntime *runtime;
|
||||
|
||||
/* Stack arena pool and frame pointer register. */
|
||||
PRArenaPool stackPool;
|
||||
JSArenaPool stackPool;
|
||||
JSStackFrame *fp;
|
||||
|
||||
/* Temporary arena pools used while compiling and decompiling. */
|
||||
PRArenaPool codePool;
|
||||
PRArenaPool tempPool;
|
||||
JSArenaPool codePool;
|
||||
JSArenaPool tempPool;
|
||||
|
||||
/* Top-level object and pointer to top stack frame's scope chain. */
|
||||
JSObject *globalObject;
|
||||
@@ -154,29 +162,20 @@ struct JSContext {
|
||||
/* Client opaque pointer */
|
||||
void *data;
|
||||
|
||||
/* Java environment and JS errors to throw as exceptions. */
|
||||
void *javaEnv;
|
||||
void *savedErrors;
|
||||
|
||||
/* GC and thread-safe state. */
|
||||
JSStackFrame *dormantFrameChain; /* dormant stack frame to scan */
|
||||
uint32 gcDisabled; /* XXX for pre-ECMAv2 switch */
|
||||
#ifdef JS_THREADSAFE
|
||||
prword thread;
|
||||
JSPackedBool gcActive;
|
||||
jsword thread;
|
||||
jsrefcount requestDepth;
|
||||
JSPackedBool gcActive;
|
||||
#endif
|
||||
JSStackFrame *dormantFrameChain; /* dormant frame chains */
|
||||
|
||||
/* Exception state (NB: throwing is packed with gcActive above). */
|
||||
JSPackedBool throwing; /* is there a pending exception? */
|
||||
jsval exception; /* most-recently-thrown exceptin */
|
||||
};
|
||||
|
||||
typedef struct JSInterpreterHooks {
|
||||
void (*destroyContext)(JSContext *cx);
|
||||
void (*destroyScript)(JSContext *cx, JSScript *script);
|
||||
void (*destroyFrame)(JSContext *cx, JSStackFrame *frame);
|
||||
} JSInterpreterHooks;
|
||||
|
||||
extern JSInterpreterHooks *js_InterpreterHooks;
|
||||
|
||||
extern JS_FRIEND_API(void)
|
||||
js_SetInterpreterHooks(JSInterpreterHooks *hooks);
|
||||
|
||||
extern JSContext *
|
||||
js_NewContext(JSRuntime *rt, size_t stacksize);
|
||||
|
||||
@@ -190,9 +189,29 @@ js_ContextIterator(JSRuntime *rt, JSContext **iterp);
|
||||
* Report an exception, which is currently realized as a printf-style format
|
||||
* string and its arguments.
|
||||
*/
|
||||
typedef enum JSErrNum {
|
||||
#define MSG_DEF(name, number, count, exception, format) \
|
||||
name = number,
|
||||
#include "js.msg"
|
||||
#undef MSG_DEF
|
||||
JSErr_Limit
|
||||
} JSErrNum;
|
||||
|
||||
extern const JSErrorFormatString *
|
||||
js_GetErrorMessage(void *userRef, const char *locale, const uintN errorNumber);
|
||||
|
||||
#ifdef va_start
|
||||
extern void
|
||||
js_ReportErrorVA(JSContext *cx, const char *format, va_list ap);
|
||||
js_ReportErrorVA(JSContext *cx, uintN flags, const char *format, va_list ap);
|
||||
extern void
|
||||
js_ReportErrorNumberVA(JSContext *cx, uintN flags, JSErrorCallback callback,
|
||||
void *userRef, const uintN errorNumber, va_list ap);
|
||||
|
||||
extern JSBool
|
||||
js_ExpandErrorArguments(JSContext *cx, JSErrorCallback callback,
|
||||
void *userRef, const uintN errorNumber,
|
||||
char **message, JSErrorReport *reportp,
|
||||
va_list ap);
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -204,6 +223,8 @@ js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *report);
|
||||
extern void
|
||||
js_ReportIsNotDefined(JSContext *cx, const char *name);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
extern JSErrorFormatString js_ErrorFormatString[JSErr_Limit];
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jscntxt_h___ */
|
||||
|
||||
@@ -5,55 +5,16 @@
|
||||
#define jscompat_h___
|
||||
/*
|
||||
* Compatibility glue for various NSPR versions. We must always define int8,
|
||||
* int16, prword, and so on to minimize differences with js/ref, no matter what
|
||||
* int16, jsword, and so on to minimize differences with js/ref, no matter what
|
||||
* the NSPR typedef names may be.
|
||||
*/
|
||||
#include "prtypes.h"
|
||||
#include "prlong.h"
|
||||
#ifdef NSPR20
|
||||
typedef PRIntn intN;
|
||||
typedef PRUintn uintN;
|
||||
/* Following are already available in compatibility mode of NSPR 2.0 */
|
||||
#if 0
|
||||
typedef PRInt64 int64;
|
||||
typedef PRInt32 int32;
|
||||
typedef PRInt16 int16;
|
||||
typedef PRInt8 int8;
|
||||
typedef uint64 uint64;
|
||||
typedef uint32 uint32;
|
||||
typedef uint16 uint16;
|
||||
typedef uint8 uint8;
|
||||
#endif
|
||||
typedef PRUword pruword;
|
||||
typedef PRWord prword;
|
||||
#else /* NSPR 1.0 */
|
||||
typedef int intN;
|
||||
typedef uint uintN;
|
||||
typedef uprword_t pruword;
|
||||
typedef prword_t prword;
|
||||
typedef int PRIntn;
|
||||
typedef unsigned int PRUintn;
|
||||
typedef int64 PRInt64;
|
||||
typedef int32 PRInt32;
|
||||
typedef int16 PRInt16;
|
||||
typedef int8 PRInt8;
|
||||
typedef uint64 PRUint64;
|
||||
typedef uint32 PRUint32;
|
||||
typedef uint16 PRUint16;
|
||||
typedef uint8 PRUint8;
|
||||
typedef double PRFloat64;
|
||||
typedef uprword_t PRUword;
|
||||
typedef prword_t PRWord;
|
||||
#define PR_EXTERN extern PR_PUBLIC_API
|
||||
#define PR_IMPLEMENT PR_PUBLIC_API
|
||||
#define PR_BEGIN_EXTERN_C NSPR_BEGIN_EXTERN_C
|
||||
#define PR_END_EXTERN_C NSPR_END_EXTERN_C
|
||||
#define PR_BEGIN_MACRO NSPR_BEGIN_MACRO
|
||||
#define PR_END_MACRO NSPR_END_MACRO
|
||||
#endif /* NSPR 1.0 */
|
||||
#ifndef NSPR20
|
||||
typedef double float64;
|
||||
#endif
|
||||
#include "jstypes.h"
|
||||
#include "jslong.h"
|
||||
|
||||
typedef JSIntn intN;
|
||||
typedef JSUintn uintN;
|
||||
typedef JSUword jsuword;
|
||||
typedef JSWord jsword;
|
||||
typedef float float32;
|
||||
#define allocPriv allocPool
|
||||
#endif /* jscompat_h___ */
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
#define JS_HAS_INSTANCEOF 0 /* has {p:1} instanceof Object */
|
||||
#define JS_HAS_ARGS_OBJECT 0 /* has minimal ECMA arguments object */
|
||||
#define JS_HAS_DEBUGGER_KEYWORD 0 /* has hook for debugger keyword */
|
||||
#define JS_HAS_ERROR_EXCEPTIONS 0 /* has error object hierarchy */
|
||||
|
||||
#elif JS_VERSION == 110
|
||||
|
||||
@@ -114,6 +115,7 @@
|
||||
#define JS_HAS_INSTANCEOF 0 /* has {p:1} instanceof Object */
|
||||
#define JS_HAS_ARGS_OBJECT 0 /* has minimal ECMA arguments object */
|
||||
#define JS_HAS_DEBUGGER_KEYWORD 0 /* has hook for debugger keyword */
|
||||
#define JS_HAS_ERROR_EXCEPTIONS 0 /* has error object hierarchy */
|
||||
|
||||
#elif JS_VERSION == 120
|
||||
|
||||
@@ -160,6 +162,7 @@
|
||||
#define JS_HAS_INSTANCEOF 0 /* has {p:1} instanceof Object */
|
||||
#define JS_HAS_ARGS_OBJECT 0 /* has minimal ECMA arguments object */
|
||||
#define JS_HAS_DEBUGGER_KEYWORD 0 /* has hook for debugger keyword */
|
||||
#define JS_HAS_ERROR_EXCEPTIONS 0 /* has error object hierarchy */
|
||||
|
||||
#elif JS_VERSION == 130
|
||||
|
||||
@@ -206,6 +209,7 @@
|
||||
#define JS_HAS_INSTANCEOF 0 /* has {p:1} instanceof Object */
|
||||
#define JS_HAS_ARGS_OBJECT 1 /* has minimal ECMA arguments object */
|
||||
#define JS_HAS_DEBUGGER_KEYWORD 1 /* has hook for debugger keyword */
|
||||
#define JS_HAS_ERROR_EXCEPTIONS 0 /* has error object hierarchy */
|
||||
|
||||
#elif JS_VERSION == 140
|
||||
|
||||
@@ -252,6 +256,9 @@
|
||||
#define JS_HAS_INSTANCEOF 1 /* has {p:1} instanceof Object */
|
||||
#define JS_HAS_ARGS_OBJECT 1 /* has minimal ECMA arguments object */
|
||||
#define JS_HAS_DEBUGGER_KEYWORD 1 /* has hook for debugger keyword */
|
||||
#define JS_HAS_ERROR_EXCEPTIONS 1 /* rt errors reflected as exceptions */
|
||||
|
||||
#define JS_HAS_DFLT_MSG_STRINGS 1 /* provides English error messages */
|
||||
|
||||
#else
|
||||
|
||||
|
||||
288
mozilla/js/src/jscpucfg.c
Normal file
288
mozilla/js/src/jscpucfg.c
Normal file
@@ -0,0 +1,288 @@
|
||||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Generate CPU-specific bit-size and similar #defines.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(sgi)
|
||||
#ifndef IRIX
|
||||
# error "IRIX is not defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__sun)
|
||||
#if defined(__svr4) || defined(__svr4__)
|
||||
#ifndef SOLARIS
|
||||
# error "SOLARIS is not defined"
|
||||
#endif
|
||||
#else
|
||||
#ifndef SUNOS4
|
||||
# error "SUNOS4 is not defined"
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__hpux)
|
||||
#ifndef HPUX
|
||||
# error "HPUX is not defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__osf__)
|
||||
#ifndef OSF1
|
||||
# error "OSF1 is not defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_IBMR2)
|
||||
#ifndef AIX
|
||||
# error "AIX is not defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(linux)
|
||||
#ifndef LINUX
|
||||
# error "LINUX is not defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(bsdi)
|
||||
#ifndef BSDI
|
||||
# error "BSDI is not defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(M_UNIX)
|
||||
#ifndef SCO
|
||||
# error "SCO is not defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(M_UNIX) && defined(_USLC_)
|
||||
#ifndef UNIXWARE
|
||||
# error "UNIXWARE is not defined"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __MWERKS__
|
||||
#define XP_MAC 1
|
||||
#endif
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
/* Generate cpucfg.h */
|
||||
#ifdef XP_MAC
|
||||
#include <Types.h>
|
||||
#define INT64 UnsignedWide
|
||||
#else
|
||||
#ifdef XP_PC
|
||||
#ifdef WIN32
|
||||
#define INT64 _int64
|
||||
#else
|
||||
#define INT64 long
|
||||
#endif
|
||||
#else
|
||||
#if defined(HPUX) || defined(SCO) || defined(UNIXWARE)
|
||||
#define INT64 long
|
||||
#else
|
||||
#define INT64 long long
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef void *prword;
|
||||
|
||||
struct align_short {
|
||||
char c;
|
||||
short a;
|
||||
};
|
||||
struct align_int {
|
||||
char c;
|
||||
int a;
|
||||
};
|
||||
struct align_long {
|
||||
char c;
|
||||
long a;
|
||||
};
|
||||
struct align_int64 {
|
||||
char c;
|
||||
INT64 a;
|
||||
};
|
||||
struct align_fakelonglong {
|
||||
char c;
|
||||
struct {
|
||||
long hi, lo;
|
||||
} a;
|
||||
};
|
||||
struct align_float {
|
||||
char c;
|
||||
float a;
|
||||
};
|
||||
struct align_double {
|
||||
char c;
|
||||
double a;
|
||||
};
|
||||
struct align_pointer {
|
||||
char c;
|
||||
void *a;
|
||||
};
|
||||
struct align_prword {
|
||||
char c;
|
||||
prword a;
|
||||
};
|
||||
|
||||
#define ALIGN_OF(type) \
|
||||
(((char*)&(((struct align_##type *)0)->a)) - ((char*)0))
|
||||
|
||||
int bpb;
|
||||
|
||||
static int Log2(int n)
|
||||
{
|
||||
int log2 = 0;
|
||||
|
||||
if (n & (n-1))
|
||||
log2++;
|
||||
if (n >> 16)
|
||||
log2 += 16, n >>= 16;
|
||||
if (n >> 8)
|
||||
log2 += 8, n >>= 8;
|
||||
if (n >> 4)
|
||||
log2 += 4, n >>= 4;
|
||||
if (n >> 2)
|
||||
log2 += 2, n >>= 2;
|
||||
if (n >> 1)
|
||||
log2++;
|
||||
return log2;
|
||||
}
|
||||
|
||||
/* We assume that int's are 32 bits */
|
||||
static void do64(void)
|
||||
{
|
||||
union {
|
||||
long i;
|
||||
char c[4];
|
||||
} u;
|
||||
|
||||
u.i = 0x01020304;
|
||||
if (u.c[0] == 0x01) {
|
||||
printf("#undef IS_LITTLE_ENDIAN\n");
|
||||
printf("#define IS_BIG_ENDIAN 1\n\n");
|
||||
} else {
|
||||
printf("#define IS_LITTLE_ENDIAN 1\n");
|
||||
printf("#undef IS_BIG_ENDIAN\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void do32(void)
|
||||
{
|
||||
union {
|
||||
long i;
|
||||
char c[4];
|
||||
} u;
|
||||
|
||||
u.i = 0x01020304;
|
||||
if (u.c[0] == 0x01) {
|
||||
printf("#undef IS_LITTLE_ENDIAN\n");
|
||||
printf("#define IS_BIG_ENDIAN 1\n\n");
|
||||
} else {
|
||||
printf("#define IS_LITTLE_ENDIAN 1\n");
|
||||
printf("#undef IS_BIG_ENDIAN\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Conceivably this could actually be used, but there is lots of code out
|
||||
* there with ands and shifts in it that assumes a byte is exactly 8 bits,
|
||||
* so forget about porting THIS code to all those non 8 bit byte machines.
|
||||
*/
|
||||
static void BitsPerByte(void)
|
||||
{
|
||||
bpb = 8;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
BitsPerByte();
|
||||
|
||||
printf("#ifndef js_cpucfg___\n");
|
||||
printf("#define js_cpucfg___\n\n");
|
||||
|
||||
printf("/* AUTOMATICALLY GENERATED - DO NOT EDIT */\n\n");
|
||||
|
||||
if (sizeof(long) == 8) {
|
||||
do64();
|
||||
} else {
|
||||
do32();
|
||||
}
|
||||
printf("#define JS_BYTES_PER_BYTE %dL\n", sizeof(char));
|
||||
printf("#define JS_BYTES_PER_SHORT %dL\n", sizeof(short));
|
||||
printf("#define JS_BYTES_PER_INT %dL\n", sizeof(int));
|
||||
printf("#define JS_BYTES_PER_INT64 %dL\n", 8);
|
||||
printf("#define JS_BYTES_PER_LONG %dL\n", sizeof(long));
|
||||
printf("#define JS_BYTES_PER_FLOAT %dL\n", sizeof(float));
|
||||
printf("#define JS_BYTES_PER_DOUBLE %dL\n", sizeof(double));
|
||||
printf("#define JS_BYTES_PER_WORD %dL\n", sizeof(prword));
|
||||
printf("#define JS_BYTES_PER_DWORD %dL\n", 8);
|
||||
printf("\n");
|
||||
|
||||
printf("#define JS_BITS_PER_BYTE %dL\n", bpb);
|
||||
printf("#define JS_BITS_PER_SHORT %dL\n", bpb * sizeof(short));
|
||||
printf("#define JS_BITS_PER_INT %dL\n", bpb * sizeof(int));
|
||||
printf("#define JS_BITS_PER_INT64 %dL\n", bpb * 8);
|
||||
printf("#define JS_BITS_PER_LONG %dL\n", bpb * sizeof(long));
|
||||
printf("#define JS_BITS_PER_FLOAT %dL\n", bpb * sizeof(float));
|
||||
printf("#define JS_BITS_PER_DOUBLE %dL\n", bpb * sizeof(double));
|
||||
printf("#define JS_BITS_PER_WORD %dL\n", bpb * sizeof(prword));
|
||||
printf("\n");
|
||||
|
||||
printf("#define JS_BITS_PER_BYTE_LOG2 %dL\n", Log2(bpb));
|
||||
printf("#define JS_BITS_PER_SHORT_LOG2 %dL\n", Log2(bpb * sizeof(short)));
|
||||
printf("#define JS_BITS_PER_INT_LOG2 %dL\n", Log2(bpb * sizeof(int)));
|
||||
printf("#define JS_BITS_PER_INT64_LOG2 %dL\n", 6);
|
||||
printf("#define JS_BITS_PER_LONG_LOG2 %dL\n", Log2(bpb * sizeof(long)));
|
||||
printf("#define JS_BITS_PER_FLOAT_LOG2 %dL\n", Log2(bpb * sizeof(float)));
|
||||
printf("#define JS_BITS_PER_DOUBLE_LOG2 %dL\n", Log2(bpb * sizeof(double)));
|
||||
printf("#define JS_BITS_PER_WORD_LOG2 %dL\n", Log2(bpb * sizeof(prword)));
|
||||
printf("\n");
|
||||
|
||||
printf("#define JS_ALIGN_OF_SHORT %dL\n", ALIGN_OF(short));
|
||||
printf("#define JS_ALIGN_OF_INT %dL\n", ALIGN_OF(int));
|
||||
printf("#define JS_ALIGN_OF_LONG %dL\n", ALIGN_OF(long));
|
||||
if (sizeof(INT64) < 8) {
|
||||
/* this machine doesn't actually support int64's */
|
||||
printf("#define JS_ALIGN_OF_INT64 %dL\n", ALIGN_OF(fakelonglong));
|
||||
} else {
|
||||
printf("#define JS_ALIGN_OF_INT64 %dL\n", ALIGN_OF(int64));
|
||||
}
|
||||
printf("#define JS_ALIGN_OF_FLOAT %dL\n", ALIGN_OF(float));
|
||||
printf("#define JS_ALIGN_OF_DOUBLE %dL\n", ALIGN_OF(double));
|
||||
printf("#define JS_ALIGN_OF_POINTER %dL\n", ALIGN_OF(pointer));
|
||||
printf("#define JS_ALIGN_OF_WORD %dL\n", ALIGN_OF(prword));
|
||||
printf("\n");
|
||||
|
||||
printf("#define JS_BYTES_PER_WORD_LOG2 %dL\n", Log2(sizeof(prword)));
|
||||
printf("#define JS_BYTES_PER_DWORD_LOG2 %dL\n", Log2(8));
|
||||
printf("#define JS_WORDS_PER_DWORD_LOG2 %dL\n", Log2(8/sizeof(prword)));
|
||||
printf("\n");
|
||||
|
||||
printf("#endif /* js_cpucfg___ */\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
702
mozilla/js/src/jscpucfg.h
Normal file
702
mozilla/js/src/jscpucfg.h
Normal file
@@ -0,0 +1,702 @@
|
||||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef js_cpucfg___
|
||||
#define js_cpucfg___
|
||||
|
||||
#include "jsosdep.h"
|
||||
|
||||
#ifdef XP_MAC
|
||||
#include "jsmacos.h"
|
||||
#undef IS_LITTLE_ENDIAN
|
||||
#define IS_BIG_ENDIAN 1
|
||||
|
||||
#define JS_BYTES_PER_BYTE 1L
|
||||
#define JS_BYTES_PER_SHORT 2L
|
||||
#define JS_BYTES_PER_INT 4L
|
||||
#define JS_BYTES_PER_INT64 8L
|
||||
#define JS_BYTES_PER_LONG 4L
|
||||
#define JS_BYTES_PER_FLOAT 4L
|
||||
#define JS_BYTES_PER_DOUBLE 8L
|
||||
#define JS_BYTES_PER_WORD 4L
|
||||
#define JS_BYTES_PER_DWORD 8L
|
||||
|
||||
#define JS_BITS_PER_BYTE 8L
|
||||
#define JS_BITS_PER_SHORT 16L
|
||||
#define JS_BITS_PER_INT 32L
|
||||
#define JS_BITS_PER_INT64 64L
|
||||
#define JS_BITS_PER_LONG 32L
|
||||
#define JS_BITS_PER_FLOAT 32L
|
||||
#define JS_BITS_PER_DOUBLE 64L
|
||||
#define JS_BITS_PER_WORD 32L
|
||||
|
||||
#define JS_BITS_PER_BYTE_LOG2 3L
|
||||
#define JS_BITS_PER_SHORT_LOG2 4L
|
||||
#define JS_BITS_PER_INT_LOG2 5L
|
||||
#define JS_BITS_PER_INT64_LOG2 6L
|
||||
#define JS_BITS_PER_LONG_LOG2 5L
|
||||
#define JS_BITS_PER_FLOAT_LOG2 5L
|
||||
#define JS_BITS_PER_DOUBLE_LOG2 6L
|
||||
#define JS_BITS_PER_WORD_LOG2 5L
|
||||
|
||||
#define JS_ALIGN_OF_SHORT 2L
|
||||
#define JS_ALIGN_OF_INT 4L
|
||||
#define JS_ALIGN_OF_LONG 4L
|
||||
#define JS_ALIGN_OF_INT64 2L
|
||||
#define JS_ALIGN_OF_FLOAT 4L
|
||||
#define JS_ALIGN_OF_DOUBLE 4L
|
||||
#define JS_ALIGN_OF_POINTER 4L
|
||||
#define JS_ALIGN_OF_WORD 4L
|
||||
|
||||
#define JS_BYTES_PER_WORD_LOG2 2L
|
||||
#define JS_BYTES_PER_DWORD_LOG2 3L
|
||||
#define PR_WORDS_PER_DWORD_LOG2 1L
|
||||
#endif /* XP_MAC */
|
||||
|
||||
#ifdef _WIN32
|
||||
#define IS_LITTLE_ENDIAN 1
|
||||
#undef IS_BIG_ENDIAN
|
||||
|
||||
#define JS_BYTES_PER_BYTE 1L
|
||||
#define JS_BYTES_PER_SHORT 2L
|
||||
#define JS_BYTES_PER_INT 4L
|
||||
#define JS_BYTES_PER_INT64 8L
|
||||
#define JS_BYTES_PER_LONG 4L
|
||||
#define JS_BYTES_PER_FLOAT 4L
|
||||
#define JS_BYTES_PER_DOUBLE 8L
|
||||
#define JS_BYTES_PER_WORD 4L
|
||||
#define JS_BYTES_PER_DWORD 8L
|
||||
|
||||
#define JS_BITS_PER_BYTE 8L
|
||||
#define JS_BITS_PER_SHORT 16L
|
||||
#define JS_BITS_PER_INT 32L
|
||||
#define JS_BITS_PER_INT64 64L
|
||||
#define JS_BITS_PER_LONG 32L
|
||||
#define JS_BITS_PER_FLOAT 32L
|
||||
#define JS_BITS_PER_DOUBLE 64L
|
||||
#define JS_BITS_PER_WORD 32L
|
||||
|
||||
#define JS_BITS_PER_BYTE_LOG2 3L
|
||||
#define JS_BITS_PER_SHORT_LOG2 4L
|
||||
#define JS_BITS_PER_INT_LOG2 5L
|
||||
#define JS_BITS_PER_INT64_LOG2 6L
|
||||
#define JS_BITS_PER_LONG_LOG2 5L
|
||||
#define JS_BITS_PER_FLOAT_LOG2 5L
|
||||
#define JS_BITS_PER_DOUBLE_LOG2 6L
|
||||
#define JS_BITS_PER_WORD_LOG2 5L
|
||||
|
||||
#define JS_ALIGN_OF_SHORT 2L
|
||||
#define JS_ALIGN_OF_INT 4L
|
||||
#define JS_ALIGN_OF_LONG 4L
|
||||
#define JS_ALIGN_OF_INT64 8L
|
||||
#define JS_ALIGN_OF_FLOAT 4L
|
||||
#define JS_ALIGN_OF_DOUBLE 4L
|
||||
#define JS_ALIGN_OF_POINTER 4L
|
||||
#define JS_ALIGN_OF_WORD 4L
|
||||
|
||||
#define JS_BYTES_PER_WORD_LOG2 2L
|
||||
#define JS_BYTES_PER_DWORD_LOG2 3L
|
||||
#define PR_WORDS_PER_DWORD_LOG2 1L
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#if defined(_WINDOWS) && !defined(_WIN32) /* WIN16 */
|
||||
#define IS_LITTLE_ENDIAN 1
|
||||
#undef IS_BIG_ENDIAN
|
||||
|
||||
#define JS_BYTES_PER_BYTE 1L
|
||||
#define JS_BYTES_PER_SHORT 2L
|
||||
#define JS_BYTES_PER_INT 2L
|
||||
#define JS_BYTES_PER_INT64 8L
|
||||
#define JS_BYTES_PER_LONG 4L
|
||||
#define JS_BYTES_PER_FLOAT 4L
|
||||
#define JS_BYTES_PER_DOUBLE 8L
|
||||
#define JS_BYTES_PER_WORD 4L
|
||||
#define JS_BYTES_PER_DWORD 8L
|
||||
|
||||
#define JS_BITS_PER_BYTE 8L
|
||||
#define JS_BITS_PER_SHORT 16L
|
||||
#define JS_BITS_PER_INT 16L
|
||||
#define JS_BITS_PER_INT64 64L
|
||||
#define JS_BITS_PER_LONG 32L
|
||||
#define JS_BITS_PER_FLOAT 32L
|
||||
#define JS_BITS_PER_DOUBLE 64L
|
||||
#define JS_BITS_PER_WORD 32L
|
||||
|
||||
#define JS_BITS_PER_BYTE_LOG2 3L
|
||||
#define JS_BITS_PER_SHORT_LOG2 4L
|
||||
#define JS_BITS_PER_INT_LOG2 4L
|
||||
#define JS_BITS_PER_INT64_LOG2 6L
|
||||
#define JS_BITS_PER_LONG_LOG2 5L
|
||||
#define JS_BITS_PER_FLOAT_LOG2 5L
|
||||
#define JS_BITS_PER_DOUBLE_LOG2 6L
|
||||
#define JS_BITS_PER_WORD_LOG2 5L
|
||||
|
||||
#define JS_ALIGN_OF_SHORT 2L
|
||||
#define JS_ALIGN_OF_INT 2L
|
||||
#define JS_ALIGN_OF_LONG 2L
|
||||
#define JS_ALIGN_OF_INT64 2L
|
||||
#define JS_ALIGN_OF_FLOAT 2L
|
||||
#define JS_ALIGN_OF_DOUBLE 2L
|
||||
#define JS_ALIGN_OF_POINTER 2L
|
||||
#define JS_ALIGN_OF_WORD 2L
|
||||
|
||||
#define JS_BYTES_PER_WORD_LOG2 2L
|
||||
#define JS_BYTES_PER_DWORD_LOG2 3L
|
||||
#define PR_WORDS_PER_DWORD_LOG2 1L
|
||||
#endif /* defined(_WINDOWS) && !defined(_WIN32) */
|
||||
|
||||
#ifdef XP_UNIX
|
||||
|
||||
#ifdef AIXV3
|
||||
#undef IS_LITTLE_ENDIAN
|
||||
#define IS_BIG_ENDIAN 1
|
||||
|
||||
#define JS_BYTES_PER_BYTE 1L
|
||||
#define JS_BYTES_PER_SHORT 2L
|
||||
#define JS_BYTES_PER_INT 4L
|
||||
#define JS_BYTES_PER_INT64 8L
|
||||
#define JS_BYTES_PER_LONG 4L
|
||||
#define JS_BYTES_PER_FLOAT 4L
|
||||
#define JS_BYTES_PER_DOUBLE 8L
|
||||
#define JS_BYTES_PER_WORD 4L
|
||||
#define JS_BYTES_PER_DWORD 8L
|
||||
|
||||
#define JS_BITS_PER_BYTE 8L
|
||||
#define JS_BITS_PER_SHORT 16L
|
||||
#define JS_BITS_PER_INT 32L
|
||||
#define JS_BITS_PER_INT64 64L
|
||||
#define JS_BITS_PER_LONG 32L
|
||||
#define JS_BITS_PER_FLOAT 32L
|
||||
#define JS_BITS_PER_DOUBLE 64L
|
||||
#define JS_BITS_PER_WORD 32L
|
||||
|
||||
#define JS_BITS_PER_BYTE_LOG2 3L
|
||||
#define JS_BITS_PER_SHORT_LOG2 4L
|
||||
#define JS_BITS_PER_INT_LOG2 5L
|
||||
#define JS_BITS_PER_INT64_LOG2 6L
|
||||
#define JS_BITS_PER_LONG_LOG2 5L
|
||||
#define JS_BITS_PER_FLOAT_LOG2 5L
|
||||
#define JS_BITS_PER_DOUBLE_LOG2 6L
|
||||
#define JS_BITS_PER_WORD_LOG2 5L
|
||||
|
||||
#define JS_ALIGN_OF_SHORT 2L
|
||||
#define JS_ALIGN_OF_INT 4L
|
||||
#define JS_ALIGN_OF_LONG 4L
|
||||
#define JS_ALIGN_OF_INT64 8L
|
||||
#define JS_ALIGN_OF_FLOAT 4L
|
||||
#define JS_ALIGN_OF_DOUBLE 4L
|
||||
#define JS_ALIGN_OF_POINTER 4L
|
||||
#define JS_ALIGN_OF_WORD 4L
|
||||
|
||||
#define JS_BYTES_PER_WORD_LOG2 2L
|
||||
#define JS_BYTES_PER_DWORD_LOG2 3L
|
||||
#define PR_WORDS_PER_DWORD_LOG2 1L
|
||||
|
||||
|
||||
#elif defined(BSDI)
|
||||
#define IS_LITTLE_ENDIAN 1
|
||||
#undef IS_BIG_ENDIAN
|
||||
|
||||
#define JS_BYTES_PER_BYTE 1L
|
||||
#define JS_BYTES_PER_SHORT 2L
|
||||
#define JS_BYTES_PER_INT 4L
|
||||
#define JS_BYTES_PER_INT64 8L
|
||||
#define JS_BYTES_PER_LONG 4L
|
||||
#define JS_BYTES_PER_FLOAT 4L
|
||||
#define JS_BYTES_PER_DOUBLE 8L
|
||||
#define JS_BYTES_PER_WORD 4L
|
||||
#define JS_BYTES_PER_DWORD 8L
|
||||
|
||||
#define JS_BITS_PER_BYTE 8L
|
||||
#define JS_BITS_PER_SHORT 16L
|
||||
#define JS_BITS_PER_INT 32L
|
||||
#define JS_BITS_PER_INT64 64L
|
||||
#define JS_BITS_PER_LONG 32L
|
||||
#define JS_BITS_PER_FLOAT 32L
|
||||
#define JS_BITS_PER_DOUBLE 64L
|
||||
#define JS_BITS_PER_WORD 32L
|
||||
|
||||
#define JS_BITS_PER_BYTE_LOG2 3L
|
||||
#define JS_BITS_PER_SHORT_LOG2 4L
|
||||
#define JS_BITS_PER_INT_LOG2 5L
|
||||
#define JS_BITS_PER_INT64_LOG2 6L
|
||||
#define JS_BITS_PER_LONG_LOG2 5L
|
||||
#define JS_BITS_PER_FLOAT_LOG2 5L
|
||||
#define JS_BITS_PER_DOUBLE_LOG2 6L
|
||||
#define JS_BITS_PER_WORD_LOG2 5L
|
||||
|
||||
#define JS_ALIGN_OF_SHORT 2L
|
||||
#define JS_ALIGN_OF_INT 4L
|
||||
#define JS_ALIGN_OF_LONG 4L
|
||||
#define JS_ALIGN_OF_INT64 4L
|
||||
#define JS_ALIGN_OF_FLOAT 4L
|
||||
#define JS_ALIGN_OF_DOUBLE 4L
|
||||
#define JS_ALIGN_OF_POINTER 4L
|
||||
#define JS_ALIGN_OF_WORD 4L
|
||||
|
||||
#define JS_BYTES_PER_WORD_LOG2 2L
|
||||
#define JS_BYTES_PER_DWORD_LOG2 3L
|
||||
#define PR_WORDS_PER_DWORD_LOG2 1L
|
||||
|
||||
|
||||
#elif defined(HPUX)
|
||||
#undef IS_LITTLE_ENDIAN
|
||||
#define IS_BIG_ENDIAN 1
|
||||
|
||||
#define JS_BYTES_PER_BYTE 1L
|
||||
#define JS_BYTES_PER_SHORT 2L
|
||||
#define JS_BYTES_PER_INT 4L
|
||||
#define JS_BYTES_PER_INT64 8L
|
||||
#define JS_BYTES_PER_LONG 4L
|
||||
#define JS_BYTES_PER_FLOAT 4L
|
||||
#define JS_BYTES_PER_DOUBLE 8L
|
||||
#define JS_BYTES_PER_WORD 4L
|
||||
#define JS_BYTES_PER_DWORD 8L
|
||||
|
||||
#define JS_BITS_PER_BYTE 8L
|
||||
#define JS_BITS_PER_SHORT 16L
|
||||
#define JS_BITS_PER_INT 32L
|
||||
#define JS_BITS_PER_INT64 64L
|
||||
#define JS_BITS_PER_LONG 32L
|
||||
#define JS_BITS_PER_FLOAT 32L
|
||||
#define JS_BITS_PER_DOUBLE 64L
|
||||
#define JS_BITS_PER_WORD 32L
|
||||
|
||||
#define JS_BITS_PER_BYTE_LOG2 3L
|
||||
#define JS_BITS_PER_SHORT_LOG2 4L
|
||||
#define JS_BITS_PER_INT_LOG2 5L
|
||||
#define JS_BITS_PER_INT64_LOG2 6L
|
||||
#define JS_BITS_PER_LONG_LOG2 5L
|
||||
#define JS_BITS_PER_FLOAT_LOG2 5L
|
||||
#define JS_BITS_PER_DOUBLE_LOG2 6L
|
||||
#define JS_BITS_PER_WORD_LOG2 5L
|
||||
|
||||
#define JS_ALIGN_OF_SHORT 2L
|
||||
#define JS_ALIGN_OF_INT 4L
|
||||
#define JS_ALIGN_OF_LONG 4L
|
||||
#define JS_ALIGN_OF_INT64 4L
|
||||
#define JS_ALIGN_OF_FLOAT 4L
|
||||
#define JS_ALIGN_OF_DOUBLE 8L
|
||||
#define JS_ALIGN_OF_POINTER 4L
|
||||
#define JS_ALIGN_OF_WORD 4L
|
||||
|
||||
#define JS_BYTES_PER_WORD_LOG2 2L
|
||||
#define JS_BYTES_PER_DWORD_LOG2 3L
|
||||
#define PR_WORDS_PER_DWORD_LOG2 1L
|
||||
|
||||
|
||||
#elif defined(IRIX)
|
||||
#undef IS_LITTLE_ENDIAN
|
||||
#define IS_BIG_ENDIAN 1
|
||||
|
||||
#define JS_BYTES_PER_BYTE 1L
|
||||
#define JS_BYTES_PER_SHORT 2L
|
||||
#define JS_BYTES_PER_INT 4L
|
||||
#define JS_BYTES_PER_INT64 8L
|
||||
#define JS_BYTES_PER_LONG 4L
|
||||
#define JS_BYTES_PER_FLOAT 4L
|
||||
#define JS_BYTES_PER_DOUBLE 8L
|
||||
#define JS_BYTES_PER_WORD 4L
|
||||
#define JS_BYTES_PER_DWORD 8L
|
||||
|
||||
#define JS_BITS_PER_BYTE 8L
|
||||
#define JS_BITS_PER_SHORT 16L
|
||||
#define JS_BITS_PER_INT 32L
|
||||
#define JS_BITS_PER_INT64 64L
|
||||
#define JS_BITS_PER_LONG 32L
|
||||
#define JS_BITS_PER_FLOAT 32L
|
||||
#define JS_BITS_PER_DOUBLE 64L
|
||||
#define JS_BITS_PER_WORD 32L
|
||||
|
||||
#define JS_BITS_PER_BYTE_LOG2 3L
|
||||
#define JS_BITS_PER_SHORT_LOG2 4L
|
||||
#define JS_BITS_PER_INT_LOG2 5L
|
||||
#define JS_BITS_PER_INT64_LOG2 6L
|
||||
#define JS_BITS_PER_LONG_LOG2 5L
|
||||
#define JS_BITS_PER_FLOAT_LOG2 5L
|
||||
#define JS_BITS_PER_DOUBLE_LOG2 6L
|
||||
#define JS_BITS_PER_WORD_LOG2 5L
|
||||
|
||||
#define JS_ALIGN_OF_SHORT 2L
|
||||
#define JS_ALIGN_OF_INT 4L
|
||||
#define JS_ALIGN_OF_LONG 4L
|
||||
#define JS_ALIGN_OF_INT64 8L
|
||||
#define JS_ALIGN_OF_FLOAT 4L
|
||||
#define JS_ALIGN_OF_DOUBLE 8L
|
||||
#define JS_ALIGN_OF_POINTER 4L
|
||||
#define JS_ALIGN_OF_WORD 4L
|
||||
|
||||
#define JS_BYTES_PER_WORD_LOG2 2L
|
||||
#define JS_BYTES_PER_DWORD_LOG2 3L
|
||||
#define PR_WORDS_PER_DWORD_LOG2 1L
|
||||
|
||||
|
||||
#elif defined(LINUX)
|
||||
|
||||
#ifdef __powerpc__
|
||||
#undef IS_LITTLE_ENDIAN
|
||||
#define IS_BIG_ENDIAN 1
|
||||
#elif __i386__
|
||||
#define IS_LITTLE_ENDIAN 1
|
||||
#undef IS_BIG_ENDIAN
|
||||
#else
|
||||
#error "linux cpu architecture not supported by jscpucfg.h"
|
||||
#endif
|
||||
|
||||
#define JS_BYTES_PER_BYTE 1L
|
||||
#define JS_BYTES_PER_SHORT 2L
|
||||
#define JS_BYTES_PER_INT 4L
|
||||
#define JS_BYTES_PER_INT64 8L
|
||||
#define JS_BYTES_PER_LONG 4L
|
||||
#define JS_BYTES_PER_FLOAT 4L
|
||||
#define JS_BYTES_PER_DOUBLE 8L
|
||||
#define JS_BYTES_PER_WORD 4L
|
||||
#define JS_BYTES_PER_DWORD 8L
|
||||
|
||||
#define JS_BITS_PER_BYTE 8L
|
||||
#define JS_BITS_PER_SHORT 16L
|
||||
#define JS_BITS_PER_INT 32L
|
||||
#define JS_BITS_PER_INT64 64L
|
||||
#define JS_BITS_PER_LONG 32L
|
||||
#define JS_BITS_PER_FLOAT 32L
|
||||
#define JS_BITS_PER_DOUBLE 64L
|
||||
#define JS_BITS_PER_WORD 32L
|
||||
|
||||
#define JS_BITS_PER_BYTE_LOG2 3L
|
||||
#define JS_BITS_PER_SHORT_LOG2 4L
|
||||
#define JS_BITS_PER_INT_LOG2 5L
|
||||
#define JS_BITS_PER_INT64_LOG2 6L
|
||||
#define JS_BITS_PER_LONG_LOG2 5L
|
||||
#define JS_BITS_PER_FLOAT_LOG2 5L
|
||||
#define JS_BITS_PER_DOUBLE_LOG2 6L
|
||||
#define JS_BITS_PER_WORD_LOG2 5L
|
||||
|
||||
#define JS_ALIGN_OF_SHORT 2L
|
||||
#define JS_ALIGN_OF_INT 4L
|
||||
#define JS_ALIGN_OF_LONG 4L
|
||||
#define JS_ALIGN_OF_INT64 4L
|
||||
#define JS_ALIGN_OF_FLOAT 4L
|
||||
#define JS_ALIGN_OF_DOUBLE 4L
|
||||
#define JS_ALIGN_OF_POINTER 4L
|
||||
#define JS_ALIGN_OF_WORD 4L
|
||||
|
||||
#define JS_BYTES_PER_WORD_LOG2 2L
|
||||
#define JS_BYTES_PER_DWORD_LOG2 3L
|
||||
#define PR_WORDS_PER_DWORD_LOG2 1L
|
||||
|
||||
|
||||
#elif defined(OSF1)
|
||||
#define IS_LITTLE_ENDIAN 1
|
||||
#undef IS_BIG_ENDIAN
|
||||
|
||||
#define JS_BYTES_PER_BYTE 1L
|
||||
#define JS_BYTES_PER_SHORT 2L
|
||||
#define JS_BYTES_PER_INT 4L
|
||||
#define JS_BYTES_PER_INT64 8L
|
||||
#define JS_BYTES_PER_LONG 8L
|
||||
#define JS_BYTES_PER_FLOAT 4L
|
||||
#define JS_BYTES_PER_DOUBLE 8L
|
||||
#define JS_BYTES_PER_WORD 8L
|
||||
#define JS_BYTES_PER_DWORD 8L
|
||||
|
||||
#define JS_BITS_PER_BYTE 8L
|
||||
#define JS_BITS_PER_SHORT 16L
|
||||
#define JS_BITS_PER_INT 32L
|
||||
#define JS_BITS_PER_INT64 64L
|
||||
#define JS_BITS_PER_LONG 64L
|
||||
#define JS_BITS_PER_FLOAT 32L
|
||||
#define JS_BITS_PER_DOUBLE 64L
|
||||
#define JS_BITS_PER_WORD 64L
|
||||
|
||||
#define JS_BITS_PER_BYTE_LOG2 3L
|
||||
#define JS_BITS_PER_SHORT_LOG2 4L
|
||||
#define JS_BITS_PER_INT_LOG2 5L
|
||||
#define JS_BITS_PER_INT64_LOG2 6L
|
||||
#define JS_BITS_PER_LONG_LOG2 6L
|
||||
#define JS_BITS_PER_FLOAT_LOG2 5L
|
||||
#define JS_BITS_PER_DOUBLE_LOG2 6L
|
||||
#define JS_BITS_PER_WORD_LOG2 6L
|
||||
|
||||
#define JS_ALIGN_OF_SHORT 2L
|
||||
#define JS_ALIGN_OF_INT 4L
|
||||
#define JS_ALIGN_OF_LONG 8L
|
||||
#define JS_ALIGN_OF_INT64 8L
|
||||
#define JS_ALIGN_OF_FLOAT 4L
|
||||
#define JS_ALIGN_OF_DOUBLE 8L
|
||||
#define JS_ALIGN_OF_POINTER 8L
|
||||
#define JS_ALIGN_OF_WORD 8L
|
||||
|
||||
#define JS_BYTES_PER_WORD_LOG2 3L
|
||||
#define JS_BYTES_PER_DWORD_LOG2 3L
|
||||
#define PR_WORDS_PER_DWORD_LOG2 0L
|
||||
|
||||
|
||||
#elif defined(SOLARIS)
|
||||
|
||||
#ifdef i386
|
||||
/* PC-based */
|
||||
#undef IS_BIG_ENDIAN
|
||||
#define IS_LITTLE_ENDIAN 1
|
||||
#else
|
||||
/* Sparc-based */
|
||||
#undef IS_LITTLE_ENDIAN
|
||||
#define IS_BIG_ENDIAN 1
|
||||
#endif
|
||||
|
||||
#define JS_BYTES_PER_BYTE 1L
|
||||
#define JS_BYTES_PER_SHORT 2L
|
||||
#define JS_BYTES_PER_INT 4L
|
||||
#define JS_BYTES_PER_INT64 8L
|
||||
#define JS_BYTES_PER_LONG 4L
|
||||
#define JS_BYTES_PER_FLOAT 4L
|
||||
#define JS_BYTES_PER_DOUBLE 8L
|
||||
#define JS_BYTES_PER_WORD 4L
|
||||
#define JS_BYTES_PER_DWORD 8L
|
||||
|
||||
#define JS_BITS_PER_BYTE 8L
|
||||
#define JS_BITS_PER_SHORT 16L
|
||||
#define JS_BITS_PER_INT 32L
|
||||
#define JS_BITS_PER_INT64 64L
|
||||
#define JS_BITS_PER_LONG 32L
|
||||
#define JS_BITS_PER_FLOAT 32L
|
||||
#define JS_BITS_PER_DOUBLE 64L
|
||||
#define JS_BITS_PER_WORD 32L
|
||||
|
||||
#define JS_BITS_PER_BYTE_LOG2 3L
|
||||
#define JS_BITS_PER_SHORT_LOG2 4L
|
||||
#define JS_BITS_PER_INT_LOG2 5L
|
||||
#define JS_BITS_PER_INT64_LOG2 6L
|
||||
#define JS_BITS_PER_LONG_LOG2 5L
|
||||
#define JS_BITS_PER_FLOAT_LOG2 5L
|
||||
#define JS_BITS_PER_DOUBLE_LOG2 6L
|
||||
#define JS_BITS_PER_WORD_LOG2 5L
|
||||
|
||||
#define JS_ALIGN_OF_SHORT 2L
|
||||
#define JS_ALIGN_OF_INT 4L
|
||||
#define JS_ALIGN_OF_LONG 4L
|
||||
#define JS_ALIGN_OF_INT64 8L
|
||||
#define JS_ALIGN_OF_FLOAT 4L
|
||||
#define JS_ALIGN_OF_DOUBLE 8L
|
||||
#define JS_ALIGN_OF_POINTER 4L
|
||||
#define JS_ALIGN_OF_WORD 4L
|
||||
|
||||
#ifdef i386
|
||||
#undef JS_ALIGN_OF_INT64
|
||||
#undef JS_ALIGN_OF_DOUBLE
|
||||
#define JS_ALIGN_OF_INT64 4L
|
||||
#define JS_ALIGN_OF_DOUBLE 4L
|
||||
#endif
|
||||
|
||||
#define JS_BYTES_PER_WORD_LOG2 2L
|
||||
#define JS_BYTES_PER_DWORD_LOG2 3L
|
||||
#define PR_WORDS_PER_DWORD_LOG2 1L
|
||||
|
||||
|
||||
#elif defined(SUNOS4)
|
||||
#undef IS_LITTLE_ENDIAN
|
||||
#define IS_BIG_ENDIAN 1
|
||||
|
||||
#define JS_BYTES_PER_BYTE 1L
|
||||
#define JS_BYTES_PER_SHORT 2L
|
||||
#define JS_BYTES_PER_INT 4L
|
||||
#define JS_BYTES_PER_INT64 8L
|
||||
#define JS_BYTES_PER_LONG 4L
|
||||
#define JS_BYTES_PER_FLOAT 4L
|
||||
#define JS_BYTES_PER_DOUBLE 8L
|
||||
#define JS_BYTES_PER_WORD 4L
|
||||
#define JS_BYTES_PER_DWORD 8L
|
||||
|
||||
#define JS_BITS_PER_BYTE 8L
|
||||
#define JS_BITS_PER_SHORT 16L
|
||||
#define JS_BITS_PER_INT 32L
|
||||
#define JS_BITS_PER_INT64 64L
|
||||
#define JS_BITS_PER_LONG 32L
|
||||
#define JS_BITS_PER_FLOAT 32L
|
||||
#define JS_BITS_PER_DOUBLE 64L
|
||||
#define JS_BITS_PER_WORD 32L
|
||||
|
||||
#define JS_BITS_PER_BYTE_LOG2 3L
|
||||
#define JS_BITS_PER_SHORT_LOG2 4L
|
||||
#define JS_BITS_PER_INT_LOG2 5L
|
||||
#define JS_BITS_PER_INT64_LOG2 6L
|
||||
#define JS_BITS_PER_LONG_LOG2 5L
|
||||
#define JS_BITS_PER_FLOAT_LOG2 5L
|
||||
#define JS_BITS_PER_DOUBLE_LOG2 6L
|
||||
#define JS_BITS_PER_WORD_LOG2 5L
|
||||
|
||||
#define JS_ALIGN_OF_SHORT 2L
|
||||
#define JS_ALIGN_OF_INT 4L
|
||||
#define JS_ALIGN_OF_LONG 4L
|
||||
#define JS_ALIGN_OF_INT64 8L
|
||||
#define JS_ALIGN_OF_FLOAT 4L
|
||||
#define JS_ALIGN_OF_DOUBLE 8L
|
||||
#define JS_ALIGN_OF_POINTER 4L
|
||||
#define JS_ALIGN_OF_WORD 4L
|
||||
|
||||
#define JS_BYTES_PER_WORD_LOG2 2L
|
||||
#define JS_BYTES_PER_DWORD_LOG2 3L
|
||||
#define PR_WORDS_PER_DWORD_LOG2 1L
|
||||
|
||||
|
||||
#elif defined(SNI)
|
||||
#undef IS_LITTLE_ENDIAN
|
||||
#define IS_BIG_ENDIAN 1
|
||||
|
||||
#define JS_BYTES_PER_BYTE 1L
|
||||
#define JS_BYTES_PER_SHORT 2L
|
||||
#define JS_BYTES_PER_INT 4L
|
||||
#define JS_BYTES_PER_INT64 8L
|
||||
#define JS_BYTES_PER_LONG 4L
|
||||
#define JS_BYTES_PER_FLOAT 4L
|
||||
#define JS_BYTES_PER_DOUBLE 8L
|
||||
#define JS_BYTES_PER_WORD 4L
|
||||
#define JS_BYTES_PER_DWORD 8L
|
||||
|
||||
#define JS_BITS_PER_BYTE 8L
|
||||
#define JS_BITS_PER_SHORT 16L
|
||||
#define JS_BITS_PER_INT 32L
|
||||
#define JS_BITS_PER_INT64 64L
|
||||
#define JS_BITS_PER_LONG 32L
|
||||
#define JS_BITS_PER_FLOAT 32L
|
||||
#define JS_BITS_PER_DOUBLE 64L
|
||||
#define JS_BITS_PER_WORD 32L
|
||||
|
||||
#define JS_BITS_PER_BYTE_LOG2 3L
|
||||
#define JS_BITS_PER_SHORT_LOG2 4L
|
||||
#define JS_BITS_PER_INT_LOG2 5L
|
||||
#define JS_BITS_PER_INT64_LOG2 6L
|
||||
#define JS_BITS_PER_LONG_LOG2 5L
|
||||
#define JS_BITS_PER_FLOAT_LOG2 5L
|
||||
#define JS_BITS_PER_DOUBLE_LOG2 6L
|
||||
#define JS_BITS_PER_WORD_LOG2 5L
|
||||
|
||||
#define JS_ALIGN_OF_SHORT 2L
|
||||
#define JS_ALIGN_OF_INT 4L
|
||||
#define JS_ALIGN_OF_LONG 4L
|
||||
#define JS_ALIGN_OF_INT64 8L
|
||||
#define JS_ALIGN_OF_FLOAT 4L
|
||||
#define JS_ALIGN_OF_DOUBLE 8L
|
||||
#define JS_ALIGN_OF_POINTER 4L
|
||||
#define JS_ALIGN_OF_WORD 4L
|
||||
|
||||
#define JS_BYTES_PER_WORD_LOG2 2L
|
||||
#define JS_BYTES_PER_DWORD_LOG2 3L
|
||||
#define PR_WORDS_PER_DWORD_LOG2 1L
|
||||
|
||||
|
||||
#elif defined(SONY)
|
||||
/* Don't have it */
|
||||
|
||||
#elif defined(NECSVR4)
|
||||
/* Don't have it */
|
||||
|
||||
#elif defined(SCO)
|
||||
#define IS_LITTLE_ENDIAN 1
|
||||
#undef IS_BIG_ENDIAN
|
||||
|
||||
#define JS_BYTES_PER_BYTE 1L
|
||||
#define JS_BYTES_PER_SHORT 2L
|
||||
#define JS_BYTES_PER_INT 4L
|
||||
#define JS_BYTES_PER_INT64 8L
|
||||
#define JS_BYTES_PER_LONG 4L
|
||||
#define JS_BYTES_PER_FLOAT 4L
|
||||
#define JS_BYTES_PER_DOUBLE 8L
|
||||
#define JS_BYTES_PER_WORD 4L
|
||||
#define JS_BYTES_PER_DWORD 8L
|
||||
|
||||
#define JS_BITS_PER_BYTE 8L
|
||||
#define JS_BITS_PER_SHORT 16L
|
||||
#define JS_BITS_PER_INT 32L
|
||||
#define JS_BITS_PER_INT64 64L
|
||||
#define JS_BITS_PER_LONG 32L
|
||||
#define JS_BITS_PER_FLOAT 32L
|
||||
#define JS_BITS_PER_DOUBLE 64L
|
||||
#define JS_BITS_PER_WORD 32L
|
||||
|
||||
#define JS_BITS_PER_BYTE_LOG2 3L
|
||||
#define JS_BITS_PER_SHORT_LOG2 4L
|
||||
#define JS_BITS_PER_INT_LOG2 5L
|
||||
#define JS_BITS_PER_INT64_LOG2 6L
|
||||
#define JS_BITS_PER_LONG_LOG2 5L
|
||||
#define JS_BITS_PER_FLOAT_LOG2 5L
|
||||
#define JS_BITS_PER_DOUBLE_LOG2 6L
|
||||
#define JS_BITS_PER_WORD_LOG2 5L
|
||||
|
||||
#define JS_ALIGN_OF_SHORT 2L
|
||||
#define JS_ALIGN_OF_INT 4L
|
||||
#define JS_ALIGN_OF_LONG 4L
|
||||
#define JS_ALIGN_OF_INT64 4L
|
||||
#define JS_ALIGN_OF_FLOAT 4L
|
||||
#define JS_ALIGN_OF_DOUBLE 4L
|
||||
#define JS_ALIGN_OF_POINTER 4L
|
||||
#define JS_ALIGN_OF_WORD 4L
|
||||
|
||||
#define JS_BYTES_PER_WORD_LOG2 2L
|
||||
#define JS_BYTES_PER_DWORD_LOG2 3L
|
||||
#define PR_WORDS_PER_DWORD_LOG2 1L
|
||||
|
||||
|
||||
#elif defined(UNIXWARE)
|
||||
#define IS_LITTLE_ENDIAN 1
|
||||
#undef IS_BIG_ENDIAN
|
||||
|
||||
#define JS_BYTES_PER_BYTE 1L
|
||||
#define JS_BYTES_PER_SHORT 2L
|
||||
#define JS_BYTES_PER_INT 4L
|
||||
#define JS_BYTES_PER_INT64 8L
|
||||
#define JS_BYTES_PER_LONG 4L
|
||||
#define JS_BYTES_PER_FLOAT 4L
|
||||
#define JS_BYTES_PER_DOUBLE 8L
|
||||
#define JS_BYTES_PER_WORD 4L
|
||||
#define JS_BYTES_PER_DWORD 8L
|
||||
|
||||
#define JS_BITS_PER_BYTE 8L
|
||||
#define JS_BITS_PER_SHORT 16L
|
||||
#define JS_BITS_PER_INT 32L
|
||||
#define JS_BITS_PER_INT64 64L
|
||||
#define JS_BITS_PER_LONG 32L
|
||||
#define JS_BITS_PER_FLOAT 32L
|
||||
#define JS_BITS_PER_DOUBLE 64L
|
||||
#define JS_BITS_PER_WORD 32L
|
||||
|
||||
#define JS_BITS_PER_BYTE_LOG2 3L
|
||||
#define JS_BITS_PER_SHORT_LOG2 4L
|
||||
#define JS_BITS_PER_INT_LOG2 5L
|
||||
#define JS_BITS_PER_INT64_LOG2 6L
|
||||
#define JS_BITS_PER_LONG_LOG2 5L
|
||||
#define JS_BITS_PER_FLOAT_LOG2 5L
|
||||
#define JS_BITS_PER_DOUBLE_LOG2 6L
|
||||
#define JS_BITS_PER_WORD_LOG2 5L
|
||||
|
||||
#define JS_ALIGN_OF_SHORT 2L
|
||||
#define JS_ALIGN_OF_INT 4L
|
||||
#define JS_ALIGN_OF_LONG 4L
|
||||
#define JS_ALIGN_OF_INT64 4L
|
||||
#define JS_ALIGN_OF_FLOAT 4L
|
||||
#define JS_ALIGN_OF_DOUBLE 4L
|
||||
#define JS_ALIGN_OF_POINTER 4L
|
||||
#define JS_ALIGN_OF_WORD 4L
|
||||
|
||||
#define JS_BYTES_PER_WORD_LOG2 2L
|
||||
#define JS_BYTES_PER_DWORD_LOG2 3L
|
||||
#define PR_WORDS_PER_DWORD_LOG2 1L
|
||||
|
||||
#endif
|
||||
#endif /* XP_UNIX */
|
||||
|
||||
#endif /* js_cpucfg___ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -22,7 +22,7 @@
|
||||
* JS Date class interface.
|
||||
*/
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
extern JSObject *
|
||||
js_InitDateClass(JSContext *cx, JSObject *obj);
|
||||
@@ -32,7 +32,7 @@ js_InitDateClass(JSContext *cx, JSObject *obj);
|
||||
*/
|
||||
extern JS_FRIEND_API(JSObject*)
|
||||
js_NewDateObject(JSContext* cx, int year, int mon, int mday,
|
||||
int hour, int min, int sec);
|
||||
int hour, int min, int sec);
|
||||
|
||||
extern JS_FRIEND_API(int)
|
||||
js_DateGetYear(JSContext *cx, JSObject* obj);
|
||||
@@ -71,6 +71,6 @@ extern JS_FRIEND_API(void)
|
||||
js_DateSetSeconds(JSContext *cx, JSObject *obj, int seconds);
|
||||
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsdate_h___ */
|
||||
|
||||
@@ -21,9 +21,10 @@
|
||||
*/
|
||||
#include "jsstddef.h"
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "prlog.h"
|
||||
#include "prclist.h"
|
||||
#include "jstypes.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#include "jsclist.h"
|
||||
#include "jsapi.h"
|
||||
#include "jscntxt.h"
|
||||
#include "jsconfig.h"
|
||||
@@ -39,7 +40,7 @@
|
||||
#include "jsstr.h"
|
||||
|
||||
typedef struct JSTrap {
|
||||
PRCList links;
|
||||
JSCList links;
|
||||
JSScript *script;
|
||||
jsbytecode *pc;
|
||||
JSOp op;
|
||||
@@ -93,7 +94,7 @@ JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
PR_APPEND_LINK(&trap->links, &rt->trapList);
|
||||
JS_APPEND_LINK(&trap->links, &rt->trapList);
|
||||
trap->script = script;
|
||||
trap->pc = pc;
|
||||
trap->op = (JSOp)*pc;
|
||||
@@ -110,7 +111,7 @@ JS_GetTrapOpcode(JSContext *cx, JSScript *script, jsbytecode *pc)
|
||||
|
||||
trap = FindTrap(cx->runtime, script, pc);
|
||||
if (!trap) {
|
||||
PR_ASSERT(0); /* XXX can't happen */
|
||||
JS_ASSERT(0); /* XXX can't happen */
|
||||
return JSOP_LIMIT;
|
||||
}
|
||||
return trap->op;
|
||||
@@ -119,7 +120,7 @@ JS_GetTrapOpcode(JSContext *cx, JSScript *script, jsbytecode *pc)
|
||||
static void
|
||||
DestroyTrap(JSContext *cx, JSTrap *trap)
|
||||
{
|
||||
PR_REMOVE_LINK(&trap->links);
|
||||
JS_REMOVE_LINK(&trap->links);
|
||||
*trap->pc = (jsbytecode)trap->op;
|
||||
js_RemoveRoot(cx, &trap->closure);
|
||||
JS_free(cx, trap);
|
||||
@@ -180,7 +181,7 @@ JS_HandleTrap(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval)
|
||||
|
||||
trap = FindTrap(cx->runtime, script, pc);
|
||||
if (!trap) {
|
||||
PR_ASSERT(0); /* XXX can't happen */
|
||||
JS_ASSERT(0); /* XXX can't happen */
|
||||
return JSTRAP_ERROR;
|
||||
}
|
||||
/*
|
||||
@@ -218,7 +219,7 @@ JS_ClearInterrupt(JSRuntime *rt, JSTrapHandler *handlerp, void **closurep)
|
||||
|
||||
|
||||
typedef struct JSWatchPoint {
|
||||
PRCList links;
|
||||
JSCList links;
|
||||
JSObject *object; /* weak link, see js_FinalizeObject */
|
||||
jsval userid;
|
||||
JSScopeProperty *sprop;
|
||||
@@ -239,7 +240,7 @@ DropWatchPoint(JSContext *cx, JSWatchPoint *wp)
|
||||
JS_LOCK_OBJ_VOID(cx, wp->object,
|
||||
js_DropScopeProperty(cx, (JSScope *)wp->object->map,
|
||||
wp->sprop));
|
||||
PR_REMOVE_LINK(&wp->links);
|
||||
JS_REMOVE_LINK(&wp->links);
|
||||
js_RemoveRoot(cx, &wp->closure);
|
||||
JS_free(cx, wp);
|
||||
}
|
||||
@@ -269,7 +270,7 @@ js_FindWatchPoint(JSRuntime *rt, JSObject *obj, jsval userid)
|
||||
return wp->sprop;
|
||||
}
|
||||
|
||||
JSBool PR_CALLBACK
|
||||
JSBool DLL_CALLBACK
|
||||
js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
@@ -304,7 +305,7 @@ js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
symid = (jsid)atom;
|
||||
}
|
||||
scope = (JSScope *) obj->map;
|
||||
PR_ASSERT(scope->props);
|
||||
JS_ASSERT(scope->props);
|
||||
ok = LOCKED_OBJ_GET_CLASS(obj)->addProperty(cx, obj, sprop->id,
|
||||
&value);
|
||||
if (!ok) {
|
||||
@@ -329,7 +330,7 @@ js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
PR_ASSERT(0); /* XXX can't happen */
|
||||
JS_ASSERT(0); /* XXX can't happen */
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@@ -345,8 +346,8 @@ JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval id,
|
||||
JSWatchPoint *wp;
|
||||
|
||||
if (!OBJ_IS_NATIVE(obj)) {
|
||||
JS_ReportError(cx, "can't watch non-native objects of class %s",
|
||||
OBJ_GET_CLASS(cx, obj)->name);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_WATCH,
|
||||
OBJ_GET_CLASS(cx, obj)->name);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@@ -415,7 +416,7 @@ JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval id,
|
||||
JS_free(cx, wp);
|
||||
return JS_FALSE;
|
||||
}
|
||||
PR_APPEND_LINK(&wp->links, &rt->watchPointList);
|
||||
JS_APPEND_LINK(&wp->links, &rt->watchPointList);
|
||||
wp->object = obj;
|
||||
wp->userid = id;
|
||||
wp->sprop = js_HoldScopeProperty(cx, (JSScope *)obj->map, sprop);
|
||||
@@ -580,12 +581,36 @@ JS_IsNativeFrame(JSContext *cx, JSStackFrame *fp)
|
||||
return fp->fun && fp->fun->call;
|
||||
}
|
||||
|
||||
/* this is deprecated, use JS_GetFrameScopeChain instead */
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_GetFrameObject(JSContext *cx, JSStackFrame *fp)
|
||||
{
|
||||
return fp->scopeChain;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fp)
|
||||
{
|
||||
/* Force creation of argument and call objects if not yet created */
|
||||
JS_GetFrameCallObject(cx, fp);
|
||||
return fp->scopeChain;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_GetFrameCallObject(JSContext *cx, JSStackFrame *fp)
|
||||
{
|
||||
if (! fp->fun)
|
||||
return NULL;
|
||||
/* Force creation of argument object if not yet created */
|
||||
js_GetArgsObject(cx, fp);
|
||||
#if JS_HAS_CALL_OBJECT
|
||||
return js_GetCallObject(cx, fp, NULL, NULL);
|
||||
#else
|
||||
return NULL;
|
||||
#endif /* JS_HAS_CALL_OBJECT */
|
||||
}
|
||||
|
||||
|
||||
JS_PUBLIC_API(JSObject *)
|
||||
JS_GetFrameThis(JSContext *cx, JSStackFrame *fp)
|
||||
{
|
||||
@@ -598,6 +623,30 @@ JS_GetFrameFunction(JSContext *cx, JSStackFrame *fp)
|
||||
return fp->fun;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_IsContructorFrame(JSContext *cx, JSStackFrame *fp)
|
||||
{
|
||||
return fp->constructing;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_IsDebuggerFrame(JSContext *cx, JSStackFrame *fp)
|
||||
{
|
||||
return fp->debugging;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(jsval)
|
||||
JS_GetFrameReturnValue(JSContext *cx, JSStackFrame *fp)
|
||||
{
|
||||
return fp->rval;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_SetFrameReturnValue(JSContext *cx, JSStackFrame *fp, jsval rval)
|
||||
{
|
||||
fp->rval = rval;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
JS_PUBLIC_API(const char *)
|
||||
@@ -680,12 +729,22 @@ JS_GetPropertyDesc(JSContext *cx, JSObject *obj, JSScopeProperty *sprop,
|
||||
|
||||
sym = sprop->symbols;
|
||||
pd->id = sym ? js_IdToValue(sym_id(sym)) : JSVAL_VOID;
|
||||
pd->value = OBJ_GET_SLOT(cx, obj, sprop->slot);
|
||||
if (!sym || !js_GetProperty(cx, obj, sym_id(sym), &pd->value))
|
||||
pd->value = OBJ_GET_SLOT(cx, obj, sprop->slot);
|
||||
pd->flags = ((sprop->attrs & JSPROP_ENUMERATE) ? JSPD_ENUMERATE : 0)
|
||||
| ((sprop->attrs & JSPROP_READONLY) ? JSPD_READONLY : 0)
|
||||
| ((sprop->attrs & JSPROP_PERMANENT) ? JSPD_PERMANENT : 0)
|
||||
#if JS_HAS_CALL_OBJECT
|
||||
| ((sprop->getter == js_GetCallVariable) ? JSPD_VARIABLE : 0)
|
||||
#endif /* JS_HAS_CALL_OBJECT */
|
||||
| ((sprop->getter == js_GetArgument) ? JSPD_ARGUMENT : 0)
|
||||
| ((sprop->getter == js_GetLocalVariable) ? JSPD_VARIABLE : 0);
|
||||
#if JS_HAS_CALL_OBJECT
|
||||
/* for Call Object 'real' getter isn't passed in to us */
|
||||
if (OBJ_GET_CLASS(cx, obj) == &js_CallClass &&
|
||||
OBJ_GET_CLASS(cx, obj)->getProperty == sprop->getter)
|
||||
pd->flags |= JSPD_ARGUMENT;
|
||||
#endif /* JS_HAS_CALL_OBJECT */
|
||||
pd->spare = 0;
|
||||
pd->slot = (pd->flags & (JSPD_ARGUMENT | JSPD_VARIABLE))
|
||||
? JSVAL_TO_INT(sprop->id)
|
||||
@@ -706,11 +765,16 @@ JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda)
|
||||
uint32 i, n;
|
||||
JSPropertyDesc *pd;
|
||||
JSScopeProperty *sprop;
|
||||
jsval state;
|
||||
jsid num_prop;
|
||||
|
||||
if (!OBJ_GET_CLASS(cx, obj)->enumerate(cx, obj))
|
||||
if (!OBJ_ENUMERATE(cx, obj, JSENUMERATE_INIT, &state, &num_prop))
|
||||
return JS_FALSE;
|
||||
scope = (JSScope *)obj->map;
|
||||
if (!scope->props) {
|
||||
/* have no props, or object's scope has not mutated from that of proto */
|
||||
if (!scope->props ||
|
||||
(OBJ_GET_PROTO(cx,obj) &&
|
||||
scope == (JSScope *)(OBJ_GET_PROTO(cx,obj)->map))) {
|
||||
pda->length = 0;
|
||||
pda->array = NULL;
|
||||
return JS_TRUE;
|
||||
@@ -767,3 +831,29 @@ JS_SetDebuggerHandler(JSRuntime *rt, JSTrapHandler handler, void *closure)
|
||||
rt->debuggerHandlerData = closure;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure)
|
||||
{
|
||||
rt->sourceHandler = handler;
|
||||
rt->sourceHandlerData = closure;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure)
|
||||
{
|
||||
rt->executeHook = hook;
|
||||
rt->executeHookData = closure;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure)
|
||||
{
|
||||
rt->callHook = hook;
|
||||
rt->callHookData = closure;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "jsopcode.h"
|
||||
#include "jsprvtd.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
extern void
|
||||
js_PatchOpcode(JSContext *cx, JSScript *script, jsbytecode *pc, JSOp op);
|
||||
@@ -58,10 +58,6 @@ JS_ClearInterrupt(JSRuntime *rt, JSTrapHandler *handlerp, void **closurep);
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
typedef JSBool
|
||||
(*JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsval id,
|
||||
jsval old, jsval *newp, void *closure);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval id,
|
||||
JSWatchPointHandler handler, void *closure);
|
||||
@@ -84,7 +80,7 @@ JS_ClearAllWatchPoints(JSContext *cx);
|
||||
extern JSScopeProperty *
|
||||
js_FindWatchPoint(JSRuntime *rt, JSObject *obj, jsval userid);
|
||||
|
||||
extern JSBool PR_CALLBACK
|
||||
extern JSBool DLL_CALLBACK
|
||||
js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
|
||||
#endif
|
||||
|
||||
@@ -130,15 +126,34 @@ JS_SetFrameAnnotation(JSContext *cx, JSStackFrame *fp, void *annotation);
|
||||
extern JS_PUBLIC_API(void *)
|
||||
JS_GetFramePrincipalArray(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
/* this is deprecated, use JS_GetFrameScopeChain instead */
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
JS_GetFrameObject(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
JS_GetFrameCallObject(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject *)
|
||||
JS_GetFrameThis(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
extern JS_PUBLIC_API(JSFunction *)
|
||||
JS_GetFrameFunction(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_IsContructorFrame(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_IsDebuggerFrame(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
extern JS_PUBLIC_API(jsval)
|
||||
JS_GetFrameReturnValue(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_SetFrameReturnValue(JSContext *cx, JSStackFrame *fp, jsval rval);
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
extern JS_PUBLIC_API(const char *)
|
||||
@@ -216,6 +231,15 @@ JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda);
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetDebuggerHandler(JSRuntime *rt, JSTrapHandler handler, void *closure);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure);
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsdbgapi_h___ */
|
||||
|
||||
@@ -20,10 +20,11 @@
|
||||
* Portable double to alphanumeric string and back converters.
|
||||
*/
|
||||
#include "jsstddef.h"
|
||||
#include "prtypes.h"
|
||||
#include "prdtoa.h"
|
||||
#include "prprf.h"
|
||||
#include "prlog.h"
|
||||
#include "jstypes.h"
|
||||
#include "jsdtoa.h"
|
||||
#include "jsprf.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
#include "prlock.h"
|
||||
@@ -206,7 +207,7 @@ extern void *MALLOC(size_t);
|
||||
#define Sign_Extend(a,b) /*no-op*/
|
||||
#endif
|
||||
|
||||
#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1
|
||||
#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1
|
||||
Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
|
||||
#endif
|
||||
|
||||
@@ -1184,21 +1185,21 @@ static CONST double tinytens[] = { 1e-16, 1e-32 };
|
||||
#endif
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
static PRBool initialized = PR_FALSE;
|
||||
static JSBool initialized = JS_FALSE;
|
||||
|
||||
/* hacked replica of nspr _PR_InitDtoa */
|
||||
static void InitDtoa(void)
|
||||
{
|
||||
freelist_lock = PR_NewLock();
|
||||
p5s_lock = PR_NewLock();
|
||||
initialized = PR_TRUE;
|
||||
initialized = JS_TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* nspr2 watcom bug ifdef omitted */
|
||||
|
||||
PR_PUBLIC_API(double)
|
||||
PUBLIC_API(double)
|
||||
PR_strtod(CONST char *s00, char **se)
|
||||
{
|
||||
int32 bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign,
|
||||
@@ -1872,7 +1873,7 @@ quorem(Bigint *b, Bigint *S)
|
||||
* calculation.
|
||||
*/
|
||||
|
||||
static PRBool
|
||||
static JSBool
|
||||
PR_dtoa(double d, int mode, int ndigits,
|
||||
int *decpt, int *sign, char **rve, char *buf, size_t bufsize)
|
||||
{
|
||||
@@ -1923,7 +1924,7 @@ PR_dtoa(double d, int mode, int ndigits,
|
||||
char *s, *s0;
|
||||
Bigint *result = 0;
|
||||
static int32 result_k;
|
||||
PRBool retval;
|
||||
JSBool retval;
|
||||
size_t strsize;
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
@@ -1953,9 +1954,9 @@ PR_dtoa(double d, int mode, int ndigits,
|
||||
#endif
|
||||
"NaN";
|
||||
if ((s[0] == 'I' && bufsize < 9) || (s[0] == 'N' && bufsize < 4)) {
|
||||
PR_ASSERT(PR_FALSE);
|
||||
/* PR_SetError(PR_BUFFER_OVERFLOW_ERROR, 0); */
|
||||
return PR_FALSE;
|
||||
JS_ASSERT(JS_FALSE);
|
||||
/* JS_SetError(JS_BUFFER_OVERFLOW_ERROR, 0); */
|
||||
return JS_FALSE;
|
||||
}
|
||||
strcpy(buf, s);
|
||||
if (rve) {
|
||||
@@ -1964,9 +1965,9 @@ PR_dtoa(double d, int mode, int ndigits,
|
||||
buf[3] ? buf + 8 :
|
||||
#endif
|
||||
buf + 3;
|
||||
PR_ASSERT(**rve == '\0');
|
||||
JS_ASSERT(**rve == '\0');
|
||||
}
|
||||
return PR_TRUE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
#endif
|
||||
#ifdef IBM
|
||||
@@ -1975,16 +1976,16 @@ PR_dtoa(double d, int mode, int ndigits,
|
||||
if (!d) {
|
||||
*decpt = 1;
|
||||
if (bufsize < 2) {
|
||||
PR_ASSERT(PR_FALSE);
|
||||
/* PR_SetError(PR_BUFFER_OVERFLOW_ERROR, 0); */
|
||||
return PR_FALSE;
|
||||
JS_ASSERT(JS_FALSE);
|
||||
/* JS_SetError(JS_BUFFER_OVERFLOW_ERROR, 0); */
|
||||
return JS_FALSE;
|
||||
}
|
||||
buf[0] = '0'; buf[1] = '\0'; /* copy "0" to buffer */
|
||||
if (rve) {
|
||||
*rve = buf + 1;
|
||||
PR_ASSERT(**rve == '\0');
|
||||
JS_ASSERT(**rve == '\0');
|
||||
}
|
||||
return PR_TRUE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
b = d2b(d, &be, &bbits);
|
||||
@@ -2488,16 +2489,16 @@ ret1:
|
||||
*decpt = k + 1;
|
||||
strsize = (s - s0) + 1;
|
||||
if (strsize <= bufsize) {
|
||||
retval = PR_TRUE;
|
||||
retval = JS_TRUE;
|
||||
memcpy(buf, s0, strsize);
|
||||
if (rve) {
|
||||
*rve = buf + strsize - 1;
|
||||
PR_ASSERT(**rve == '\0');
|
||||
JS_ASSERT(**rve == '\0');
|
||||
}
|
||||
} else {
|
||||
PR_ASSERT(PR_FALSE);
|
||||
/* PR_SetError(PR_BUFFER_OVERFLOW_ERROR, 0); */
|
||||
retval = PR_FALSE;
|
||||
JS_ASSERT(JS_FALSE);
|
||||
/* JS_SetError(JS_BUFFER_OVERFLOW_ERROR, 0); */
|
||||
retval = JS_FALSE;
|
||||
}
|
||||
|
||||
/* cleanup */
|
||||
@@ -2519,7 +2520,7 @@ ret1:
|
||||
** Also, the ECMA spec says that there should always be a
|
||||
** '+' or '-' after the 'e' in scientific notation
|
||||
*/
|
||||
PR_PUBLIC_API(void)
|
||||
PUBLIC_API(void)
|
||||
PR_cnvtf(char *buf,int bufsz, int prcsn,double fval)
|
||||
{
|
||||
intN decpt,sign,numdigits;
|
||||
@@ -2535,7 +2536,7 @@ PR_cnvtf(char *buf,int bufsz, int prcsn,double fval)
|
||||
}
|
||||
/* XXX Why use mode 1? */
|
||||
if (PR_dtoa(fval,1,prcsn,&decpt,&sign,&endnum,num,bufsz)
|
||||
== PR_FALSE) {
|
||||
== JS_FALSE) {
|
||||
buf[0] = '\0';
|
||||
goto done;
|
||||
}
|
||||
@@ -2565,7 +2566,7 @@ PR_cnvtf(char *buf,int bufsz, int prcsn,double fval)
|
||||
*bufp++ = *nump++;
|
||||
}
|
||||
*bufp++ = 'e';
|
||||
PR_snprintf(bufp,bufsz - (bufp - buf), "%+d",decpt-1);
|
||||
JS_snprintf(bufp,bufsz - (bufp - buf), "%+d",decpt-1);
|
||||
}
|
||||
else if(decpt >= 0){
|
||||
if (decpt == 0){
|
||||
@@ -16,8 +16,8 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef prdtoa_h___
|
||||
#define prdtoa_h___
|
||||
#ifndef jsdtoa_h___
|
||||
#define jsdtoa_h___
|
||||
/*
|
||||
* Public interface to portable double-precision floating point to string
|
||||
* and back conversion package.
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "jscompat.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
* PR_strtod() returns as a double-precision floating-point number
|
||||
@@ -37,7 +37,7 @@ PR_BEGIN_EXTERN_C
|
||||
* to by se. If no number can be formed, se is set to s00r, and
|
||||
* zero is returned.
|
||||
*/
|
||||
extern PR_PUBLIC_API(double)
|
||||
extern PUBLIC_API(double)
|
||||
PR_strtod(const char *s00, char **se);
|
||||
|
||||
/*
|
||||
@@ -46,9 +46,9 @@ PR_strtod(const char *s00, char **se);
|
||||
* prcsn - number of digits of precision to generate floating
|
||||
* point value.
|
||||
*/
|
||||
extern PR_PUBLIC_API(void)
|
||||
extern PUBLIC_API(void)
|
||||
PR_cnvtf(char *buf, intN bufsz, intN prcsn, double dval);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* prdtoa_h___ */
|
||||
#endif /* jsdtoa_h___ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -23,13 +23,13 @@
|
||||
*/
|
||||
|
||||
#include "jsstddef.h"
|
||||
#include "prtypes.h"
|
||||
#include "jstypes.h"
|
||||
#include "jsatom.h"
|
||||
#include "jsopcode.h"
|
||||
#include "jsprvtd.h"
|
||||
#include "jspubtd.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
typedef enum JSStmtType {
|
||||
STMT_BLOCK = 0, /* compound statement: { s1[;... sN] } */
|
||||
@@ -62,7 +62,7 @@ struct JSStmtInfo {
|
||||
};
|
||||
|
||||
#define SET_STATEMENT_TOP(stmt, top) \
|
||||
((stmt)->top = (stmt)->update = (stmt)->breaks = (stmt)->continues = (top))
|
||||
((stmt)->top = (stmt)->update = (top), (stmt)->breaks = (stmt)->continues = (-1))
|
||||
|
||||
struct JSTreeContext { /* tree context for semantic checks */
|
||||
uint32 flags; /* statement state flags, see below */
|
||||
@@ -75,7 +75,7 @@ struct JSTreeContext { /* tree context for semantic checks */
|
||||
#define TCF_RETURN_VOID 0x04 /* function has 'return;' */
|
||||
#define TCF_IN_FOR_INIT 0x08 /* parsing init expr of for; exclude 'in' */
|
||||
|
||||
#define INIT_TREE_CONTEXT(tc) \
|
||||
#define TREE_CONTEXT_INIT(tc) \
|
||||
((tc)->flags = 0, (tc)->tryCount = 0, (tc)->topStmt = NULL)
|
||||
|
||||
struct JSCodeGenerator {
|
||||
@@ -84,37 +84,24 @@ struct JSCodeGenerator {
|
||||
jsbytecode *base; /* base of JS bytecode vector */
|
||||
jsbytecode *limit; /* one byte beyond end of bytecode */
|
||||
jsbytecode *next; /* pointer to next free bytecode */
|
||||
JSAtomList atomList; /* literals indexed for mapping */
|
||||
ptrdiff_t lastCodeOffset; /* offset of last non-nop opcode */
|
||||
intN stackDepth; /* current stack depth in basic block */
|
||||
uintN maxStackDepth; /* maximum stack depth so far */
|
||||
jssrcnote *notes; /* source notes, see below */
|
||||
uintN noteCount; /* number of source notes so far */
|
||||
ptrdiff_t lastNoteOffset; /* code offset for last source note */
|
||||
const char *filename; /* null or weak link to source filename */
|
||||
uintN firstLine; /* first line, for js_NewScriptFromCG */
|
||||
uintN currentLine; /* line number for tree-based srcnote gen */
|
||||
JSPrincipals *principals; /* principals for constant folding eval */
|
||||
JSTreeContext treeContext; /* for break/continue code generation */
|
||||
JSTryNote *tryBase; /* first exception handling block */
|
||||
JSTryNote *tryNext; /* next avail block */
|
||||
JSTryNote *tryLimit; /* pointer to one-past-end block */
|
||||
JSAtomList atomList; /* literals indexed for mapping */
|
||||
intN stackDepth; /* current stack depth in basic block */
|
||||
uintN maxStackDepth; /* maximum stack depth so far */
|
||||
jssrcnote *notes; /* source notes, see below */
|
||||
uintN noteCount; /* number of source notes so far */
|
||||
ptrdiff_t lastNoteOffset; /* code offset for last source note */
|
||||
JSTryNote *tryBase; /* first exception handling note */
|
||||
JSTryNote *tryNext; /* next available note */
|
||||
size_t tryNoteSpace; /* # of bytes allocated at tryBase */
|
||||
};
|
||||
|
||||
#define CG_CODE(cg,offset) ((cg)->base + (offset))
|
||||
#define CG_OFFSET(cg) PTRDIFF((cg)->next, (cg)->base, jsbytecode)
|
||||
#define CG_RESET(cg) ((cg)->next = (cg)->base, \
|
||||
ATOM_LIST_INIT(&(cg)->atomList), \
|
||||
(cg)->lastCodeOffset = 0, \
|
||||
(cg)->stackDepth = (cg)->maxStackDepth = 0, \
|
||||
(cg)->currentLine = (cg)->firstLine, \
|
||||
INIT_TREE_CONTEXT(&(cg)->treeContext), \
|
||||
(cg)->tryNext = (cg)->tryBase, \
|
||||
CG_RESET_NOTES(cg))
|
||||
#define CG_RESET_NOTES(cg) ((cg)->notes = NULL, (cg)->noteCount = 0, \
|
||||
(cg)->lastNoteOffset = 0)
|
||||
#define CG_PUSH(cg, newcg) ((newcg)->atomList = (cg)->atomList)
|
||||
#define CG_POP(cg, newcg) ((cg)->atomList = (newcg)->atomList)
|
||||
#define CG_CODE(cg,offset) ((cg)->base + (offset))
|
||||
#define CG_OFFSET(cg) PTRDIFF((cg)->next, (cg)->base, jsbytecode)
|
||||
|
||||
/*
|
||||
* Initialize cg to allocate bytecode space from cx->codePool, and srcnote
|
||||
@@ -161,10 +148,10 @@ js_EmitN(JSContext *cx, JSCodeGenerator *cg, JSOp op, size_t extra);
|
||||
* Unsafe macro to call js_SetJumpOffset and return false if it does.
|
||||
*/
|
||||
#define CHECK_AND_SET_JUMP_OFFSET(cx,cg,pc,off) \
|
||||
PR_BEGIN_MACRO \
|
||||
JS_BEGIN_MACRO \
|
||||
if (!js_SetJumpOffset(cx, cg, pc, off)) \
|
||||
return JS_FALSE; \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
#define CHECK_AND_SET_JUMP_OFFSET_AT(cx,cg,off) \
|
||||
CHECK_AND_SET_JUMP_OFFSET(cx, cg, CG_CODE(cg,off), CG_OFFSET(cg) - (off))
|
||||
@@ -228,7 +215,7 @@ js_EmitFunctionBody(JSContext *cx, JSCodeGenerator *cg, JSParseNode *body,
|
||||
* the previous note. If 3 bits of offset aren't enough, extended delta notes
|
||||
* (SRC_XDELTA) consisting of 2 set high order bits followed by 6 offset bits
|
||||
* are emitted before the next note. Some notes have operand offsets encoded
|
||||
* in note bytes or byte-pairs.
|
||||
* immediately after them, in note bytes or byte-triples.
|
||||
*
|
||||
* At most one "gettable" note (i.e., a note of type other than SRC_NEWLINE,
|
||||
* SRC_SETLINE, and SRC_XDELTA) applies to a given bytecode.
|
||||
@@ -242,9 +229,12 @@ typedef enum JSSrcNoteType {
|
||||
SRC_IF_ELSE = 2, /* JSOP_IFEQ bytecode is from an if-then-else */
|
||||
SRC_WHILE = 3, /* JSOP_IFEQ is from a while loop */
|
||||
SRC_FOR = 4, /* JSOP_NOP or JSOP_POP in for loop head */
|
||||
SRC_CONTINUE = 5, /* JSOP_GOTO is a continue, not a break */
|
||||
SRC_CONTINUE = 5, /* JSOP_GOTO is a continue, not a break;
|
||||
also used on JSOP_ENDINIT if extra comma
|
||||
at end of array literal: [1,2,,] */
|
||||
SRC_VAR = 6, /* JSOP_NAME/FORNAME with a var declaration */
|
||||
SRC_COMMA = 7, /* JSOP_POP representing a comma operator */
|
||||
SRC_PCDELTA = 7, /* offset from comma-operator to next POP,
|
||||
or from CONDSWITCH to first CASE opcode */
|
||||
SRC_ASSIGNOP = 8, /* += or another assign-op follows */
|
||||
SRC_COND = 9, /* JSOP_IFEQ is from conditional ?: operator */
|
||||
SRC_PAREN = 10, /* JSOP_NOP generated to mark user parens */
|
||||
@@ -255,9 +245,10 @@ typedef enum JSSrcNoteType {
|
||||
SRC_ENDBRACE = 15, /* JSOP_NOP for label: {...} end brace */
|
||||
SRC_BREAK2LABEL = 16, /* JSOP_GOTO for 'break label' with atomid */
|
||||
SRC_CONT2LABEL = 17, /* JSOP_GOTO for 'continue label' with atomid */
|
||||
SRC_SWITCH = 18, /* JSOP_*SWITCH with offset to end of switch */
|
||||
SRC_SWITCH = 18, /* JSOP_*SWITCH with offset to end of switch,
|
||||
2nd off to first JSOP_CASE if condswitch */
|
||||
SRC_FUNCDEF = 19, /* JSOP_NOP for function f() with atomid */
|
||||
SRC_TRYFIN = 20, /* JSOP_NOP for try{} or finally{} section */
|
||||
SRC_TRYFIN = 20, /* JSOP_NOP for try or finally section */
|
||||
SRC_CATCH = 21, /* catch block has guard */
|
||||
SRC_NEWLINE = 22, /* bytecode follows a source newline */
|
||||
SRC_SETLINE = 23, /* a file-absolute source line number note */
|
||||
@@ -267,9 +258,9 @@ typedef enum JSSrcNoteType {
|
||||
#define SN_TYPE_BITS 5
|
||||
#define SN_DELTA_BITS 3
|
||||
#define SN_XDELTA_BITS 6
|
||||
#define SN_TYPE_MASK (PR_BITMASK(SN_TYPE_BITS) << SN_DELTA_BITS)
|
||||
#define SN_DELTA_MASK ((ptrdiff_t)PR_BITMASK(SN_DELTA_BITS))
|
||||
#define SN_XDELTA_MASK ((ptrdiff_t)PR_BITMASK(SN_XDELTA_BITS))
|
||||
#define SN_TYPE_MASK (JS_BITMASK(SN_TYPE_BITS) << SN_DELTA_BITS)
|
||||
#define SN_DELTA_MASK ((ptrdiff_t)JS_BITMASK(SN_DELTA_BITS))
|
||||
#define SN_XDELTA_MASK ((ptrdiff_t)JS_BITMASK(SN_XDELTA_BITS))
|
||||
|
||||
#define SN_MAKE_NOTE(sn,t,d) (*(sn) = (jssrcnote) \
|
||||
(((t) << SN_DELTA_BITS) \
|
||||
@@ -291,8 +282,8 @@ typedef enum JSSrcNoteType {
|
||||
? SN_MAKE_XDELTA(sn, delta) \
|
||||
: SN_MAKE_NOTE(sn, SN_TYPE(sn), delta))
|
||||
|
||||
#define SN_DELTA_LIMIT ((ptrdiff_t)PR_BIT(SN_DELTA_BITS))
|
||||
#define SN_XDELTA_LIMIT ((ptrdiff_t)PR_BIT(SN_XDELTA_BITS))
|
||||
#define SN_DELTA_LIMIT ((ptrdiff_t)JS_BIT(SN_DELTA_BITS))
|
||||
#define SN_XDELTA_LIMIT ((ptrdiff_t)JS_BIT(SN_XDELTA_BITS))
|
||||
|
||||
/*
|
||||
* Offset fields follow certain notes and are frequency-encoded: an offset in
|
||||
@@ -345,14 +336,13 @@ js_SetSrcNoteOffset(JSContext *cx, JSCodeGenerator *cg, uintN index,
|
||||
* stable store allocated via JS_malloc. Return null on malloc failure,
|
||||
* which means this function reported an error.
|
||||
*/
|
||||
extern JS_FRIEND_API(jssrcnote *)
|
||||
extern jssrcnote *
|
||||
js_FinishTakingSrcNotes(JSContext *cx, JSCodeGenerator *cg);
|
||||
|
||||
/*
|
||||
* Allocate cg->treeContext.tryCount notes (plus one for the end sentinel)
|
||||
* from cx->tempPool and set cg->tryBase/tryNext/tryLimit for exactly tryCount
|
||||
* js_NewTryNote calls. The storage is freed in one fell swoop by JS_Compile*
|
||||
* API entry points at the end of compilation.
|
||||
* from cx->tempPool and set up cg->tryBase/tryNext for exactly tryCount
|
||||
* js_NewTryNote calls. The storage is freed by js_ResetCodeGenerator.
|
||||
*/
|
||||
extern JSBool
|
||||
js_AllocTryNotes(JSContext *cx, JSCodeGenerator *cg);
|
||||
@@ -360,7 +350,7 @@ js_AllocTryNotes(JSContext *cx, JSCodeGenerator *cg);
|
||||
/*
|
||||
* Grab the next trynote slot in cg, filling it in appropriately.
|
||||
*/
|
||||
extern JS_FRIEND_API(JSTryNote *)
|
||||
extern JSTryNote *
|
||||
js_NewTryNote(JSContext *cx, JSCodeGenerator *cg, ptrdiff_t start,
|
||||
ptrdiff_t end, ptrdiff_t catchStart);
|
||||
|
||||
@@ -368,9 +358,9 @@ js_NewTryNote(JSContext *cx, JSCodeGenerator *cg, ptrdiff_t start,
|
||||
* Finish generating exception information, and copy it to JS_malloc
|
||||
* storage.
|
||||
*/
|
||||
extern JS_FRIEND_API(JSBool)
|
||||
extern JSBool
|
||||
js_FinishTakingTryNotes(JSContext *cx, JSCodeGenerator *cg, JSTryNote **tryp);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsemit_h___ */
|
||||
|
||||
477
mozilla/js/src/jsexn.c
Normal file
477
mozilla/js/src/jsexn.c
Normal file
@@ -0,0 +1,477 @@
|
||||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
* JS standard exception implementation.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* This is currently very messy, and in flux. Don't anybody think
|
||||
* I'm going to leave it like this. No no.
|
||||
*/
|
||||
|
||||
|
||||
#include "jsstddef.h"
|
||||
#include "jstypes.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#include "jsprf.h"
|
||||
#include "jsapi.h"
|
||||
#include "jscntxt.h"
|
||||
#include "jsconfig.h"
|
||||
#include "jsexn.h"
|
||||
|
||||
#if JS_HAS_ERROR_EXCEPTIONS
|
||||
#if !JS_HAS_EXCEPTIONS
|
||||
# error "JS_HAS_EXCEPTIONS must be defined to use JS_HAS_ERROR_EXCEPTIONS"
|
||||
#endif
|
||||
|
||||
JSObject *tlobj;
|
||||
|
||||
/*
|
||||
* This could end up just being the error report, but I
|
||||
* want to learn how to support random garbage here.
|
||||
*
|
||||
* If I go with it, a rambling comment mentioning GC, memory management etc. is
|
||||
* needed.
|
||||
*
|
||||
* I'd rather have the errorReport inline, to avoid the extra malloc'd object
|
||||
* dangle. But I'll figure that out later, if I still need it.
|
||||
*/
|
||||
typedef struct JSExnPrivate {
|
||||
JSErrorReport *errorReport;
|
||||
const char *message;
|
||||
} JSExnPrivate;
|
||||
|
||||
|
||||
/*
|
||||
* Copy everything interesting about an error into allocated memory.
|
||||
*/
|
||||
static JSExnPrivate *
|
||||
exn_initPrivate(JSContext *cx, JSErrorReport *report, const char *message)
|
||||
{
|
||||
JSExnPrivate *newPrivate;
|
||||
JSErrorReport * newReport;
|
||||
char *newMessage;
|
||||
|
||||
newPrivate = (JSExnPrivate *)JS_malloc(cx, sizeof (JSExnPrivate));
|
||||
|
||||
JS_ASSERT(message);
|
||||
newMessage = (char *)JS_malloc(cx, strlen(message)+1);
|
||||
strcpy(newMessage, message);
|
||||
newPrivate->message = newMessage;
|
||||
|
||||
/* Copy the error report */
|
||||
newReport = (JSErrorReport *)JS_malloc(cx, sizeof (JSErrorReport));
|
||||
|
||||
if (report->filename) {
|
||||
newReport->filename =
|
||||
(const char *)JS_malloc(cx, strlen(report->filename)+1);
|
||||
/* Ack. Const! */
|
||||
strcpy((char *)newReport->filename, report->filename);
|
||||
} else {
|
||||
newReport->filename = NULL;
|
||||
}
|
||||
|
||||
newReport->lineno = report->lineno;
|
||||
|
||||
/*
|
||||
* We don't need to copy linebuf and tokenptr, because they
|
||||
* point into the deflated string cache. (currently?)
|
||||
*/
|
||||
newReport->linebuf = report->linebuf;
|
||||
newReport->tokenptr = report->tokenptr;
|
||||
|
||||
/*
|
||||
* But we do need to copy uclinebuf, uctokenptr, because they're
|
||||
* pointers into internal tokenstream structs, and may go away.
|
||||
* But only if they're non-null...
|
||||
*
|
||||
* NOTE nothing uses this and I'm not really maintaining it until
|
||||
* I know it's the desired API.
|
||||
*
|
||||
* Temporarily disabled, because uclinebuf is 0x10 when I evaluate 'Math()'!
|
||||
*/
|
||||
|
||||
#if 0
|
||||
if (report->uclinebuf) {
|
||||
size_t len = js_strlen(report->uclinebuf)+1;
|
||||
newReport->uclinebuf =
|
||||
(const jschar *)JS_malloc(cx, len);
|
||||
js_strncpy(newReport->uclinebuf, report->uclinebuf, len);
|
||||
newReport->uctokenptr = newReport->uclinebuf + (report->uctokenptr -
|
||||
report->uclinebuf);
|
||||
} else
|
||||
#endif
|
||||
newReport->uclinebuf = newReport->uctokenptr = NULL;
|
||||
|
||||
/* Note that this is before it gets flagged with JSREPORT_EXCEPTION */
|
||||
newReport->flags = report->flags;
|
||||
|
||||
/* Skipping *ucmessage, **messageArgs for now. My guess is that it'll just
|
||||
* mean copying the pointers, and adding another GC root. Then de-rooting
|
||||
* them in the finalizer. Dunno if they're rooted in the first place -
|
||||
* maybe it's only relevant for an exception that goes where it pleases,
|
||||
* and not for the formerly stack-bound use of the error report.
|
||||
*/
|
||||
|
||||
newPrivate->errorReport = newReport;
|
||||
|
||||
return newPrivate;
|
||||
}
|
||||
|
||||
/*
|
||||
* Undo all the damage done by exn_initPrivate.
|
||||
*/
|
||||
static void
|
||||
exn_destroyPrivate(JSContext *cx, JSExnPrivate *privateData)
|
||||
{
|
||||
JS_ASSERT(privateData->message);
|
||||
/* ! what does const do? */
|
||||
JS_free(cx, (void *)privateData->message);
|
||||
|
||||
JS_ASSERT(privateData->errorReport);
|
||||
if (privateData->errorReport->uclinebuf)
|
||||
JS_free(cx, (void *)privateData->errorReport->uclinebuf);
|
||||
|
||||
if (privateData->errorReport->filename)
|
||||
JS_free(cx, (void *)privateData->errorReport->filename);
|
||||
|
||||
JS_free(cx, privateData->errorReport);
|
||||
|
||||
JS_free(cx, privateData);
|
||||
}
|
||||
|
||||
/* Destroy associated data... */
|
||||
static void
|
||||
exn_finalize(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
JSExnPrivate *privateData;
|
||||
|
||||
privateData = (JSExnPrivate *)
|
||||
JSVAL_TO_PRIVATE(OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE));
|
||||
|
||||
if (privateData) {
|
||||
exn_destroyPrivate(cx, privateData);
|
||||
}
|
||||
}
|
||||
|
||||
/* This must be kept in synch with the exceptions array below. */
|
||||
typedef enum JSExnType {
|
||||
JSEXN_NONE = -1,
|
||||
JSEXN_EXCEPTION,
|
||||
JSEXN_ERR,
|
||||
JSEXN_INTERNALERR,
|
||||
JSEXN_SYNTAXERR,
|
||||
JSEXN_REFERENCEERR,
|
||||
JSEXN_CALLERR,
|
||||
JSEXN_TARGETERR,
|
||||
JSEXN_CONSTRUCTORERR,
|
||||
JSEXN_CONVERSIONERR,
|
||||
JSEXN_TOOBJECTERR,
|
||||
JSEXN_TOPRIMITIVEERR,
|
||||
JSEXN_DEFAULTVALUEERR,
|
||||
JSEXN_ARRAYERR,
|
||||
JSEXN_LIMIT
|
||||
} JSExnType;
|
||||
|
||||
#define FLAGS JSCLASS_HAS_PRIVATE
|
||||
|
||||
/* Maybe #define RANDOM_CLASS(name, prototype) 4 here? */
|
||||
struct JSExnSpec {
|
||||
int protoIndex;
|
||||
JSClass theclass;
|
||||
};
|
||||
|
||||
/*
|
||||
* I want to replace all of these with just one class. All we really care
|
||||
* about is the prototypes, and the constructor names.
|
||||
*/
|
||||
static struct JSExnSpec exceptions[] = {
|
||||
{ JSEXN_NONE, /* No proto? */ {
|
||||
"Exception", FLAGS,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, exn_finalize
|
||||
} },
|
||||
{ JSEXN_EXCEPTION, {
|
||||
"Error", FLAGS,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, exn_finalize
|
||||
} },
|
||||
{ JSEXN_ERR, {
|
||||
"InternalError", FLAGS,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, exn_finalize
|
||||
} },
|
||||
{ JSEXN_ERR, {
|
||||
"SyntaxError", FLAGS,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, exn_finalize
|
||||
} },
|
||||
{ JSEXN_ERR, {
|
||||
"ReferenceError", FLAGS,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, exn_finalize
|
||||
} },
|
||||
{ JSEXN_ERR, {
|
||||
"CallError", FLAGS,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, exn_finalize
|
||||
} },
|
||||
{ JSEXN_CALLERR, {
|
||||
"TargetError", FLAGS,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, exn_finalize
|
||||
} },
|
||||
{ JSEXN_ERR, {
|
||||
"ConstructorError", FLAGS,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, exn_finalize
|
||||
} },
|
||||
{ JSEXN_ERR, {
|
||||
"ConversionError", FLAGS,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, exn_finalize
|
||||
} },
|
||||
{ JSEXN_CONVERSIONERR, {
|
||||
"ToObjectError", FLAGS,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, exn_finalize
|
||||
} },
|
||||
{ JSEXN_CONVERSIONERR, {
|
||||
"ToPrimitiveError", FLAGS,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, exn_finalize
|
||||
} },
|
||||
{ JSEXN_CONVERSIONERR, {
|
||||
"DefaultValueError", FLAGS,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, exn_finalize
|
||||
} },
|
||||
{ JSEXN_ERR, {
|
||||
"ArrayError", FLAGS,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, exn_finalize
|
||||
} },
|
||||
{0}
|
||||
};
|
||||
|
||||
static JSBool
|
||||
Exception(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
if (!cx->fp->constructing) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/* gotta null out that private data */
|
||||
OBJ_SET_SLOT(cx, obj, JSSLOT_PRIVATE, JSVAL_NULL);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert to string. Much of this is taken from js.c.
|
||||
*
|
||||
* I should rewrite this to use message, line, file etc. from
|
||||
* javascript-modifiable properties (which might be lazily created
|
||||
* from the encapsulated error report.)
|
||||
*/
|
||||
static JSBool
|
||||
exn_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
JSString *str;
|
||||
JSExnPrivate *privateData;
|
||||
JSErrorReport *report;
|
||||
jsval v;
|
||||
char *name;
|
||||
JSClass *theclass;
|
||||
|
||||
/* Check needed against incompatible target... */
|
||||
|
||||
/* Try to include the exception name in the error message. */
|
||||
theclass = OBJ_GET_CLASS(cx, obj);
|
||||
name = theclass->name;
|
||||
|
||||
v = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
|
||||
|
||||
if (!JSVAL_IS_NULL(v)) {
|
||||
char *msgbuf, *tmp;
|
||||
|
||||
privateData = JSVAL_TO_PRIVATE(v);
|
||||
report = privateData->errorReport;
|
||||
|
||||
msgbuf = JS_smprintf("%s:", name);
|
||||
|
||||
if (report->filename) {
|
||||
tmp = msgbuf;
|
||||
msgbuf = JS_smprintf("%s%s:", tmp, report->filename);
|
||||
JS_free(cx, tmp);
|
||||
}
|
||||
if (report->lineno) {
|
||||
tmp = msgbuf;
|
||||
msgbuf = JS_smprintf("%s%u: ", tmp ? tmp : "", report->lineno);
|
||||
if (tmp)
|
||||
JS_free(cx, tmp);
|
||||
}
|
||||
JS_ASSERT(privateData->message);
|
||||
tmp = msgbuf;
|
||||
msgbuf = JS_smprintf("%s%s", tmp ? tmp : "", privateData->message);
|
||||
if(tmp)
|
||||
JS_free(cx, tmp);
|
||||
|
||||
str = JS_NewStringCopyZ(cx, msgbuf);
|
||||
} else {
|
||||
str = JS_NewStringCopyZ(cx, "some non-engine-thrown exception");
|
||||
}
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSFunctionSpec exception_methods[] = {
|
||||
{js_toString_str, exn_toString, 0},
|
||||
{0}
|
||||
};
|
||||
|
||||
JSObject *
|
||||
js_InitExceptionClasses(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
|
||||
JSObject *protos[JSEXN_LIMIT];
|
||||
int i;
|
||||
|
||||
for (i = 0; exceptions[i].theclass.name != 0; i++) {
|
||||
int protoidx = exceptions[i].protoIndex;
|
||||
protos[i] = JS_InitClass(cx, obj,
|
||||
((protoidx >= 0) ? protos[protoidx] : NULL),
|
||||
&(exceptions[i].theclass),
|
||||
Exception, 1,
|
||||
NULL,
|
||||
exception_methods,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
/* So finalize knows whether to. */
|
||||
OBJ_SET_SLOT(cx, protos[i], JSSLOT_PRIVATE, JSVAL_NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* JS_InitClass magically replaces a null prototype with Object.prototype,
|
||||
* so we need to explicitly assign to the proto slot to get null.
|
||||
*
|
||||
* Temporarily disabled until I do toString for Exception.
|
||||
*/
|
||||
|
||||
/* protos[0]->slots[JSSLOT_PROTO] = JSVAL_NULL; */
|
||||
|
||||
return protos[0];
|
||||
}
|
||||
|
||||
static JSErrorReport *
|
||||
js_GetErrorFromException(JSContext *cx, JSObject *errobj)
|
||||
{
|
||||
JSExnPrivate *privateData;
|
||||
#if 0
|
||||
{
|
||||
JSClass *errobjclass;
|
||||
/* Assert that we have an Exception object */
|
||||
/* This assert does the right thing, but we can't use it yet, because
|
||||
* we're throwing lots of different exception classes. */
|
||||
errobjclass = OBJ_GET_CLASS(cx, errobj);
|
||||
JS_ASSERT(errobjclass == &(exceptions[JSEXN_CALLERR].theclass));
|
||||
}
|
||||
#endif
|
||||
privateData = JSVAL_TO_PRIVATE(OBJ_GET_SLOT(cx, errobj, JSSLOT_PRIVATE));
|
||||
|
||||
/* Still OK to return NULL, tho. */
|
||||
return privateData->errorReport;
|
||||
}
|
||||
|
||||
static JSExnType errorToException[] = {
|
||||
#define MSG_DEF(name, number, count, exception, format) \
|
||||
exception,
|
||||
#include "js.msg"
|
||||
#undef MSG_DEF
|
||||
};
|
||||
|
||||
#if defined ( DEBUG_mccabe ) && defined ( PRINTNAMES )
|
||||
/* For use below... get character strings for error name and exception name */
|
||||
static struct exnname { char *name; char *exception; } errortoexnname[] = {
|
||||
#define MSG_DEF(name, number, count, exception, format) \
|
||||
{#name, #exception},
|
||||
#include "js.msg"
|
||||
#undef MSG_DEF
|
||||
};
|
||||
#endif /* DEBUG */
|
||||
|
||||
JSBool
|
||||
js_ErrorToException(JSContext *cx, JSErrorReport *reportp, const char *message)
|
||||
{
|
||||
JSErrNum errorNumber;
|
||||
JSObject *errobj;
|
||||
JSExnType exn;
|
||||
JSExnPrivate *privateData;
|
||||
|
||||
JS_ASSERT(reportp);
|
||||
errorNumber = reportp->errorNumber;
|
||||
exn = errorToException[errorNumber];
|
||||
JS_ASSERT(exn < JSEXN_LIMIT);
|
||||
|
||||
#if defined( DEBUG_mccabe ) && defined ( PRINTNAMES )
|
||||
/* Print the error name and the associated exception name to stderr */
|
||||
fprintf(stderr, "%s\t%s\n",
|
||||
errortoexnname[errorNumber].name,
|
||||
errortoexnname[errorNumber].exception);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Return false (no exception raised) if no exception is associated
|
||||
* with the given error number.
|
||||
*/
|
||||
if (exn == JSEXN_NONE)
|
||||
return JS_FALSE;
|
||||
|
||||
/*
|
||||
* Should (?) be js_ConstructObject... switching to NewObject
|
||||
* in the speculation that it won't require a frame. DefaultValue trouble.
|
||||
* And it seems to work???? For the record, the trouble was that
|
||||
* cx->fp was null when trying to construct the object...
|
||||
*/
|
||||
errobj = js_NewObject(cx,
|
||||
&(exceptions[exn].theclass),
|
||||
NULL, NULL);
|
||||
|
||||
/*
|
||||
* Construct a new copy of the error report, and store it in the
|
||||
* exception objects' private data. We can't use the error report
|
||||
* handed in, because it's stack-allocated, and may point to transient
|
||||
* data in the JSTokenStream.
|
||||
*/
|
||||
|
||||
/* XXX report failure? */
|
||||
privateData = exn_initPrivate(cx, reportp, message);
|
||||
OBJ_SET_SLOT(cx, errobj, JSSLOT_PRIVATE, PRIVATE_TO_JSVAL(privateData));
|
||||
|
||||
JS_SetPendingException(cx, OBJECT_TO_JSVAL(errobj));
|
||||
reportp->flags |= JSREPORT_EXCEPTION;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
#endif /* JS_HAS_ERROR_EXCEPTIONS */
|
||||
|
||||
47
mozilla/js/src/jsexn.h
Normal file
47
mozilla/js/src/jsexn.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
* JS runtime exception classes.
|
||||
*/
|
||||
|
||||
#ifndef jsexn_h___
|
||||
#define jsexn_h___
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
* Initialize exception object hierarchy.
|
||||
*/
|
||||
extern JSObject *
|
||||
js_InitExceptionClasses(JSContext *cx, JSObject *obj);
|
||||
|
||||
/*
|
||||
* Given a JSErrorReport, check to see if there is an exception associated
|
||||
* with the error number. If there is, then create an appropriate exception
|
||||
* object, set it as the pending exception, and set the JSREPORT_EXCEPTION
|
||||
* flag on the error report. Exception-aware host error reporters will
|
||||
* know to ignore error reports so flagged. Returns JS_TRUE if an associated
|
||||
* exception is found, JS_FALSE if none.
|
||||
*/
|
||||
extern JSBool
|
||||
js_ErrorToException(JSContext *cx, JSErrorReport *reportp, const char *message);
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsexn_h___ */
|
||||
@@ -21,8 +21,9 @@
|
||||
*/
|
||||
#include "jsstddef.h"
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "prlog.h"
|
||||
#include "jstypes.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#include "jsapi.h"
|
||||
#include "jsarray.h"
|
||||
#include "jsatom.h"
|
||||
@@ -53,8 +54,8 @@ enum {
|
||||
|
||||
#undef TEST_BIT
|
||||
#undef SET_BIT
|
||||
#define TEST_BIT(tinyid, bitset) ((bitset) & PR_BIT(-1 - (tinyid)))
|
||||
#define SET_BIT(tinyid, bitset) ((bitset) |= PR_BIT(-1 - (tinyid)))
|
||||
#define TEST_BIT(tinyid, bitset) ((bitset) & JS_BIT(-1 - (tinyid)))
|
||||
#define SET_BIT(tinyid, bitset) ((bitset) |= JS_BIT(-1 - (tinyid)))
|
||||
|
||||
#if JS_HAS_ARGS_OBJECT
|
||||
|
||||
@@ -64,10 +65,10 @@ js_GetArgsObject(JSContext *cx, JSStackFrame *fp)
|
||||
JSObject *argsobj;
|
||||
|
||||
/* Create an arguments object for fp only if it lacks one. */
|
||||
PR_ASSERT(fp->fun);
|
||||
JS_ASSERT(fp->fun);
|
||||
argsobj = fp->argsobj;
|
||||
if (argsobj)
|
||||
return argsobj;
|
||||
return argsobj;
|
||||
|
||||
/* Link the new object to fp so it can get actual argument values. */
|
||||
argsobj = js_NewObject(cx, &js_ArgumentsClass, NULL, NULL);
|
||||
@@ -205,7 +206,7 @@ args_setProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
case ARGS_LENGTH:
|
||||
if (fp) {
|
||||
if (!js_ValueToNumber(cx, *vp, &argc))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
argc = js_DoubleToInteger(argc);
|
||||
if (0 <= argc && argc < fp->argc)
|
||||
fp->argc = (uintN)argc;
|
||||
@@ -264,7 +265,7 @@ js_GetCallObject(JSContext *cx, JSStackFrame *fp, JSObject *parent,
|
||||
JSObject *callobj, *funobj, *obj;
|
||||
|
||||
/* Create a call object for fp only if it lacks one. */
|
||||
PR_ASSERT(fp->fun);
|
||||
JS_ASSERT(fp->fun);
|
||||
callobj = fp->callobj;
|
||||
if (callobj)
|
||||
return callobj;
|
||||
@@ -284,7 +285,7 @@ js_GetCallObject(JSContext *cx, JSStackFrame *fp, JSObject *parent,
|
||||
if (!withobj) {
|
||||
for (obj = fp->scopeChain; obj; obj = parent) {
|
||||
if (OBJ_GET_CLASS(cx, obj) != &js_WithClass)
|
||||
break;
|
||||
break;
|
||||
parent = OBJ_GET_PARENT(cx, obj);
|
||||
if (parent == funobj) {
|
||||
withobj = obj;
|
||||
@@ -373,7 +374,7 @@ call_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
if (fp && !TEST_BIT(slot, fp->overrides)) {
|
||||
JSObject *argsobj = js_GetArgsObject(cx, fp);
|
||||
if (!argsobj)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
*vp = OBJECT_TO_JSVAL(argsobj);
|
||||
}
|
||||
break;
|
||||
@@ -441,7 +442,7 @@ js_GetCallVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
JSStackFrame *fp;
|
||||
|
||||
PR_ASSERT(JSVAL_IS_INT(id));
|
||||
JS_ASSERT(JSVAL_IS_INT(id));
|
||||
fp = JS_GetPrivate(cx, obj);
|
||||
if (fp) {
|
||||
/* XXX no jsint slot commoning here to avoid MSVC1.52 crashes */
|
||||
@@ -456,7 +457,7 @@ js_SetCallVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
JSStackFrame *fp;
|
||||
|
||||
PR_ASSERT(JSVAL_IS_INT(id));
|
||||
JS_ASSERT(JSVAL_IS_INT(id));
|
||||
fp = JS_GetPrivate(cx, obj);
|
||||
if (fp) {
|
||||
/* XXX jsint slot is block-local here to avoid MSVC1.52 crashes */
|
||||
@@ -556,9 +557,9 @@ call_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
|
||||
getter, setter,
|
||||
JSPROP_ENUMERATE | JSPROP_PERMANENT,
|
||||
(JSProperty **)&sprop)) {
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
}
|
||||
PR_ASSERT(sprop);
|
||||
JS_ASSERT(sprop);
|
||||
if (slot < nslots)
|
||||
sprop->id = INT_TO_JSVAL(slot);
|
||||
OBJ_DROP_PROPERTY(cx, obj, (JSProperty *)sprop);
|
||||
@@ -658,7 +659,7 @@ closure_call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
/* Get a call object to link the closure's parent into the scope chain. */
|
||||
fp = cx->fp;
|
||||
closure = JSVAL_TO_OBJECT(argv[-2]);
|
||||
PR_ASSERT(OBJ_GET_CLASS(cx, closure) == &js_ClosureClass);
|
||||
JS_ASSERT(OBJ_GET_CLASS(cx, closure) == &js_ClosureClass);
|
||||
callobj = js_GetCallObject(cx, fp, OBJ_GET_PARENT(cx, closure), NULL);
|
||||
if (!callobj)
|
||||
return JS_FALSE;
|
||||
@@ -789,15 +790,15 @@ fun_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
break;
|
||||
|
||||
case FUN_CALL:
|
||||
if (fp && fp->fun) {
|
||||
if (fp && fp->fun) {
|
||||
JSObject *callobj = js_GetCallObject(cx, fp, NULL, NULL);
|
||||
if (!callobj)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
*vp = OBJECT_TO_JSVAL(callobj);
|
||||
} else {
|
||||
} else {
|
||||
*vp = JSVAL_NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
/* XXX fun[0] and fun.arguments[0] are equivalent. */
|
||||
@@ -832,16 +833,16 @@ fun_enumProperty(JSContext *cx, JSObject *obj)
|
||||
JS_LOCK_OBJ(cx, obj);
|
||||
scope = (JSScope *) obj->map;
|
||||
for (sprop = scope->props; sprop; sprop = sprop->next) {
|
||||
jsval id = sprop->id;
|
||||
if (!JSVAL_IS_INT(id)) {
|
||||
jsval id = sprop->id;
|
||||
if (!JSVAL_IS_INT(id)) {
|
||||
if (id == ATOM_KEY(cx->runtime->atomState.arityAtom) ||
|
||||
id == ATOM_KEY(cx->runtime->atomState.lengthAtom) ||
|
||||
id == ATOM_KEY(cx->runtime->atomState.callerAtom) ||
|
||||
id == ATOM_KEY(cx->runtime->atomState.nameAtom))
|
||||
{
|
||||
sprop->attrs &= ~JSPROP_ENUMERATE;
|
||||
id == ATOM_KEY(cx->runtime->atomState.lengthAtom) ||
|
||||
id == ATOM_KEY(cx->runtime->atomState.callerAtom) ||
|
||||
id == ATOM_KEY(cx->runtime->atomState.nameAtom))
|
||||
{
|
||||
sprop->attrs &= ~JSPROP_ENUMERATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
@@ -877,7 +878,7 @@ fun_setProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
|
||||
/* Set only if unqualified: 'arguments = ...' not 'fun.arguments = ...'. */
|
||||
if (!fp->pc || (js_CodeSpec[*fp->pc].format & JOF_MODEMASK) != JOF_NAME)
|
||||
goto _readonly;
|
||||
goto _readonly;
|
||||
|
||||
/* Get a Call object for fp and set its arguments property to vp. */
|
||||
callobj = js_GetCallObject(cx, fp, NULL, NULL);
|
||||
@@ -891,7 +892,8 @@ fun_setProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
_readonly:
|
||||
if (JSVERSION_IS_ECMA(cx->version))
|
||||
return fun_getProperty(cx, obj, id, vp);
|
||||
JS_ReportError(cx, "%s is read-only", js_arguments_str);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_READ_ONLY,
|
||||
js_arguments_str);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@@ -918,7 +920,7 @@ fun_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
|
||||
|
||||
/* Hide prototype if fun->object is proxying for a Call object. */
|
||||
if (!(flags & JSRESOLVE_QUALIFIED)) {
|
||||
if (cx->fp && cx->fp->fun == fun && !cx->fp->callobj)
|
||||
if (cx->fp && cx->fp->fun == fun && !cx->fp->callobj)
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
@@ -1053,17 +1055,17 @@ fun_xdrObject(JSXDRState *xdr, JSObject **objp)
|
||||
for (sprop = scope->props; sprop; sprop = sprop->next) {
|
||||
if (sprop->getter == js_GetArgument) {
|
||||
type = JSXDR_FUNARG;
|
||||
PR_ASSERT(nargs++ <= fun->nargs);
|
||||
JS_ASSERT(nargs++ <= fun->nargs);
|
||||
} else if (sprop->getter == js_GetLocalVariable) {
|
||||
type = JSXDR_FUNVAR;
|
||||
PR_ASSERT(nvars++ <= fun->nvars);
|
||||
JS_ASSERT(nvars++ <= fun->nvars);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
propname = ATOM_BYTES(sym_atom(sprop->symbols));
|
||||
propid = sprop->id;
|
||||
propid = sprop->id;
|
||||
if (!JS_XDRUint32(xdr, &type) ||
|
||||
!JS_XDRUint32(xdr, (uint32 *)&propid) ||
|
||||
!JS_XDRUint32(xdr, (uint32 *)&propid) ||
|
||||
!JS_XDRCString(xdr, &propname))
|
||||
return JS_FALSE;
|
||||
}
|
||||
@@ -1073,30 +1075,30 @@ fun_xdrObject(JSXDRState *xdr, JSObject **objp)
|
||||
i = fun->nvars + fun->nargs;
|
||||
while (i--) {
|
||||
if (!JS_XDRUint32(xdr, &type) ||
|
||||
!JS_XDRUint32(xdr, (uint32 *)&propid) ||
|
||||
!JS_XDRUint32(xdr, (uint32 *)&propid) ||
|
||||
!JS_XDRCString(xdr, &propname))
|
||||
return JS_FALSE;
|
||||
PR_ASSERT(type == JSXDR_FUNARG || type == JSXDR_FUNVAR);
|
||||
JS_ASSERT(type == JSXDR_FUNARG || type == JSXDR_FUNVAR);
|
||||
if (type == JSXDR_FUNARG) {
|
||||
getter = js_GetArgument;
|
||||
setter = js_SetArgument;
|
||||
PR_ASSERT(nargs++ <= fun->nargs);
|
||||
JS_ASSERT(nargs++ <= fun->nargs);
|
||||
} else if (type == JSXDR_FUNVAR) {
|
||||
getter = js_GetLocalVariable;
|
||||
setter = js_SetLocalVariable;
|
||||
PR_ASSERT(nvars++ <= fun->nvars);
|
||||
JS_ASSERT(nvars++ <= fun->nvars);
|
||||
}
|
||||
atom = js_Atomize(xdr->cx, propname, strlen(propname), 0);
|
||||
atom = js_Atomize(xdr->cx, propname, strlen(propname), 0);
|
||||
if (!atom ||
|
||||
!OBJ_DEFINE_PROPERTY(xdr->cx, fun->object, (jsid)atom,
|
||||
JSVAL_VOID, getter, setter,
|
||||
JSPROP_ENUMERATE | JSPROP_PERMANENT,
|
||||
(JSProperty **)&sprop) ||
|
||||
!sprop){
|
||||
!OBJ_DEFINE_PROPERTY(xdr->cx, fun->object, (jsid)atom,
|
||||
JSVAL_VOID, getter, setter,
|
||||
JSPROP_ENUMERATE | JSPROP_PERMANENT,
|
||||
(JSProperty **)&sprop) ||
|
||||
!sprop){
|
||||
JS_free(xdr->cx, propname);
|
||||
return JS_FALSE;
|
||||
}
|
||||
sprop->id = propid;
|
||||
sprop->id = propid;
|
||||
JS_free(xdr->cx, propname);
|
||||
}
|
||||
}
|
||||
@@ -1112,11 +1114,11 @@ fun_xdrObject(JSXDRState *xdr, JSObject **objp)
|
||||
return JS_FALSE;
|
||||
}
|
||||
*objp = fun->object;
|
||||
if (!OBJ_DEFINE_PROPERTY(xdr->cx, xdr->cx->globalObject,
|
||||
(jsid)fun->atom, OBJECT_TO_JSVAL(*objp),
|
||||
NULL, NULL, JSPROP_ENUMERATE,
|
||||
(JSProperty **)&sprop))
|
||||
return JS_FALSE;
|
||||
if (!OBJ_DEFINE_PROPERTY(xdr->cx, xdr->cx->globalObject,
|
||||
(jsid)fun->atom, OBJECT_TO_JSVAL(*objp),
|
||||
NULL, NULL, JSPROP_ENUMERATE,
|
||||
(JSProperty **)&sprop))
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
@@ -1130,21 +1132,36 @@ fun_xdrObject(JSXDRState *xdr, JSObject **objp)
|
||||
|
||||
#if JS_HAS_INSTANCEOF
|
||||
|
||||
/*
|
||||
* [[HasInstance]] internal method for Function objects - takes the .prototype
|
||||
* property of its target, and walks the prototype chain of v (if v is an
|
||||
* object,) returning true if .prototype is found.
|
||||
*/
|
||||
static JSBool
|
||||
fun_hasInstance(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
|
||||
{
|
||||
jsval pval;
|
||||
JSString *str;
|
||||
|
||||
if (!OBJ_GET_PROPERTY(cx, obj,
|
||||
(jsid)cx->runtime->atomState.classPrototypeAtom,
|
||||
&pval)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
if (JSVAL_IS_PRIMITIVE(pval)) {
|
||||
*bp = JS_FALSE;
|
||||
return JS_TRUE;
|
||||
if (!JSVAL_IS_PRIMITIVE(pval))
|
||||
return js_IsDelegate(cx, JSVAL_TO_OBJECT(pval), v, bp);
|
||||
|
||||
/*
|
||||
* Throw a runtime error if instanceof is called on a function
|
||||
* that has a non-Object as its .prototype value.
|
||||
*/
|
||||
str = js_DecompileValueGenerator(cx, OBJECT_TO_JSVAL(obj), NULL);
|
||||
if (str) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_PROTOTYPE,
|
||||
JS_GetStringBytes(str));
|
||||
}
|
||||
return js_IsDelegate(cx, JSVAL_TO_OBJECT(pval), v, bp);
|
||||
return JS_FALSE;
|
||||
|
||||
}
|
||||
|
||||
#else /* !JS_HAS_INSTANCEOF */
|
||||
@@ -1258,7 +1275,7 @@ fun_apply(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
!JSVAL_IS_OBJECT(argv[1]) ||
|
||||
!(aobj = JSVAL_TO_OBJECT(argv[1])) ||
|
||||
!js_HasLengthProperty(cx, aobj, &length)) {
|
||||
return fun_call(cx, obj, argc, argv, rval);
|
||||
return fun_call(cx, obj, argc, argv, rval);
|
||||
}
|
||||
|
||||
if (!OBJ_DEFAULT_VALUE(cx, obj, JSTYPE_FUNCTION, &argv[-1]))
|
||||
@@ -1345,11 +1362,13 @@ Function(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
JSScopeProperty *sprop;
|
||||
JSString *str, *arg;
|
||||
JSStackFrame *fp;
|
||||
void *mark;
|
||||
JSTokenStream *ts;
|
||||
JSPrincipals *principals;
|
||||
jschar *collected_args, *cp;
|
||||
size_t args_length;
|
||||
JSTokenType tt;
|
||||
JSBool ok;
|
||||
|
||||
if (cx->fp && !cx->fp->constructing) {
|
||||
obj = js_NewObject(cx, &js_FunctionClass, NULL, NULL);
|
||||
@@ -1381,7 +1400,7 @@ Function(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
fun = js_NewFunction(cx, obj, NULL, 0, 0, parent,
|
||||
(JSVERSION_IS_ECMA(cx->version))
|
||||
? cx->runtime->atomState.anonymousAtom
|
||||
: NULL);
|
||||
: NULL);
|
||||
|
||||
if (!fun)
|
||||
return JS_FALSE;
|
||||
@@ -1389,128 +1408,144 @@ Function(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
if ((fp = cx->fp) != NULL && (fp = fp->down) != NULL && fp->script) {
|
||||
filename = fp->script->filename;
|
||||
lineno = js_PCToLineNumber(fp->script, fp->pc);
|
||||
principals = fp->script->principals;
|
||||
principals = fp->script->principals;
|
||||
} else {
|
||||
filename = NULL;
|
||||
lineno = 0;
|
||||
principals = NULL;
|
||||
principals = NULL;
|
||||
}
|
||||
|
||||
n = argc ? argc - 1 : 0;
|
||||
if (n > 0) {
|
||||
/* Collect the function-argument arguments into one string, separated
|
||||
* by commas, then make a tokenstream from that string, and scan it to
|
||||
* get the arguments. We need to throw the full scanner at the
|
||||
* problem, because the argument string can legitimately contain
|
||||
* comments and linefeeds. XXX It might be better to concatenate
|
||||
* everything up into a function definition and pass it to the
|
||||
* compiler, but doing it this way is less of a delta from the old
|
||||
* code. See ECMA 15.3.2.1.
|
||||
*/
|
||||
args_length = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
/* Collect the lengths for all the function-argument arguments. */
|
||||
arg = JSVAL_TO_STRING(argv[i]);
|
||||
args_length += arg->length;
|
||||
}
|
||||
/* Add 1 for each joining comma. */
|
||||
args_length += n - 1;
|
||||
/*
|
||||
* Collect the function-argument arguments into one string, separated
|
||||
* by commas, then make a tokenstream from that string, and scan it to
|
||||
* get the arguments. We need to throw the full scanner at the
|
||||
* problem, because the argument string can legitimately contain
|
||||
* comments and linefeeds. XXX It might be better to concatenate
|
||||
* everything up into a function definition and pass it to the
|
||||
* compiler, but doing it this way is less of a delta from the old
|
||||
* code. See ECMA 15.3.2.1.
|
||||
*/
|
||||
args_length = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
/* Collect the lengths for all the function-argument arguments. */
|
||||
arg = JSVAL_TO_STRING(argv[i]);
|
||||
args_length += arg->length;
|
||||
}
|
||||
/* Add 1 for each joining comma. */
|
||||
args_length += n - 1;
|
||||
|
||||
/* Allocate a string to hold the concatenated arguments, including room
|
||||
* for a terminating 0.
|
||||
*/
|
||||
cp = collected_args = (jschar *) JS_malloc(cx, (args_length + 1) *
|
||||
sizeof(jschar));
|
||||
/* Concatenate the arguments into the new string, separated by commas. */
|
||||
for (i = 0; i < n; i++) {
|
||||
arg = JSVAL_TO_STRING(argv[i]);
|
||||
(void)js_strncpy(cp, arg->chars, arg->length);
|
||||
cp += arg->length;
|
||||
/* Add separating comma or terminating 0. */
|
||||
*(cp++) = (i + 1 < n) ? ',' : 0;
|
||||
}
|
||||
/*
|
||||
* Allocate a string to hold the concatenated arguments, including room
|
||||
* for a terminating 0. Mark cx->tempPool for later release, to free
|
||||
* collected_args and its tokenstream in one swoop.
|
||||
*/
|
||||
mark = JS_ARENA_MARK(&cx->tempPool);
|
||||
JS_ARENA_ALLOCATE(cp, &cx->tempPool, (args_length+1) * sizeof(jschar));
|
||||
if (!cp)
|
||||
return JS_FALSE;
|
||||
collected_args = cp;
|
||||
|
||||
/* Make a tokenstream that reads from the given string. */
|
||||
ts = js_NewTokenStream(cx, collected_args, args_length, filename, lineno,
|
||||
principals);
|
||||
if (!ts) {
|
||||
JS_free(cx, collected_args);
|
||||
return JS_FALSE;
|
||||
}
|
||||
/*
|
||||
* Concatenate the arguments into the new string, separated by commas.
|
||||
*/
|
||||
for (i = 0; i < n; i++) {
|
||||
arg = JSVAL_TO_STRING(argv[i]);
|
||||
(void) js_strncpy(cp, arg->chars, arg->length);
|
||||
cp += arg->length;
|
||||
|
||||
tt = js_GetToken(cx, ts);
|
||||
/* The argument string may be empty or contain no tokens. */
|
||||
if (tt != TOK_EOF) {
|
||||
while (1) {
|
||||
/* Check that it's a name. This also implicitly guards against
|
||||
* TOK_ERROR.
|
||||
*/
|
||||
if (tt != TOK_NAME) {
|
||||
JS_ReportError(cx, "missing formal parameter");
|
||||
goto badargs;
|
||||
}
|
||||
/* Get the atom corresponding to the name from the tokenstream;
|
||||
* we're assured at this point that it's a valid identifier.
|
||||
*/
|
||||
atom = ts->token.t_atom;
|
||||
if (!js_LookupProperty(cx, obj, (jsid)atom, &obj2,
|
||||
(JSProperty **)&sprop)) {
|
||||
goto badargs;
|
||||
}
|
||||
if (sprop && obj2 == obj) {
|
||||
/* Add separating comma or terminating 0. */
|
||||
*cp++ = (i + 1 < n) ? ',' : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Make a tokenstream (allocated from cx->tempPool) that reads from
|
||||
* the given string.
|
||||
*/
|
||||
ts = js_NewTokenStream(cx, collected_args, args_length, filename,
|
||||
lineno, principals);
|
||||
if (!ts) {
|
||||
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
/* The argument string may be empty or contain no tokens. */
|
||||
tt = js_GetToken(cx, ts);
|
||||
if (tt != TOK_EOF) {
|
||||
while (1) {
|
||||
/*
|
||||
* Check that it's a name. This also implicitly guards against
|
||||
* TOK_ERROR, which was already reported.
|
||||
*/
|
||||
if (tt != TOK_NAME)
|
||||
goto bad_formal;
|
||||
|
||||
/*
|
||||
* Get the atom corresponding to the name from the tokenstream;
|
||||
* we're assured at this point that it's a valid identifier.
|
||||
*/
|
||||
atom = ts->token.t_atom;
|
||||
if (!js_LookupProperty(cx, obj, (jsid)atom, &obj2,
|
||||
(JSProperty **)&sprop)) {
|
||||
goto bad_formal;
|
||||
}
|
||||
if (sprop && obj2 == obj) {
|
||||
#ifdef CHECK_ARGUMENT_HIDING
|
||||
PR_ASSERT(sprop->getter == js_GetArgument);
|
||||
OBJ_DROP_PROPERTY(cx, obj2, (JSProperty *)sprop);
|
||||
JS_ReportError(cx, "duplicate formal argument %s",
|
||||
ATOM_BYTES(atom));
|
||||
goto badargs;
|
||||
JS_ASSERT(sprop->getter == js_GetArgument);
|
||||
OBJ_DROP_PROPERTY(cx, obj2, (JSProperty *)sprop);
|
||||
JS_ReportErrorNumber(cx, JSREPORT_WARNING,
|
||||
JSMSG_SAME_FORMAL, ATOM_BYTES(atom));
|
||||
goto bad_formal;
|
||||
#else
|
||||
/* A duplicate parameter name. We create a dummy symbol
|
||||
* entry with property id of the parameter number and set
|
||||
* the id to the name of the parameter.
|
||||
* The decompiler will know to treat this case specially.
|
||||
*/
|
||||
jsid oldArgId = (jsid) sprop->id;
|
||||
OBJ_DROP_PROPERTY(cx, obj2, (JSProperty *)sprop);
|
||||
sprop = NULL;
|
||||
if (!js_DefineProperty(cx, obj, oldArgId, JSVAL_VOID,
|
||||
js_GetArgument, js_SetArgument,
|
||||
JSPROP_ENUMERATE | JSPROP_PERMANENT,
|
||||
(JSProperty **)&sprop)) {
|
||||
goto badargs;
|
||||
}
|
||||
sprop->id = (jsid) atom;
|
||||
/*
|
||||
* A duplicate parameter name. We create a dummy symbol
|
||||
* entry with property id of the parameter number and set
|
||||
* the id to the name of the parameter. See jsopcode.c:
|
||||
* the decompiler knows to treat this case specially.
|
||||
*/
|
||||
jsid oldArgId = (jsid) sprop->id;
|
||||
OBJ_DROP_PROPERTY(cx, obj2, (JSProperty *)sprop);
|
||||
sprop = NULL;
|
||||
if (!js_DefineProperty(cx, obj, oldArgId, JSVAL_VOID,
|
||||
js_GetArgument, js_SetArgument,
|
||||
JSPROP_ENUMERATE | JSPROP_PERMANENT,
|
||||
(JSProperty **)&sprop)) {
|
||||
goto bad_formal;
|
||||
}
|
||||
sprop->id = (jsid) atom;
|
||||
#endif
|
||||
}
|
||||
if (sprop)
|
||||
OBJ_DROP_PROPERTY(cx, obj2, (JSProperty *)sprop);
|
||||
if (!js_DefineProperty(cx, obj, (jsid)atom, JSVAL_VOID,
|
||||
js_GetArgument, js_SetArgument,
|
||||
JSPROP_ENUMERATE | JSPROP_PERMANENT,
|
||||
(JSProperty **)&sprop)) {
|
||||
goto badargs;
|
||||
}
|
||||
PR_ASSERT(sprop);
|
||||
sprop->id = INT_TO_JSVAL(fun->nargs++);
|
||||
OBJ_DROP_PROPERTY(cx, obj, (JSProperty *)sprop);
|
||||
}
|
||||
if (sprop)
|
||||
OBJ_DROP_PROPERTY(cx, obj2, (JSProperty *)sprop);
|
||||
if (!js_DefineProperty(cx, obj, (jsid)atom, JSVAL_VOID,
|
||||
js_GetArgument, js_SetArgument,
|
||||
JSPROP_ENUMERATE | JSPROP_PERMANENT,
|
||||
(JSProperty **)&sprop)) {
|
||||
goto bad_formal;
|
||||
}
|
||||
JS_ASSERT(sprop);
|
||||
sprop->id = INT_TO_JSVAL(fun->nargs++);
|
||||
OBJ_DROP_PROPERTY(cx, obj, (JSProperty *)sprop);
|
||||
|
||||
/* Done with the NAME; get the next token. */
|
||||
tt = js_GetToken(cx, ts);
|
||||
/* Stop if we've reached the end of the string. */
|
||||
if (tt == TOK_EOF)
|
||||
break;
|
||||
/*
|
||||
* Get the next token. Stop on end of stream. Otherwise
|
||||
* insist on a comma, get another name, and iterate.
|
||||
*/
|
||||
tt = js_GetToken(cx, ts);
|
||||
if (tt == TOK_EOF)
|
||||
break;
|
||||
if (tt != TOK_COMMA)
|
||||
goto bad_formal;
|
||||
tt = js_GetToken(cx, ts);
|
||||
}
|
||||
}
|
||||
|
||||
/* If a comma is seen, get the next token. Otherwise, let the
|
||||
* loop catch the error.
|
||||
*/
|
||||
if (tt == TOK_COMMA)
|
||||
tt = js_GetToken(cx, ts);
|
||||
}
|
||||
}
|
||||
/* Clean up. */
|
||||
JS_free(cx, collected_args);
|
||||
if (!js_CloseTokenStream(cx, ts))
|
||||
return JS_FALSE;
|
||||
/* Clean up. */
|
||||
ok = js_CloseTokenStream(cx, ts);
|
||||
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
if (!ok)
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
if (argc) {
|
||||
@@ -1529,25 +1564,39 @@ Function(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
if ((fp = cx->fp) != NULL && (fp = fp->down) != NULL && fp->script) {
|
||||
filename = fp->script->filename;
|
||||
lineno = js_PCToLineNumber(fp->script, fp->pc);
|
||||
principals = fp->script->principals;
|
||||
principals = fp->script->principals;
|
||||
} else {
|
||||
filename = NULL;
|
||||
lineno = 0;
|
||||
principals = NULL;
|
||||
principals = NULL;
|
||||
}
|
||||
ts = js_NewTokenStream(cx, str->chars, str->length, filename, lineno,
|
||||
principals);
|
||||
if (!ts)
|
||||
return JS_FALSE;
|
||||
return js_ParseFunctionBody(cx, ts, fun) &&
|
||||
js_CloseTokenStream(cx, ts);
|
||||
|
||||
badargs:
|
||||
/* Clean up the arguments string and tokenstream if we failed to parse
|
||||
mark = JS_ARENA_MARK(&cx->tempPool);
|
||||
ts = js_NewTokenStream(cx, str->chars, str->length, filename, lineno,
|
||||
principals);
|
||||
if (!ts) {
|
||||
ok = JS_FALSE;
|
||||
} else {
|
||||
ok = js_ParseFunctionBody(cx, ts, fun) &&
|
||||
js_CloseTokenStream(cx, ts);
|
||||
}
|
||||
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
return ok;
|
||||
|
||||
bad_formal:
|
||||
/*
|
||||
* Report "malformed formal parameter" iff no illegal char or similar
|
||||
* scanner error was already reported.
|
||||
*/
|
||||
if (!(ts->flags & TSF_ERROR))
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_FORMAL);
|
||||
|
||||
/*
|
||||
* Clean up the arguments string and tokenstream if we failed to parse
|
||||
* the arguments.
|
||||
*/
|
||||
JS_free(cx, collected_args);
|
||||
(void)js_CloseTokenStream(cx, ts);
|
||||
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@@ -1568,10 +1617,10 @@ js_InitFunctionClass(JSContext *cx, JSObject *obj)
|
||||
goto bad;
|
||||
fun = js_NewFunction(cx, proto, NULL, 0, 0, obj, atom);
|
||||
if (!fun)
|
||||
goto bad;
|
||||
goto bad;
|
||||
fun->script = js_NewScript(cx, 0);
|
||||
if (!fun->script)
|
||||
goto bad;
|
||||
goto bad;
|
||||
return proto;
|
||||
|
||||
bad:
|
||||
@@ -1714,8 +1763,9 @@ js_ReportIsNotFunction(JSContext *cx, jsval *vp, JSBool constructing)
|
||||
if (fp)
|
||||
fp->sp = sp;
|
||||
if (str) {
|
||||
JS_ReportError(cx, "%s is not a %s",
|
||||
JS_GetStringBytes(str),
|
||||
constructing ? "constructor" : "function");
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
constructing ? JSMSG_NOT_CONSTRUCTOR
|
||||
: JSMSG_NOT_FUNCTION,
|
||||
JS_GetStringBytes(str));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "jsprvtd.h"
|
||||
#include "jspubtd.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
struct JSFunction {
|
||||
jsrefcount nrefs; /* number of referencing objects */
|
||||
@@ -42,7 +42,8 @@ struct JSFunction {
|
||||
extern JSClass js_ArgumentsClass;
|
||||
extern JSClass js_CallClass;
|
||||
extern JSClass js_ClosureClass;
|
||||
extern JSClass js_FunctionClass;
|
||||
/* JS_FRIEND_DATA so that JSVAL_IS_FUNCTION is callable from outside */
|
||||
extern JS_FRIEND_DATA(JSClass) js_FunctionClass;
|
||||
|
||||
/*
|
||||
* NB: jsapi.h and jsobj.h must be included before any call to this macro.
|
||||
@@ -100,6 +101,6 @@ js_PutArgsObject(JSContext *cx, JSStackFrame *fp);
|
||||
extern JSBool
|
||||
js_XDRFunction(JSXDRState *xdr, JSObject **objp);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsfun_h___ */
|
||||
|
||||
@@ -21,25 +21,30 @@
|
||||
*
|
||||
* This GC allocates only fixed-sized things big enough to contain two words
|
||||
* (pointers) on any host architecture. It allocates from an arena pool (see
|
||||
* prarena.h). It uses a parallel arena-pool array of flag bytes to hold the
|
||||
* jsarena.h). It uses a parallel arena-pool array of flag bytes to hold the
|
||||
* mark bit, finalizer type index, etc.
|
||||
*
|
||||
* XXX swizzle page to freelist for better locality of reference
|
||||
*/
|
||||
#include "jsstddef.h"
|
||||
#include <stdlib.h> /* for free, called by PR_ARENA_DESTROY */
|
||||
#include <string.h> /* for memset, called by prarena.h macros if DEBUG */
|
||||
#include "prtypes.h"
|
||||
#include <stdlib.h> /* for free, called by JS_ARENA_DESTROY */
|
||||
#include <string.h> /* for memset, called by jsarena.h macros if DEBUG */
|
||||
#include "jstypes.h"
|
||||
#ifndef NSPR20
|
||||
#include "prarena.h"
|
||||
#include "jsarena.h"
|
||||
#else
|
||||
#include "plarena.h"
|
||||
/* Removed by JSIFY: #include "plarena.h"
|
||||
*/
|
||||
#include "jsarena.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "prlog.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#ifndef NSPR20
|
||||
#include "prhash.h"
|
||||
#include "jshash.h"
|
||||
#else
|
||||
#include "plhash.h"
|
||||
/* Removed by JSIFY: #include "JShash.h"
|
||||
*/
|
||||
#include "jshash.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "jsapi.h"
|
||||
#include "jsatom.h"
|
||||
@@ -63,7 +68,7 @@
|
||||
#define GC_FLAGS_SIZE (GC_ARENA_SIZE / sizeof(JSGCThing))
|
||||
#define GC_ROOTS_SIZE 256 /* SWAG, small enough to amortize */
|
||||
|
||||
static PRHashNumber gc_hash_root(const void *key);
|
||||
static JSHashNumber gc_hash_root(const void *key);
|
||||
|
||||
struct JSGCThing {
|
||||
JSGCThing *next;
|
||||
@@ -89,12 +94,12 @@ js_InitGC(JSRuntime *rt, uint32 maxbytes)
|
||||
gc_finalizers[GCX_DOUBLE] = (GCFinalizeOp)js_FinalizeDouble;
|
||||
}
|
||||
|
||||
PR_InitArenaPool(&rt->gcArenaPool, "gc-arena", GC_ARENA_SIZE,
|
||||
JS_InitArenaPool(&rt->gcArenaPool, "gc-arena", GC_ARENA_SIZE,
|
||||
sizeof(JSGCThing));
|
||||
PR_InitArenaPool(&rt->gcFlagsPool, "gc-flags", GC_FLAGS_SIZE,
|
||||
JS_InitArenaPool(&rt->gcFlagsPool, "gc-flags", GC_FLAGS_SIZE,
|
||||
sizeof(uint8));
|
||||
rt->gcRootsHash = PR_NewHashTable(GC_ROOTS_SIZE, gc_hash_root,
|
||||
PR_CompareValues, PR_CompareValues,
|
||||
rt->gcRootsHash = JS_NewHashTable(GC_ROOTS_SIZE, gc_hash_root,
|
||||
JS_CompareValues, JS_CompareValues,
|
||||
NULL, NULL);
|
||||
if (!rt->gcRootsHash)
|
||||
return JS_FALSE;
|
||||
@@ -126,8 +131,8 @@ js_DumpGCStats(JSRuntime *rt, FILE *fp)
|
||||
fprintf(fp, " flags arena corruption: %lu\n", rt->gcStats.badflag);
|
||||
fprintf(fp, " thing arenas freed so far: %lu\n", rt->gcStats.afree);
|
||||
fprintf(fp, " flags arenas freed so far: %lu\n", rt->gcStats.fafree);
|
||||
#ifdef PR_ARENAMETER
|
||||
PR_DumpArenaStats(fp);
|
||||
#ifdef JS_ARENAMETER
|
||||
JS_DumpArenaStats(fp);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@@ -135,16 +140,16 @@ js_DumpGCStats(JSRuntime *rt, FILE *fp)
|
||||
void
|
||||
js_FinishGC(JSRuntime *rt)
|
||||
{
|
||||
#ifdef PR_ARENAMETER
|
||||
PR_DumpArenaStats(stdout);
|
||||
#ifdef JS_ARENAMETER
|
||||
JS_DumpArenaStats(stdout);
|
||||
#endif
|
||||
#ifdef JS_GCMETER
|
||||
js_DumpGCStats(rt, stdout);
|
||||
#endif
|
||||
PR_FinishArenaPool(&rt->gcArenaPool);
|
||||
PR_FinishArenaPool(&rt->gcFlagsPool);
|
||||
PR_ArenaFinish();
|
||||
PR_HashTableDestroy(rt->gcRootsHash);
|
||||
JS_FinishArenaPool(&rt->gcArenaPool);
|
||||
JS_FinishArenaPool(&rt->gcFlagsPool);
|
||||
JS_ArenaFinish();
|
||||
JS_HashTableDestroy(rt->gcRootsHash);
|
||||
rt->gcRootsHash = NULL;
|
||||
rt->gcFreeList = NULL;
|
||||
}
|
||||
@@ -157,7 +162,7 @@ js_AddRoot(JSContext *cx, void *rp, const char *name)
|
||||
|
||||
rt = cx->runtime;
|
||||
JS_LOCK_GC_VOID(rt,
|
||||
ok = (PR_HashTableAdd(rt->gcRootsHash, rp, (void *)name) != NULL));
|
||||
ok = (JS_HashTableAdd(rt->gcRootsHash, rp, (void *)name) != NULL));
|
||||
if (!ok)
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return ok;
|
||||
@@ -169,7 +174,7 @@ js_RemoveRoot(JSContext *cx, void *rp)
|
||||
JSRuntime *rt;
|
||||
|
||||
rt = cx->runtime;
|
||||
JS_LOCK_GC_VOID(rt, PR_HashTableRemove(rt->gcRootsHash, rp));
|
||||
JS_LOCK_GC_VOID(rt, JS_HashTableRemove(rt->gcRootsHash, rp));
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
@@ -198,12 +203,12 @@ retry:
|
||||
METER(rt->gcStats.recycle++);
|
||||
} else {
|
||||
if (rt->gcBytes < rt->gcMaxBytes) {
|
||||
PR_ARENA_ALLOCATE(thing, &rt->gcArenaPool, sizeof(JSGCThing));
|
||||
PR_ARENA_ALLOCATE(flagp, &rt->gcFlagsPool, sizeof(uint8));
|
||||
JS_ARENA_ALLOCATE(thing, &rt->gcArenaPool, sizeof(JSGCThing));
|
||||
JS_ARENA_ALLOCATE(flagp, &rt->gcFlagsPool, sizeof(uint8));
|
||||
}
|
||||
if (!thing || !flagp) {
|
||||
if (thing)
|
||||
PR_ARENA_RELEASE(&rt->gcArenaPool, thing);
|
||||
JS_ARENA_RELEASE(&rt->gcArenaPool, thing);
|
||||
if (!tried_gc) {
|
||||
JS_UNLOCK_GC(rt);
|
||||
js_GC(cx);
|
||||
@@ -235,12 +240,12 @@ retry:
|
||||
static uint8 *
|
||||
gc_find_flags(JSRuntime *rt, void *thing)
|
||||
{
|
||||
pruword index, offset, length;
|
||||
PRArena *a, *fa;
|
||||
jsuword index, offset, length;
|
||||
JSArena *a, *fa;
|
||||
|
||||
index = 0;
|
||||
for (a = rt->gcArenaPool.first.next; a; a = a->next) {
|
||||
offset = PR_UPTRDIFF(thing, a->base);
|
||||
offset = JS_UPTRDIFF(thing, a->base);
|
||||
length = a->avail - a->base;
|
||||
if (offset < length) {
|
||||
index += offset / sizeof(JSGCThing);
|
||||
@@ -301,7 +306,7 @@ js_UnlockGCThing(JSContext *cx, void *thing)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "prprf.h"
|
||||
#include "jsprf.h"
|
||||
|
||||
JS_FRIEND_DATA(FILE *) js_DumpGCHeap;
|
||||
JS_FRIEND_DATA(void *) js_LiveThingToFind;
|
||||
@@ -328,7 +333,7 @@ gc_dump_thing(JSGCThing *thing, uint8 flags, GCMarkNode *prev, FILE *fp)
|
||||
prev = prev->prev;
|
||||
}
|
||||
while (next) {
|
||||
path = PR_sprintf_append(path, "%s.", next->name);
|
||||
path = JS_sprintf_append(path, "%s.", next->name);
|
||||
next = next->next;
|
||||
}
|
||||
if (!path)
|
||||
@@ -358,7 +363,7 @@ static void
|
||||
gc_mark_node(JSRuntime *rt, void *thing, GCMarkNode *prev);
|
||||
|
||||
#define GC_MARK(_rt, _thing, _name, _prev) \
|
||||
PR_BEGIN_MACRO \
|
||||
JS_BEGIN_MACRO \
|
||||
GCMarkNode _node; \
|
||||
_node.thing = _thing; \
|
||||
_node.name = _name; \
|
||||
@@ -366,7 +371,7 @@ gc_mark_node(JSRuntime *rt, void *thing, GCMarkNode *prev);
|
||||
_node.prev = _prev; \
|
||||
if (_prev) ((GCMarkNode *)(_prev))->next = &_node; \
|
||||
gc_mark_node(_rt, _thing, &_node); \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
static void
|
||||
gc_mark(JSRuntime *rt, void *thing)
|
||||
@@ -406,10 +411,10 @@ gc_mark_atom(JSRuntime *rt, JSAtom *atom
|
||||
char name[32];
|
||||
|
||||
if (JSVAL_IS_STRING(key)) {
|
||||
PR_snprintf(name, sizeof name, "'%s'",
|
||||
JS_snprintf(name, sizeof name, "'%s'",
|
||||
JS_GetStringBytes(JSVAL_TO_STRING(key)));
|
||||
} else {
|
||||
PR_snprintf(name, sizeof name, "<%x>", key);
|
||||
JS_snprintf(name, sizeof name, "<%x>", key);
|
||||
}
|
||||
#endif
|
||||
GC_MARK(rt, JSVAL_TO_GCTHING(key), name, prev);
|
||||
@@ -501,7 +506,7 @@ gc_mark(JSRuntime *rt, void *thing)
|
||||
fun = JSVAL_TO_PRIVATE(v);
|
||||
if (fun) {
|
||||
if (fun->atom)
|
||||
GC_MARK_ATOM(rt, fun->atom, prev);
|
||||
GC_MARK_ATOM(rt, fun->atom, prev);
|
||||
if (fun->script)
|
||||
GC_MARK_SCRIPT(rt, fun->script, prev);
|
||||
}
|
||||
@@ -544,7 +549,7 @@ gc_mark(JSRuntime *rt, void *thing)
|
||||
strcpy(name, "__private__");
|
||||
break;
|
||||
default:
|
||||
PR_snprintf(name, sizeof name,
|
||||
JS_snprintf(name, sizeof name,
|
||||
"**UNKNOWN SLOT %ld**",
|
||||
(long)slot);
|
||||
break;
|
||||
@@ -556,10 +561,10 @@ gc_mark(JSRuntime *rt, void *thing)
|
||||
? js_IdToValue(sym_id(sprop->symbols))
|
||||
: sprop->id;
|
||||
if (JSVAL_IS_INT(nval)) {
|
||||
PR_snprintf(name, sizeof name, "%ld",
|
||||
JS_snprintf(name, sizeof name, "%ld",
|
||||
(long)JSVAL_TO_INT(nval));
|
||||
} else if (JSVAL_IS_STRING(nval)) {
|
||||
PR_snprintf(name, sizeof name, "%s",
|
||||
JS_snprintf(name, sizeof name, "%s",
|
||||
JS_GetStringBytes(JSVAL_TO_STRING(nval)));
|
||||
} else {
|
||||
strcpy(name, "**FINALIZED ATOM KEY**");
|
||||
@@ -578,21 +583,31 @@ gc_mark(JSRuntime *rt, void *thing)
|
||||
METER(rt->gcStats.depth--);
|
||||
}
|
||||
|
||||
static PRHashNumber
|
||||
static JSHashNumber
|
||||
gc_hash_root(const void *key)
|
||||
{
|
||||
PRHashNumber num = (PRHashNumber) key; /* help lame MSVC1.5 on Win16 */
|
||||
JSHashNumber num = (JSHashNumber) key; /* help lame MSVC1.5 on Win16 */
|
||||
|
||||
return num >> 2;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(intN)
|
||||
gc_root_marker(PRHashEntry *he, intN i, void *arg)
|
||||
STATIC_DLL_CALLBACK(intN)
|
||||
gc_root_marker(JSHashEntry *he, intN i, void *arg)
|
||||
{
|
||||
void **rp = (void **)he->key;
|
||||
|
||||
if (*rp)
|
||||
if (*rp) {
|
||||
#ifdef DEBUG
|
||||
JSArena *a;
|
||||
JSRuntime *rt = (JSRuntime *)arg;
|
||||
|
||||
for (a = rt->gcArenaPool.first.next; a; a = a->next) {
|
||||
JS_ASSERT(!rp ||
|
||||
(*rp >= (void *)a->base && *rp <= (void *)a->avail));
|
||||
}
|
||||
#endif
|
||||
GC_MARK(arg, *rp, he->value ? he->value : "root", NULL);
|
||||
}
|
||||
return HT_ENUMERATE_NEXT;
|
||||
}
|
||||
|
||||
@@ -604,7 +619,7 @@ js_ForceGC(JSContext *cx)
|
||||
cx->newborn[GCX_DOUBLE] = NULL;
|
||||
cx->runtime->gcPoke = JS_TRUE;
|
||||
js_GC(cx);
|
||||
PR_ArenaFinish();
|
||||
JS_ArenaFinish();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -612,9 +627,9 @@ js_GC(JSContext *cx)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
JSContext *iter, *acx;
|
||||
PRArena *a, *ma, *fa, **ap, **fap;
|
||||
JSArena *a, *ma, *fa, **ap, **fap;
|
||||
jsval v, *vp, *sp;
|
||||
pruword begin, end;
|
||||
jsuword begin, end;
|
||||
JSStackFrame *fp, *chain;
|
||||
void *mark;
|
||||
uint8 flags, *flagp;
|
||||
@@ -622,10 +637,17 @@ js_GC(JSContext *cx)
|
||||
GCFinalizeOp finalizer;
|
||||
JSBool a_all_clear, f_all_clear;
|
||||
|
||||
/*
|
||||
* XXX kludge for pre-ECMAv2 compile-time switch case expr eval, see
|
||||
* jsemit.c:js_EmitTree, under case TOK_SWITCH: (look for XXX).
|
||||
*/
|
||||
if (cx->gcDisabled)
|
||||
return;
|
||||
|
||||
rt = cx->runtime;
|
||||
#ifdef JS_THREADSAFE
|
||||
/* Avoid deadlock. */
|
||||
PR_ASSERT(!JS_IS_RUNTIME_LOCKED(rt));
|
||||
JS_ASSERT(!JS_IS_RUNTIME_LOCKED(rt));
|
||||
#endif
|
||||
|
||||
/* Let the API user decide to defer a GC if it wants to. */
|
||||
@@ -699,38 +721,38 @@ restart:
|
||||
rt->gcNumber++;
|
||||
|
||||
/* Mark phase. */
|
||||
PR_HashTableEnumerateEntries(rt->gcRootsHash, gc_root_marker, rt);
|
||||
JS_HashTableEnumerateEntries(rt->gcRootsHash, gc_root_marker, rt);
|
||||
js_MarkAtomState(&rt->atomState, gc_mark);
|
||||
iter = NULL;
|
||||
while ((acx = js_ContextIterator(rt, &iter)) != NULL) {
|
||||
/*
|
||||
* Iterate frame chain and dormant chains. Temporarily tack current
|
||||
* frame onto the head of the dormant list to ease iteration.
|
||||
*
|
||||
* (NOTE: see comment on this whole 'dormant' thing in js_Execute)
|
||||
*/
|
||||
* frame onto the head of the dormant list to ease iteration.
|
||||
*
|
||||
* (NOTE: see comment on this whole 'dormant' thing in js_Execute)
|
||||
*/
|
||||
chain = acx->fp;
|
||||
if (chain) {
|
||||
PR_ASSERT(!chain->dormantNext);
|
||||
chain->dormantNext = acx->dormantFrameChain;
|
||||
} else {
|
||||
chain = acx->dormantFrameChain;
|
||||
}
|
||||
for (fp=chain; fp; fp = chain = chain->dormantNext) {
|
||||
if (chain) {
|
||||
JS_ASSERT(!chain->dormantNext);
|
||||
chain->dormantNext = acx->dormantFrameChain;
|
||||
} else {
|
||||
chain = acx->dormantFrameChain;
|
||||
}
|
||||
for (fp=chain; fp; fp = chain = chain->dormantNext) {
|
||||
sp = fp->sp;
|
||||
if (sp) {
|
||||
for (a = acx->stackPool.first.next; a; a = a->next) {
|
||||
begin = a->base;
|
||||
end = a->avail;
|
||||
if (PR_UPTRDIFF(sp, begin) < PR_UPTRDIFF(end, begin))
|
||||
end = (pruword)sp;
|
||||
if (JS_UPTRDIFF(sp, begin) < JS_UPTRDIFF(end, begin))
|
||||
end = (jsuword)sp;
|
||||
for (vp = (jsval *)begin; vp < (jsval *)end; vp++) {
|
||||
v = *vp;
|
||||
if (JSVAL_IS_GCTHING(v))
|
||||
GC_MARK(rt, JSVAL_TO_GCTHING(v), "stack", NULL);
|
||||
}
|
||||
if (end == (pruword)sp)
|
||||
break;
|
||||
if (end == (jsuword)sp)
|
||||
break;
|
||||
}
|
||||
}
|
||||
do {
|
||||
@@ -748,18 +770,22 @@ restart:
|
||||
GC_MARK(rt, fp->sharpArray, "sharp array", NULL);
|
||||
} while ((fp = fp->down) != NULL);
|
||||
}
|
||||
/* cleanup temporary link */
|
||||
if (acx->fp)
|
||||
acx->fp->dormantNext = NULL;
|
||||
/* cleanup temporary link */
|
||||
if (acx->fp)
|
||||
acx->fp->dormantNext = NULL;
|
||||
GC_MARK(rt, acx->globalObject, "global object", NULL);
|
||||
GC_MARK(rt, acx->newborn[GCX_OBJECT], "newborn object", NULL);
|
||||
GC_MARK(rt, acx->newborn[GCX_STRING], "newborn string", NULL);
|
||||
GC_MARK(rt, acx->newborn[GCX_DOUBLE], "newborn double", NULL);
|
||||
#if JS_HAS_EXCEPTIONS
|
||||
if (acx->throwing)
|
||||
GC_MARK(rt, acx->exception, "exception", NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Sweep phase. Mark in tempPool for release at label out:. */
|
||||
ma = cx->tempPool.current;
|
||||
mark = PR_ARENA_MARK(&cx->tempPool);
|
||||
mark = JS_ARENA_MARK(&cx->tempPool);
|
||||
js_SweepAtomState(&rt->atomState);
|
||||
fa = rt->gcFlagsPool.first.next;
|
||||
flagp = (uint8 *)fa->base;
|
||||
@@ -768,7 +794,7 @@ restart:
|
||||
thing++) {
|
||||
if (flagp >= (uint8 *)fa->avail) {
|
||||
fa = fa->next;
|
||||
PR_ASSERT(fa);
|
||||
JS_ASSERT(fa);
|
||||
if (!fa) {
|
||||
METER(rt->gcStats.badflag++);
|
||||
goto out;
|
||||
@@ -779,12 +805,12 @@ restart:
|
||||
if (flags & GCF_MARK) {
|
||||
*flagp &= ~GCF_MARK;
|
||||
} else if (!(flags & (GCF_LOCKMASK | GCF_FINAL))) {
|
||||
PR_ARENA_ALLOCATE(final, &cx->tempPool, sizeof(JSGCThing));
|
||||
JS_ARENA_ALLOCATE(final, &cx->tempPool, sizeof(JSGCThing));
|
||||
if (!final)
|
||||
goto out;
|
||||
final->next = thing;
|
||||
final->flagp = flagp;
|
||||
PR_ASSERT(rt->gcBytes >= sizeof(JSGCThing) + sizeof(uint8));
|
||||
JS_ASSERT(rt->gcBytes >= sizeof(JSGCThing) + sizeof(uint8));
|
||||
rt->gcBytes -= sizeof(JSGCThing) + sizeof(uint8);
|
||||
}
|
||||
flagp++;
|
||||
@@ -794,7 +820,7 @@ restart:
|
||||
/* Finalize phase. Don't hold the GC lock while running finalizers! */
|
||||
JS_UNLOCK_GC(rt);
|
||||
for (final = mark; ; final++) {
|
||||
if ((pruword)final >= ma->avail) {
|
||||
if ((jsuword)final >= ma->avail) {
|
||||
ma = ma->next;
|
||||
if (!ma)
|
||||
break;
|
||||
@@ -833,14 +859,14 @@ restart:
|
||||
while ((fa = *fap) != NULL) {
|
||||
/* XXX optimize by unrolling to use word loads */
|
||||
for (flagp = (uint8 *)fa->base; ; flagp++) {
|
||||
PR_ASSERT(a);
|
||||
JS_ASSERT(a);
|
||||
if (!a) {
|
||||
METER(rt->gcStats.badarena++);
|
||||
goto out;
|
||||
}
|
||||
if (thing >= (JSGCThing *)a->avail) {
|
||||
if (a_all_clear) {
|
||||
PR_ARENA_DESTROY(&rt->gcArenaPool, a, ap);
|
||||
JS_ARENA_DESTROY(&rt->gcArenaPool, a, ap);
|
||||
flp = oflp;
|
||||
METER(rt->gcStats.afree++);
|
||||
} else {
|
||||
@@ -866,7 +892,7 @@ restart:
|
||||
thing++;
|
||||
}
|
||||
if (f_all_clear) {
|
||||
PR_ARENA_DESTROY(&rt->gcFlagsPool, fa, fap);
|
||||
JS_ARENA_DESTROY(&rt->gcFlagsPool, fa, fap);
|
||||
METER(rt->gcStats.fafree++);
|
||||
} else {
|
||||
fap = &fa->next;
|
||||
@@ -878,7 +904,7 @@ restart:
|
||||
*flp = NULL;
|
||||
|
||||
out:
|
||||
PR_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
if (rt->gcLevel > 1) {
|
||||
rt->gcLevel = 1;
|
||||
goto restart;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
*/
|
||||
#include "jspubtd.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/* GC thing type indexes. */
|
||||
#define GCX_OBJECT 0 /* JSObject */
|
||||
@@ -33,12 +33,12 @@ PR_BEGIN_EXTERN_C
|
||||
#define GCX_NTYPES 4
|
||||
|
||||
/* GC flag definitions (type index goes in low bits). */
|
||||
#define GCF_TYPEMASK PR_BITMASK(2) /* use low bits for type */
|
||||
#define GCF_MARK PR_BIT(2) /* mark bit */
|
||||
#define GCF_FINAL PR_BIT(3) /* in finalization bit */
|
||||
#define GCF_TYPEMASK JS_BITMASK(2) /* use low bits for type */
|
||||
#define GCF_MARK JS_BIT(2) /* mark bit */
|
||||
#define GCF_FINAL JS_BIT(3) /* in finalization bit */
|
||||
#define GCF_LOCKBIT 4 /* lock bit shift and mask */
|
||||
#define GCF_LOCKMASK (PR_BITMASK(4) << GCF_LOCKBIT)
|
||||
#define GCF_LOCK PR_BIT(GCF_LOCKBIT) /* lock request bit in API */
|
||||
#define GCF_LOCKMASK (JS_BITMASK(4) << GCF_LOCKBIT)
|
||||
#define GCF_LOCK JS_BIT(GCF_LOCKBIT) /* lock request bit in API */
|
||||
|
||||
#if 1
|
||||
/*
|
||||
@@ -105,6 +105,6 @@ js_DumpGCStats(JSRuntime *rt, FILE *fp);
|
||||
|
||||
#endif /* JS_GCMETER */
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsgc_h___ */
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
@@ -17,22 +17,28 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* PL hash table package.
|
||||
* PR hash table package.
|
||||
*/
|
||||
#include "plhash.h"
|
||||
#include "prbit.h"
|
||||
#include "prlog.h"
|
||||
#include "prmem.h"
|
||||
#include "prtypes.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "jstypes.h"
|
||||
#include "jsbit.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#ifndef NSPR20
|
||||
#include "jshash.h"
|
||||
#else
|
||||
/* Removed by JSIFY: #include "JShash.h"
|
||||
*/
|
||||
#include "jshash.h" /* Added by JSIFY */
|
||||
#endif
|
||||
|
||||
/* Compute the number of buckets in ht */
|
||||
#define NBUCKETS(ht) (1 << (PL_HASH_BITS - (ht)->shift))
|
||||
#define NBUCKETS(ht) JS_BIT(PR_HASH_BITS - (ht)->shift)
|
||||
|
||||
/* The smallest table has 16 buckets */
|
||||
#define MINBUCKETSLOG2 4
|
||||
#define MINBUCKETS (1 << MINBUCKETSLOG2)
|
||||
#define MINBUCKETS JS_BIT(MINBUCKETSLOG2)
|
||||
|
||||
/* Compute the maximum entries given n buckets that we will tolerate, ~90% */
|
||||
#define OVERLOADED(n) ((n) - ((n) >> 3))
|
||||
@@ -43,87 +49,71 @@
|
||||
/*
|
||||
** Stubs for default hash allocator ops.
|
||||
*/
|
||||
static void * PR_CALLBACK
|
||||
DefaultAllocTable(void *pool, PRSize size)
|
||||
static void *
|
||||
DefaultAllocTable(void *pool, size_t size)
|
||||
{
|
||||
#if defined(XP_MAC)
|
||||
#pragma unused (pool)
|
||||
#endif
|
||||
|
||||
return PR_MALLOC(size);
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
static void PR_CALLBACK
|
||||
static void
|
||||
DefaultFreeTable(void *pool, void *item)
|
||||
{
|
||||
#if defined(XP_MAC)
|
||||
#pragma unused (pool)
|
||||
#endif
|
||||
|
||||
PR_DELETE(item);
|
||||
free(item);
|
||||
}
|
||||
|
||||
static PLHashEntry * PR_CALLBACK
|
||||
static JSHashEntry *
|
||||
DefaultAllocEntry(void *pool, const void *key)
|
||||
{
|
||||
#if defined(XP_MAC)
|
||||
#pragma unused (pool,key)
|
||||
#endif
|
||||
|
||||
return PR_NEW(PLHashEntry);
|
||||
return malloc(sizeof(JSHashEntry));
|
||||
}
|
||||
|
||||
static void PR_CALLBACK
|
||||
DefaultFreeEntry(void *pool, PLHashEntry *he, PRUintn flag)
|
||||
static void
|
||||
DefaultFreeEntry(void *pool, JSHashEntry *he, uintN flag)
|
||||
{
|
||||
#if defined(XP_MAC)
|
||||
#pragma unused (pool)
|
||||
#endif
|
||||
|
||||
if (flag == HT_FREE_ENTRY)
|
||||
PR_DELETE(he);
|
||||
free(he);
|
||||
}
|
||||
|
||||
static PLHashAllocOps defaultHashAllocOps = {
|
||||
static JSHashAllocOps defaultHashAllocOps = {
|
||||
DefaultAllocTable, DefaultFreeTable,
|
||||
DefaultAllocEntry, DefaultFreeEntry
|
||||
};
|
||||
|
||||
PR_IMPLEMENT(PLHashTable *)
|
||||
PL_NewHashTable(PRUint32 n, PLHashFunction keyHash,
|
||||
PLHashComparator keyCompare, PLHashComparator valueCompare,
|
||||
PLHashAllocOps *allocOps, void *allocPriv)
|
||||
IMPLEMENT(JSHashTable *)
|
||||
JS_NewHashTable(uint32 n, JSHashFunction keyHash,
|
||||
JSHashComparator keyCompare, JSHashComparator valueCompare,
|
||||
JSHashAllocOps *allocOps, void *allocPriv)
|
||||
{
|
||||
PLHashTable *ht;
|
||||
PRUint32 nb;
|
||||
JSHashTable *ht;
|
||||
size_t nb;
|
||||
|
||||
if (n <= MINBUCKETS) {
|
||||
n = MINBUCKETSLOG2;
|
||||
} else {
|
||||
n = PR_CeilingLog2(n);
|
||||
if ((PRInt32)n < 0)
|
||||
return 0;
|
||||
n = JS_CeilingLog2(n);
|
||||
if ((int32)n < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!allocOps) allocOps = &defaultHashAllocOps;
|
||||
|
||||
ht = (PLHashTable*)((*allocOps->allocTable)(allocPriv, sizeof *ht));
|
||||
ht = (*allocOps->allocTable)(allocPriv, sizeof *ht);
|
||||
if (!ht)
|
||||
return 0;
|
||||
return NULL;
|
||||
memset(ht, 0, sizeof *ht);
|
||||
ht->shift = PL_HASH_BITS - n;
|
||||
n = 1 << n;
|
||||
#if defined(XP_PC) && !defined(_WIN32)
|
||||
ht->shift = PR_HASH_BITS - n;
|
||||
n = JS_BIT(n);
|
||||
#if defined(XP_PC) && defined _MSC_VER && _MSC_VER <= 800
|
||||
if (n > 16000) {
|
||||
(*allocOps->freeTable)(allocPriv, ht);
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
#endif /* WIN16 */
|
||||
nb = n * sizeof(PLHashEntry *);
|
||||
ht->buckets = (PLHashEntry**)((*allocOps->allocTable)(allocPriv, nb));
|
||||
nb = n * sizeof(JSHashEntry *);
|
||||
ht->buckets = (*allocOps->allocTable)(allocPriv, nb);
|
||||
if (!ht->buckets) {
|
||||
(*allocOps->freeTable)(allocPriv, ht);
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
memset(ht->buckets, 0, nb);
|
||||
|
||||
@@ -135,12 +125,12 @@ PL_NewHashTable(PRUint32 n, PLHashFunction keyHash,
|
||||
return ht;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(void)
|
||||
PL_HashTableDestroy(PLHashTable *ht)
|
||||
IMPLEMENT(void)
|
||||
JS_HashTableDestroy(JSHashTable *ht)
|
||||
{
|
||||
PRUint32 i, n;
|
||||
PLHashEntry *he, *next;
|
||||
PLHashAllocOps *allocOps = ht->allocOps;
|
||||
uint32 i, n;
|
||||
JSHashEntry *he, *next;
|
||||
JSHashAllocOps *allocOps = ht->allocOps;
|
||||
void *allocPriv = ht->allocPriv;
|
||||
|
||||
n = NBUCKETS(ht);
|
||||
@@ -163,21 +153,19 @@ PL_HashTableDestroy(PLHashTable *ht)
|
||||
/*
|
||||
** Multiplicative hash, from Knuth 6.4.
|
||||
*/
|
||||
#define GOLDEN_RATIO 0x9E3779B9U
|
||||
|
||||
PR_IMPLEMENT(PLHashEntry **)
|
||||
PL_HashTableRawLookup(PLHashTable *ht, PLHashNumber keyHash, const void *key)
|
||||
IMPLEMENT(JSHashEntry **)
|
||||
JS_HashTableRawLookup(JSHashTable *ht, JSHashNumber keyHash, const void *key)
|
||||
{
|
||||
PLHashEntry *he, **hep, **hep0;
|
||||
PLHashNumber h;
|
||||
JSHashEntry *he, **hep, **hep0;
|
||||
JSHashNumber h;
|
||||
|
||||
#ifdef HASHMETER
|
||||
ht->nlookups++;
|
||||
#endif
|
||||
h = keyHash * GOLDEN_RATIO;
|
||||
h = keyHash * PR_GOLDEN_RATIO;
|
||||
h >>= ht->shift;
|
||||
hep = hep0 = &ht->buckets[h];
|
||||
while ((he = *hep) != 0) {
|
||||
while ((he = *hep) != NULL) {
|
||||
if (he->keyHash == keyHash && (*ht->keyCompare)(key, he->key)) {
|
||||
/* Move to front of chain if not already there */
|
||||
if (hep != hep0) {
|
||||
@@ -195,13 +183,13 @@ PL_HashTableRawLookup(PLHashTable *ht, PLHashNumber keyHash, const void *key)
|
||||
return hep;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(PLHashEntry *)
|
||||
PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep,
|
||||
PLHashNumber keyHash, const void *key, void *value)
|
||||
IMPLEMENT(JSHashEntry *)
|
||||
JS_HashTableRawAdd(JSHashTable *ht, JSHashEntry **hep,
|
||||
JSHashNumber keyHash, const void *key, void *value)
|
||||
{
|
||||
PRUint32 i, n;
|
||||
PLHashEntry *he, *next, **oldbuckets;
|
||||
PRUint32 nb;
|
||||
uint32 i, n;
|
||||
JSHashEntry *he, *next, **oldbuckets;
|
||||
size_t nb;
|
||||
|
||||
/* Grow the table if it is overloaded */
|
||||
n = NBUCKETS(ht);
|
||||
@@ -211,25 +199,24 @@ PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep,
|
||||
#endif
|
||||
ht->shift--;
|
||||
oldbuckets = ht->buckets;
|
||||
#if defined(XP_PC) && !defined(_WIN32)
|
||||
#if defined(XP_PC) && defined _MSC_VER && _MSC_VER <= 800
|
||||
if (2 * n > 16000)
|
||||
return 0;
|
||||
return NULL;
|
||||
#endif /* WIN16 */
|
||||
nb = 2 * n * sizeof(PLHashEntry *);
|
||||
ht->buckets = (PLHashEntry**)
|
||||
((*ht->allocOps->allocTable)(ht->allocPriv, nb));
|
||||
nb = 2 * n * sizeof(JSHashEntry *);
|
||||
ht->buckets = (*ht->allocOps->allocTable)(ht->allocPriv, nb);
|
||||
if (!ht->buckets) {
|
||||
ht->buckets = oldbuckets;
|
||||
return 0;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
memset(ht->buckets, 0, nb);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (he = oldbuckets[i]; he; he = next) {
|
||||
next = he->next;
|
||||
hep = PL_HashTableRawLookup(ht, he->keyHash, he->key);
|
||||
PR_ASSERT(*hep == 0);
|
||||
he->next = 0;
|
||||
hep = JS_HashTableRawLookup(ht, he->keyHash, he->key);
|
||||
JS_ASSERT(*hep == NULL);
|
||||
he->next = NULL;
|
||||
*hep = he;
|
||||
}
|
||||
}
|
||||
@@ -237,13 +224,13 @@ PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep,
|
||||
memset(oldbuckets, 0xDB, n * sizeof oldbuckets[0]);
|
||||
#endif
|
||||
(*ht->allocOps->freeTable)(ht->allocPriv, oldbuckets);
|
||||
hep = PL_HashTableRawLookup(ht, keyHash, key);
|
||||
hep = JS_HashTableRawLookup(ht, keyHash, key);
|
||||
}
|
||||
|
||||
/* Make a new key value entry */
|
||||
he = (*ht->allocOps->allocEntry)(ht->allocPriv, key);
|
||||
if (!he)
|
||||
return 0;
|
||||
return NULL;
|
||||
he->keyHash = keyHash;
|
||||
he->key = key;
|
||||
he->value = value;
|
||||
@@ -253,15 +240,15 @@ PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep,
|
||||
return he;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(PLHashEntry *)
|
||||
PL_HashTableAdd(PLHashTable *ht, const void *key, void *value)
|
||||
IMPLEMENT(JSHashEntry *)
|
||||
JS_HashTableAdd(JSHashTable *ht, const void *key, void *value)
|
||||
{
|
||||
PLHashNumber keyHash;
|
||||
PLHashEntry *he, **hep;
|
||||
JSHashNumber keyHash;
|
||||
JSHashEntry *he, **hep;
|
||||
|
||||
keyHash = (*ht->keyHash)(key);
|
||||
hep = PL_HashTableRawLookup(ht, keyHash, key);
|
||||
if ((he = *hep) != 0) {
|
||||
hep = JS_HashTableRawLookup(ht, keyHash, key);
|
||||
if ((he = *hep) != NULL) {
|
||||
/* Hit; see if values match */
|
||||
if ((*ht->valueCompare)(he->value, value)) {
|
||||
/* key,value pair is already present in table */
|
||||
@@ -272,15 +259,15 @@ PL_HashTableAdd(PLHashTable *ht, const void *key, void *value)
|
||||
he->value = value;
|
||||
return he;
|
||||
}
|
||||
return PL_HashTableRawAdd(ht, hep, keyHash, key, value);
|
||||
return JS_HashTableRawAdd(ht, hep, keyHash, key, value);
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(void)
|
||||
PL_HashTableRawRemove(PLHashTable *ht, PLHashEntry **hep, PLHashEntry *he)
|
||||
IMPLEMENT(void)
|
||||
JS_HashTableRawRemove(JSHashTable *ht, JSHashEntry **hep, JSHashEntry *he)
|
||||
{
|
||||
PRUint32 i, n;
|
||||
PLHashEntry *next, **oldbuckets;
|
||||
PRUint32 nb;
|
||||
uint32 i, n;
|
||||
JSHashEntry *next, **oldbuckets;
|
||||
size_t nb;
|
||||
|
||||
*hep = he->next;
|
||||
(*ht->allocOps->freeEntry)(ht->allocPriv, he, HT_FREE_ENTRY);
|
||||
@@ -293,9 +280,8 @@ PL_HashTableRawRemove(PLHashTable *ht, PLHashEntry **hep, PLHashEntry *he)
|
||||
#endif
|
||||
ht->shift++;
|
||||
oldbuckets = ht->buckets;
|
||||
nb = n * sizeof(PLHashEntry*) / 2;
|
||||
ht->buckets = (PLHashEntry**)(
|
||||
(*ht->allocOps->allocTable)(ht->allocPriv, nb));
|
||||
nb = n * sizeof(JSHashEntry*) / 2;
|
||||
ht->buckets = (*ht->allocOps->allocTable)(ht->allocPriv, nb);
|
||||
if (!ht->buckets) {
|
||||
ht->buckets = oldbuckets;
|
||||
return;
|
||||
@@ -305,9 +291,9 @@ PL_HashTableRawRemove(PLHashTable *ht, PLHashEntry **hep, PLHashEntry *he)
|
||||
for (i = 0; i < n; i++) {
|
||||
for (he = oldbuckets[i]; he; he = next) {
|
||||
next = he->next;
|
||||
hep = PL_HashTableRawLookup(ht, he->keyHash, he->key);
|
||||
PR_ASSERT(*hep == 0);
|
||||
he->next = 0;
|
||||
hep = JS_HashTableRawLookup(ht, he->keyHash, he->key);
|
||||
JS_ASSERT(*hep == NULL);
|
||||
he->next = NULL;
|
||||
*hep = he;
|
||||
}
|
||||
}
|
||||
@@ -318,53 +304,53 @@ PL_HashTableRawRemove(PLHashTable *ht, PLHashEntry **hep, PLHashEntry *he)
|
||||
}
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(PRBool)
|
||||
PL_HashTableRemove(PLHashTable *ht, const void *key)
|
||||
IMPLEMENT(JSBool)
|
||||
JS_HashTableRemove(JSHashTable *ht, const void *key)
|
||||
{
|
||||
PLHashNumber keyHash;
|
||||
PLHashEntry *he, **hep;
|
||||
JSHashNumber keyHash;
|
||||
JSHashEntry *he, **hep;
|
||||
|
||||
keyHash = (*ht->keyHash)(key);
|
||||
hep = PL_HashTableRawLookup(ht, keyHash, key);
|
||||
if ((he = *hep) == 0)
|
||||
return PR_FALSE;
|
||||
hep = JS_HashTableRawLookup(ht, keyHash, key);
|
||||
if ((he = *hep) == NULL)
|
||||
return JS_FALSE;
|
||||
|
||||
/* Hit; remove element */
|
||||
PL_HashTableRawRemove(ht, hep, he);
|
||||
return PR_TRUE;
|
||||
JS_HashTableRawRemove(ht, hep, he);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(void *)
|
||||
PL_HashTableLookup(PLHashTable *ht, const void *key)
|
||||
IMPLEMENT(void *)
|
||||
JS_HashTableLookup(JSHashTable *ht, const void *key)
|
||||
{
|
||||
PLHashNumber keyHash;
|
||||
PLHashEntry *he, **hep;
|
||||
JSHashNumber keyHash;
|
||||
JSHashEntry *he, **hep;
|
||||
|
||||
keyHash = (*ht->keyHash)(key);
|
||||
hep = PL_HashTableRawLookup(ht, keyHash, key);
|
||||
if ((he = *hep) != 0) {
|
||||
hep = JS_HashTableRawLookup(ht, keyHash, key);
|
||||
if ((he = *hep) != NULL) {
|
||||
return he->value;
|
||||
}
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
** Iterate over the entries in the hash table calling func for each
|
||||
** entry found. Stop if "f" says to (return value & PR_ENUMERATE_STOP).
|
||||
** entry found. Stop if "f" says to (return value & JS_ENUMERATE_STOP).
|
||||
** Return a count of the number of elements scanned.
|
||||
*/
|
||||
PR_IMPLEMENT(int)
|
||||
PL_HashTableEnumerateEntries(PLHashTable *ht, PLHashEnumerator f, void *arg)
|
||||
IMPLEMENT(int)
|
||||
JS_HashTableEnumerateEntries(JSHashTable *ht, JSHashEnumerator f, void *arg)
|
||||
{
|
||||
PLHashEntry *he, **hep;
|
||||
PRUint32 i, nbuckets;
|
||||
JSHashEntry *he, **hep;
|
||||
uint32 i, nbuckets;
|
||||
int rv, n = 0;
|
||||
PLHashEntry *todo = 0;
|
||||
JSHashEntry *todo = NULL;
|
||||
|
||||
nbuckets = NBUCKETS(ht);
|
||||
for (i = 0; i < nbuckets; i++) {
|
||||
hep = &ht->buckets[i];
|
||||
while ((he = *hep) != 0) {
|
||||
while ((he = *hep) != NULL) {
|
||||
rv = (*f)(he, n, arg);
|
||||
n++;
|
||||
if (rv & (HT_ENUMERATE_REMOVE | HT_ENUMERATE_UNHASH)) {
|
||||
@@ -384,8 +370,8 @@ PL_HashTableEnumerateEntries(PLHashTable *ht, PLHashEnumerator f, void *arg)
|
||||
|
||||
out:
|
||||
hep = &todo;
|
||||
while ((he = *hep) != 0) {
|
||||
PL_HashTableRawRemove(ht, hep, he);
|
||||
while ((he = *hep) != NULL) {
|
||||
JS_HashTableRawRemove(ht, hep, he);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
@@ -394,13 +380,13 @@ out:
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
PR_IMPLEMENT(void)
|
||||
PL_HashTableDumpMeter(PLHashTable *ht, PLHashEnumerator dump, FILE *fp)
|
||||
IMPLEMENT(void)
|
||||
JS_HashTableDumpMeter(JSHashTable *ht, JSHashEnumerator dump, FILE *fp)
|
||||
{
|
||||
double mean, variance;
|
||||
PRUint32 nchains, nbuckets;
|
||||
PRUint32 i, n, maxChain, maxChainLen;
|
||||
PLHashEntry *he;
|
||||
uint32 nchains, nbuckets;
|
||||
uint32 i, n, maxChain, maxChainLen;
|
||||
JSHashEntry *he;
|
||||
|
||||
variance = 0;
|
||||
nchains = 0;
|
||||
@@ -440,38 +426,32 @@ PL_HashTableDumpMeter(PLHashTable *ht, PLHashEnumerator dump, FILE *fp)
|
||||
}
|
||||
#endif /* HASHMETER */
|
||||
|
||||
PR_IMPLEMENT(int)
|
||||
PL_HashTableDump(PLHashTable *ht, PLHashEnumerator dump, FILE *fp)
|
||||
IMPLEMENT(int)
|
||||
JS_HashTableDump(JSHashTable *ht, JSHashEnumerator dump, FILE *fp)
|
||||
{
|
||||
int count;
|
||||
|
||||
count = PL_HashTableEnumerateEntries(ht, dump, fp);
|
||||
count = JS_HashTableEnumerateEntries(ht, dump, fp);
|
||||
#ifdef HASHMETER
|
||||
PL_HashTableDumpMeter(ht, dump, fp);
|
||||
JS_HashTableDumpMeter(ht, dump, fp);
|
||||
#endif
|
||||
return count;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(PLHashNumber)
|
||||
PL_HashString(const void *key)
|
||||
IMPLEMENT(JSHashNumber)
|
||||
JS_HashString(const void *key)
|
||||
{
|
||||
PLHashNumber h;
|
||||
const PRUint8 *s;
|
||||
JSHashNumber h;
|
||||
const unsigned char *s;
|
||||
|
||||
h = 0;
|
||||
for (s = (const PRUint8*)key; *s; s++)
|
||||
for (s = key; *s; s++)
|
||||
h = (h >> 28) ^ (h << 4) ^ *s;
|
||||
return h;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(int)
|
||||
PL_CompareStrings(const void *v1, const void *v2)
|
||||
{
|
||||
return strcmp((const char*)v1, (const char*)v2) == 0;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(int)
|
||||
PL_CompareValues(const void *v1, const void *v2)
|
||||
IMPLEMENT(int)
|
||||
JS_CompareValues(const void *v1, const void *v2)
|
||||
{
|
||||
return v1 == v2;
|
||||
}
|
||||
131
mozilla/js/src/jshash.h
Normal file
131
mozilla/js/src/jshash.h
Normal file
@@ -0,0 +1,131 @@
|
||||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef jshash_h___
|
||||
#define jshash_h___
|
||||
/*
|
||||
* API to portable hash table code.
|
||||
*/
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include "jstypes.h"
|
||||
#include "jscompat.h"
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
typedef uint32 JSHashNumber;
|
||||
typedef struct JSHashEntry JSHashEntry;
|
||||
typedef struct JSHashTable JSHashTable;
|
||||
|
||||
#define PR_HASH_BITS 32
|
||||
#define PR_GOLDEN_RATIO 0x9E3779B9U
|
||||
|
||||
typedef JSHashNumber (*JSHashFunction)(const void *key);
|
||||
typedef intN (*JSHashComparator)(const void *v1, const void *v2);
|
||||
typedef intN (*JSHashEnumerator)(JSHashEntry *he, intN i, void *arg);
|
||||
|
||||
/* Flag bits in JSHashEnumerator's return value */
|
||||
#define HT_ENUMERATE_NEXT 0 /* continue enumerating entries */
|
||||
#define HT_ENUMERATE_STOP 1 /* stop enumerating entries */
|
||||
#define HT_ENUMERATE_REMOVE 2 /* remove and free the current entry */
|
||||
#define HT_ENUMERATE_UNHASH 4 /* just unhash the current entry */
|
||||
|
||||
typedef struct JSHashAllocOps {
|
||||
void * (*allocTable)(void *pool, size_t size);
|
||||
void (*freeTable)(void *pool, void *item);
|
||||
JSHashEntry * (*allocEntry)(void *pool, const void *key);
|
||||
void (*freeEntry)(void *pool, JSHashEntry *he, uintN flag);
|
||||
} JSHashAllocOps;
|
||||
|
||||
#define HT_FREE_VALUE 0 /* just free the entry's value */
|
||||
#define HT_FREE_ENTRY 1 /* free value and entire entry */
|
||||
|
||||
struct JSHashEntry {
|
||||
JSHashEntry *next; /* hash chain linkage */
|
||||
JSHashNumber keyHash; /* key hash function result */
|
||||
const void *key; /* ptr to opaque key */
|
||||
void *value; /* ptr to opaque value */
|
||||
};
|
||||
|
||||
struct JSHashTable {
|
||||
JSHashEntry **buckets; /* vector of hash buckets */
|
||||
uint32 nentries; /* number of entries in table */
|
||||
uint32 shift; /* multiplicative hash shift */
|
||||
JSHashFunction keyHash; /* key hash function */
|
||||
JSHashComparator keyCompare; /* key comparison function */
|
||||
JSHashComparator valueCompare; /* value comparison function */
|
||||
JSHashAllocOps *allocOps; /* allocation operations */
|
||||
void *allocPriv; /* allocation private data */
|
||||
#ifdef HASHMETER
|
||||
uint32 nlookups; /* total number of lookups */
|
||||
uint32 nsteps; /* number of hash chains traversed */
|
||||
uint32 ngrows; /* number of table expansions */
|
||||
uint32 nshrinks; /* number of table contractions */
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
* Create a new hash table.
|
||||
* If allocOps is null, use default allocator ops built on top of malloc().
|
||||
*/
|
||||
EXTERN(JSHashTable *)
|
||||
JS_NewHashTable(uint32 n, JSHashFunction keyHash,
|
||||
JSHashComparator keyCompare, JSHashComparator valueCompare,
|
||||
JSHashAllocOps *allocOps, void *allocPriv);
|
||||
|
||||
EXTERN(void)
|
||||
JS_HashTableDestroy(JSHashTable *ht);
|
||||
|
||||
/* Low level access methods */
|
||||
EXTERN(JSHashEntry **)
|
||||
JS_HashTableRawLookup(JSHashTable *ht, JSHashNumber keyHash, const void *key);
|
||||
|
||||
EXTERN(JSHashEntry *)
|
||||
JS_HashTableRawAdd(JSHashTable *ht, JSHashEntry **hep, JSHashNumber keyHash,
|
||||
const void *key, void *value);
|
||||
|
||||
EXTERN(void)
|
||||
JS_HashTableRawRemove(JSHashTable *ht, JSHashEntry **hep, JSHashEntry *he);
|
||||
|
||||
/* Higher level access methods */
|
||||
EXTERN(JSHashEntry *)
|
||||
JS_HashTableAdd(JSHashTable *ht, const void *key, void *value);
|
||||
|
||||
EXTERN(JSBool)
|
||||
JS_HashTableRemove(JSHashTable *ht, const void *key);
|
||||
|
||||
EXTERN(intN)
|
||||
JS_HashTableEnumerateEntries(JSHashTable *ht, JSHashEnumerator f, void *arg);
|
||||
|
||||
EXTERN(void *)
|
||||
JS_HashTableLookup(JSHashTable *ht, const void *key);
|
||||
|
||||
EXTERN(intN)
|
||||
JS_HashTableDump(JSHashTable *ht, JSHashEnumerator dump, FILE *fp);
|
||||
|
||||
/* General-purpose C string hash function. */
|
||||
EXTERN(JSHashNumber)
|
||||
JS_HashString(const void *key);
|
||||
|
||||
/* Stub function just returns v1 == v2 */
|
||||
IMPLEMENT(intN)
|
||||
JS_CompareValues(const void *v1, const void *v2);
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jshash_h___ */
|
||||
482
mozilla/js/src/jsify.pl
Normal file
482
mozilla/js/src/jsify.pl
Normal file
@@ -0,0 +1,482 @@
|
||||
#!/usr/local/bin/perl
|
||||
|
||||
# This script modifies C code to use the hijacked NSPR routines that are
|
||||
# now baked into the JavaScript engine rather than using the NSPR
|
||||
# routines that they were based on, i.e. types like PRArenaPool are changed
|
||||
# to JSArenaPool.
|
||||
#
|
||||
# This script was used in 9/98 to facilitate the incorporation of some NSPR
|
||||
# code into the JS engine so as to minimize dependency on NSPR.
|
||||
#
|
||||
|
||||
# Command-line: jsify.pl [options] [filename]*
|
||||
#
|
||||
# Options:
|
||||
# -r Reverse direction of transformation, i.e. JS ==> NSPR2
|
||||
# -outdir Directory in which to place output files
|
||||
|
||||
|
||||
# NSPR2 symbols that will be modified to JS symbols, e.g.
|
||||
# PRArena <==> JSArena
|
||||
|
||||
@NSPR_symbols = (
|
||||
"PRArena",
|
||||
"PRArenaPool",
|
||||
"PRArenaStats",
|
||||
"PR_ARENAMETER",
|
||||
"PR_ARENA_",
|
||||
"PR_ARENA_ALIGN",
|
||||
"PR_ARENA_ALLOCATE",
|
||||
"PR_ARENA_CONST_ALIGN_MASK",
|
||||
"PR_ARENA_DEFAULT_ALIGN",
|
||||
"PR_ARENA_DESTROY",
|
||||
"PR_ARENA_GROW",
|
||||
"PR_ARENA_MARK",
|
||||
"PR_ARENA_RELEASE",
|
||||
|
||||
"PR_smprintf",
|
||||
"PR_smprintf_free",
|
||||
"PR_snprintf",
|
||||
"PR_sprintf_append",
|
||||
"PR_sscanf",
|
||||
"PR_sxprintf",
|
||||
"PR_vsmprintf",
|
||||
"PR_vsnprintf",
|
||||
"PR_vsprintf_append",
|
||||
"PR_vsxprintf",
|
||||
|
||||
"PRCList",
|
||||
"PRCListStr",
|
||||
"PRCLists",
|
||||
|
||||
"PRDestroyEventProc",
|
||||
"PREvent",
|
||||
"PREventFunProc",
|
||||
"PREventQueue",
|
||||
"PRHandleEventProc",
|
||||
"PR_PostEvent",
|
||||
"PR_PostSynchronousEvent",
|
||||
"PR_ProcessPendingEvents",
|
||||
"PR_CreateEventQueue",
|
||||
"PR_DequeueEvent",
|
||||
"PR_DestroyEvent",
|
||||
"PR_DestroyEventQueue",
|
||||
"PR_EventAvailable",
|
||||
"PR_EventLoop",
|
||||
"PR_GetEvent",
|
||||
"PR_GetEventOwner",
|
||||
"PR_GetEventQueueMonitor",
|
||||
"PR_GetEventQueueSelectFD",
|
||||
"PR_GetMainEventQueue",
|
||||
"PR_HandleEvent",
|
||||
"PR_InitEvent",
|
||||
"PR_ENTER_EVENT_QUEUE_MONITOR",
|
||||
"PR_EXIT_EVENT_QUEUE_MONITOR",
|
||||
"PR_MapEvents",
|
||||
"PR_RevokeEvents",
|
||||
|
||||
"PRFileDesc",
|
||||
|
||||
"PRHashAllocOps",
|
||||
"PRHashComparator",
|
||||
"PRHashEntry",
|
||||
"PRHashEnumerator",
|
||||
"PRHashFunction",
|
||||
"PRHashNumber",
|
||||
"PRHashTable",
|
||||
"PR_HashString",
|
||||
"PR_HashTableAdd",
|
||||
"PR_HashTableDestroy",
|
||||
"PR_HashTableDump",
|
||||
"PR_HashTableEnumerateEntries",
|
||||
"PR_HashTableLookup",
|
||||
"PR_HashTableRawAdd",
|
||||
"PR_HashTableRawLookup",
|
||||
"PR_HashTableRawRemove",
|
||||
"PR_HashTableRemove",
|
||||
|
||||
"PRBool",
|
||||
"PRFloat64",
|
||||
"PRInt16",
|
||||
"PRInt32",
|
||||
"PRInt64",
|
||||
"PRInt8",
|
||||
"PRIntn",
|
||||
"PRUint16",
|
||||
"PRUint32",
|
||||
"PRUint64",
|
||||
"PRUint8",
|
||||
"PRUintn",
|
||||
"PRPtrDiff",
|
||||
"PRPtrdiff",
|
||||
"PRUptrdiff",
|
||||
"PRUword",
|
||||
"PRWord",
|
||||
"PRPackedBool",
|
||||
"PRSize",
|
||||
"PRStatus",
|
||||
"pruword",
|
||||
"prword",
|
||||
"prword_t",
|
||||
|
||||
"PR_ALIGN_OF_DOUBLE",
|
||||
"PR_ALIGN_OF_FLOAT",
|
||||
"PR_ALIGN_OF_INT",
|
||||
"PR_ALIGN_OF_INT64",
|
||||
"PR_ALIGN_OF_LONG",
|
||||
"PR_ALIGN_OF_POINTER",
|
||||
"PR_ALIGN_OF_SHORT",
|
||||
"PR_ALIGN_OF_WORD",
|
||||
"PR_BITS_PER_BYTE",
|
||||
"PR_BITS_PER_BYTE_LOG2",
|
||||
"PR_BITS_PER_DOUBLE",
|
||||
"PR_BITS_PER_DOUBLE_LOG2",
|
||||
"PR_BITS_PER_FLOAT",
|
||||
"PR_BITS_PER_FLOAT_LOG2",
|
||||
"PR_BITS_PER_INT",
|
||||
"PR_BITS_PER_INT64",
|
||||
"PR_BITS_PER_INT64_LOG2",
|
||||
"PR_BITS_PER_INT_LOG2",
|
||||
"PR_BITS_PER_LONG",
|
||||
"PR_BITS_PER_LONG_LOG2",
|
||||
"PR_BITS_PER_SHORT",
|
||||
"PR_BITS_PER_SHORT_LOG2",
|
||||
"PR_BITS_PER_WORD",
|
||||
"PR_BITS_PER_WORD_LOG2",
|
||||
"PR_BYTES_PER_BYTE",
|
||||
"PR_BYTES_PER_DOUBLE",
|
||||
"PR_BYTES_PER_DWORD",
|
||||
"PR_BYTES_PER_DWORD_LOG2",
|
||||
"PR_BYTES_PER_FLOAT",
|
||||
"PR_BYTES_PER_INT",
|
||||
"PR_BYTES_PER_INT64",
|
||||
"PR_BYTES_PER_LONG",
|
||||
"PR_BYTES_PER_SHORT",
|
||||
"PR_BYTES_PER_WORD",
|
||||
"PR_BYTES_PER_WORD_LOG2",
|
||||
|
||||
"PRSegment",
|
||||
"PRSegmentAccess",
|
||||
"PRStuffFunc",
|
||||
"PRThread",
|
||||
|
||||
"PR_APPEND_LINK",
|
||||
|
||||
"PR_ASSERT",
|
||||
|
||||
"PR_ATOMIC_DWORD_LOAD",
|
||||
"PR_ATOMIC_DWORD_STORE",
|
||||
|
||||
"PR_Abort",
|
||||
|
||||
"PR_ArenaAllocate",
|
||||
"PR_ArenaCountAllocation",
|
||||
"PR_ArenaCountGrowth",
|
||||
"PR_ArenaCountInplaceGrowth",
|
||||
"PR_ArenaCountRelease",
|
||||
"PR_ArenaCountRetract",
|
||||
"PR_ArenaFinish",
|
||||
"PR_ArenaGrow",
|
||||
"PR_ArenaRelease",
|
||||
"PR_CompactArenaPool",
|
||||
"PR_DumpArenaStats",
|
||||
"PR_FinishArenaPool",
|
||||
"PR_FreeArenaPool",
|
||||
"PR_InitArenaPool",
|
||||
|
||||
"PR_Assert",
|
||||
|
||||
"PR_AttachThread",
|
||||
|
||||
"PR_BEGIN_EXTERN_C",
|
||||
"PR_BEGIN_MACRO",
|
||||
|
||||
"PR_BIT",
|
||||
"PR_BITMASK",
|
||||
|
||||
"PR_BUFFER_OVERFLOW_ERROR",
|
||||
|
||||
"PR_CALLBACK",
|
||||
"PR_CALLBACK_DECL",
|
||||
"PR_CALLOC",
|
||||
"PR_CEILING_LOG2",
|
||||
"PR_CLEAR_ARENA",
|
||||
"PR_CLEAR_BIT",
|
||||
"PR_CLEAR_UNUSED",
|
||||
"PR_CLIST_IS_EMPTY",
|
||||
"PR_COUNT_ARENA",
|
||||
"PR_CURRENT_THREAD",
|
||||
|
||||
"PR_GetSegmentAccess",
|
||||
"PR_GetSegmentSize",
|
||||
"PR_GetSegmentVaddr",
|
||||
"PR_GrowSegment",
|
||||
"PR_DestroySegment",
|
||||
"PR_MapSegment",
|
||||
"PR_NewSegment",
|
||||
"PR_Segment",
|
||||
"PR_Seg",
|
||||
"PR_SEGMENT_NONE",
|
||||
"PR_SEGMENT_RDONLY",
|
||||
"PR_SEGMENT_RDWR",
|
||||
|
||||
"PR_Calloc",
|
||||
"PR_CeilingLog2",
|
||||
"PR_CompareStrings",
|
||||
"PR_CompareValues",
|
||||
"PR_DELETE",
|
||||
"PR_END_EXTERN_C",
|
||||
"PR_END_MACRO",
|
||||
"PR_ENUMERATE_STOP",
|
||||
"PR_FAILURE",
|
||||
"PR_FALSE",
|
||||
"PR_FLOOR_LOG2",
|
||||
"PR_FREEIF",
|
||||
"PR_FREE_PATTERN",
|
||||
"PR_FloorLog2",
|
||||
"PR_FormatTime",
|
||||
"PR_Free",
|
||||
|
||||
"PR_GetEnv",
|
||||
"PR_GetError",
|
||||
"PR_INIT_ARENA_POOL",
|
||||
"PR_INIT_CLIST",
|
||||
"PR_INIT_STATIC_CLIST",
|
||||
"PR_INLINE",
|
||||
"PR_INSERT_AFTER",
|
||||
"PR_INSERT_BEFORE",
|
||||
"PR_INSERT_LINK",
|
||||
"PR_INT32",
|
||||
"PR_INTERVAL_NO_TIMEOUT",
|
||||
"PR_INTERVAL_NO_WAIT",
|
||||
"PR_Init",
|
||||
"PR_LIST_HEAD",
|
||||
"PR_LIST_TAIL",
|
||||
"PR_LOG",
|
||||
"PR_LOGGING",
|
||||
"PR_LOG_ALWAYS",
|
||||
"PR_LOG_BEGIN",
|
||||
"PR_LOG_DEBUG",
|
||||
"PR_LOG_DEFINE",
|
||||
"PR_LOG_END",
|
||||
"PR_LOG_ERROR",
|
||||
"PR_LOG_MAX",
|
||||
"PR_LOG_MIN",
|
||||
"PR_LOG_NONE",
|
||||
"PR_LOG_NOTICE",
|
||||
"PR_LOG_TEST",
|
||||
"PR_LOG_WARN",
|
||||
"PR_LOG_WARNING",
|
||||
"PR_LogFlush",
|
||||
"PR_LogPrint",
|
||||
"PR_MALLOC",
|
||||
"PR_MAX",
|
||||
"PR_MD_calloc",
|
||||
"PR_MD_free",
|
||||
"PR_MD_malloc",
|
||||
"PR_MD_realloc",
|
||||
"PR_MIN",
|
||||
"PR_Malloc",
|
||||
"PR_NEW",
|
||||
"PR_NEWZAP",
|
||||
"PR_NEXT_LINK",
|
||||
"PR_NOT_REACHED",
|
||||
"PR_NewCondVar",
|
||||
"PR_NewHashTable",
|
||||
"PR_NewLogModule",
|
||||
"PR_PREV_LINK",
|
||||
"PR_PUBLIC_API",
|
||||
"PR_PUBLIC_DATA",
|
||||
"PR_RANGE_ERROR",
|
||||
"PR_REALLOC",
|
||||
"PR_REMOVE_AND_INIT_LINK",
|
||||
"PR_REMOVE_LINK",
|
||||
"PR_ROUNDUP",
|
||||
"PR_Realloc",
|
||||
|
||||
"PR_SET_BIT",
|
||||
"PR_STATIC_CALLBACK",
|
||||
"PR_SUCCESS",
|
||||
"PR_SetError",
|
||||
"PR_SetLogBuffering",
|
||||
"PR_SetLogFile",
|
||||
|
||||
"PR_TEST_BIT",
|
||||
"PR_TRUE",
|
||||
"PR_UINT32",
|
||||
"PR_UPTRDIFF",
|
||||
|
||||
"prarena_h___",
|
||||
"prbit_h___",
|
||||
"prclist_h___",
|
||||
"prdtoa_h___",
|
||||
"prlog_h___",
|
||||
"prlong_h___",
|
||||
"prmacos_h___",
|
||||
"prmem_h___",
|
||||
"prprf_h___",
|
||||
"prtypes_h___",
|
||||
|
||||
"prarena",
|
||||
"prbit",
|
||||
"prbitmap_t",
|
||||
"prclist",
|
||||
"prcpucfg",
|
||||
"prdtoa",
|
||||
"prhash",
|
||||
"plhash",
|
||||
"prlong",
|
||||
"prmacos",
|
||||
"prmem",
|
||||
"prosdep",
|
||||
"protypes",
|
||||
"prprf",
|
||||
"prtypes"
|
||||
);
|
||||
|
||||
while ($ARGV[0] =~ /^-/) {
|
||||
if ($ARGV[0] eq "-r") {
|
||||
shift;
|
||||
$reverse_conversion = 1;
|
||||
} elsif ($ARGV[0] eq "-outdir") {
|
||||
shift;
|
||||
$outdir = shift;
|
||||
}
|
||||
}
|
||||
|
||||
# Given an NSPR symbol compute the JS equivalent or
|
||||
# vice-versa
|
||||
sub subst {
|
||||
local ($replacement);
|
||||
local ($sym) = @_;
|
||||
|
||||
$replacement = substr($sym,0,2) eq "pr" ? "js" : "JS";
|
||||
$replacement .= substr($sym, 2);
|
||||
return $replacement;
|
||||
}
|
||||
|
||||
# Build the regular expression that will convert between the NSPR
|
||||
# types and the JS types
|
||||
if ($reverse_conversion) {
|
||||
die "Not implemented yet";
|
||||
} else {
|
||||
foreach $sym (@NSPR_symbols) {
|
||||
$regexp .= $sym . "|"
|
||||
}
|
||||
# Get rid of the last "!"
|
||||
chop $regexp;
|
||||
|
||||
# Replace PR* with JS* and replace pr* with js*
|
||||
$regexp = 's/(^|\\W)(' . $regexp . ')/$1 . &subst($2)/eg';
|
||||
# print $regexp;
|
||||
}
|
||||
|
||||
# Pre-compile a little subroutine to perform the regexp substitution
|
||||
# between NSPR types and JS types
|
||||
eval('sub convert_from_NSPR {($line) = @_; $line =~ ' . $regexp . ';}');
|
||||
|
||||
sub convert_mallocs {
|
||||
($line) = @_;
|
||||
$line =~ s/PR_MALLOC/malloc/g;
|
||||
$line =~ s/PR_REALLOC/realloc/g;
|
||||
$line =~ s/PR_FREE/free/g;
|
||||
return $line;
|
||||
}
|
||||
|
||||
sub convert_includes {
|
||||
($line) = @_;
|
||||
if ($line !~ /include/) {
|
||||
return $line;
|
||||
}
|
||||
|
||||
if ($line =~ /prlog\.h/) {
|
||||
chop $line;
|
||||
$line = "/* Removed by JSIFY: $line */\n";
|
||||
$line .= '#include "jsutil.h"'. " /* Added by JSIFY */\n";
|
||||
} elsif ($line =~ /plhash\.h/) {
|
||||
$line = "/* Removed by JSIFY: $line */\n";
|
||||
$line .= '#include "jshash.h"'. " /* Added by JSIFY */\n";
|
||||
} elsif ($line =~ /plarena\.h/) {
|
||||
$line = "/* Removed by JSIFY: $line */\n";
|
||||
$line .= '#include "jsarena.h"'. " /* Added by JSIFY */\n";
|
||||
} elsif ($line =~ /prmem\.h/) {
|
||||
$line = "/* Removed by JSIFY: $line */\n";
|
||||
} elsif ($line =~ /jsmsg\.def/) {
|
||||
$line = '#include "js.msg"' . "\n";
|
||||
} elsif ($line =~ /shellmsg\.def/) {
|
||||
$line = '#include "jsshell.msg"' . "\n";
|
||||
} elsif ($line =~ /jsopcode\.def/) {
|
||||
$line = '#include "jsopcode.tbl"' . "\n";
|
||||
}
|
||||
return $line;
|
||||
}
|
||||
|
||||
sub convert_declarations {
|
||||
($line) = @_;
|
||||
$line =~ s/PR_EXTERN/EXTERN/g;
|
||||
$line =~ s/PR_IMPLEMENT/IMPLEMENT/g;
|
||||
$line =~ s/PR_CALLBACK/DLL_CALLBACK/g;
|
||||
$line =~ s/PR_STATIC_CALLBACK/STATIC_DLL_CALLBACK/g;
|
||||
$line =~ s/PR_IMPORT/IMPORT/g;
|
||||
$line =~ s/PR_PUBLIC_API/PUBLIC_API/g;
|
||||
$line =~ s/PR_PUBLIC_DATA/PUBLIC_DATA/g;
|
||||
return $line;
|
||||
}
|
||||
|
||||
sub convert_long_long_macros {
|
||||
($line) = @_;
|
||||
$line =~ s/\b(LL_)/JSLL_/g;
|
||||
return $line;
|
||||
}
|
||||
|
||||
sub convert_asserts {
|
||||
($line) = @_;
|
||||
$line =~ s/\bPR_ASSERT/JS_ASSERT/g;
|
||||
return $line;
|
||||
}
|
||||
|
||||
while ($#ARGV >= 0) {
|
||||
$infile = shift;
|
||||
|
||||
# Change filename, e.g. prtime.h to jsprtime.h, except for legacy
|
||||
# files that start with 'prmj', like prmjtime.h.
|
||||
$outfile = $infile;
|
||||
if ($infile !~ /^prmj/) {
|
||||
$outfile =~ s/^pr/js/;
|
||||
$outfile =~ s/^pl/js/;
|
||||
}
|
||||
|
||||
if ($outdir) {
|
||||
$outfile = $outdir . '/' . $outfile;
|
||||
}
|
||||
|
||||
if ($infile eq $outfile) {
|
||||
die "Error: refuse to overwrite $outfile, use -outdir option."
|
||||
}
|
||||
die "Can't open $infile" if !open(INFILE, "<$infile");
|
||||
die "Can't open $outfile for writing" if !open(OUTFILE, ">$outfile");
|
||||
|
||||
while (<INFILE>) {
|
||||
$line = $_;
|
||||
|
||||
#Get rid of #include "prlog.h"
|
||||
&convert_includes($line);
|
||||
|
||||
# Rename PR_EXTERN, PR_IMPORT, etc.
|
||||
&convert_declarations($line);
|
||||
|
||||
# Convert from PR_MALLOC to malloc, etc.
|
||||
&convert_mallocs($line);
|
||||
|
||||
# Convert from PR_ASSERT to JS_ASSERT
|
||||
# &convert_asserts($line);
|
||||
|
||||
# Convert from, e.g. PRArena to JSPRArena
|
||||
&convert_from_NSPR($line);
|
||||
|
||||
# Change LL_* macros to JSLL_*
|
||||
&convert_long_long_macros($line);
|
||||
|
||||
print OUTFILE $line;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -48,8 +48,6 @@ struct JSStackFrame {
|
||||
JSPackedBool constructing; /* true if called via new operator */
|
||||
uint8 overrides; /* bit-set of overridden Call properties */
|
||||
JSPackedBool debugging; /* true if for JS_EvaluateInStackFrame */
|
||||
JSPackedBool throwing; /* is there a pending exception? */
|
||||
jsval exception; /* most-recently-thrown exceptin */
|
||||
JSStackFrame *dormantNext; /* next dormant frame chain */
|
||||
};
|
||||
|
||||
@@ -57,23 +55,23 @@ struct JSStackFrame {
|
||||
* Property cache for quickened get/set property opcodes.
|
||||
*/
|
||||
#define PROPERTY_CACHE_LOG2 10
|
||||
#define PROPERTY_CACHE_SIZE PR_BIT(PROPERTY_CACHE_LOG2)
|
||||
#define PROPERTY_CACHE_MASK PR_BITMASK(PROPERTY_CACHE_LOG2)
|
||||
#define PROPERTY_CACHE_SIZE JS_BIT(PROPERTY_CACHE_LOG2)
|
||||
#define PROPERTY_CACHE_MASK JS_BITMASK(PROPERTY_CACHE_LOG2)
|
||||
|
||||
#define PROPERTY_CACHE_HASH(obj, id) \
|
||||
((((pruword)(obj) >> JSVAL_TAGBITS) ^ (pruword)(id)) & PROPERTY_CACHE_MASK)
|
||||
((((jsuword)(obj) >> JSVAL_TAGBITS) ^ (jsuword)(id)) & PROPERTY_CACHE_MASK)
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
|
||||
#if HAVE_ATOMIC_DWORD_ACCESS
|
||||
|
||||
#define PCE_LOAD(cache, pce, entry) PR_ATOMIC_DWORD_LOAD(pce, entry)
|
||||
#define PCE_STORE(cache, pce, entry) PR_ATOMIC_DWORD_STORE(pce, entry)
|
||||
#define PCE_LOAD(cache, pce, entry) JS_ATOMIC_DWORD_LOAD(pce, entry)
|
||||
#define PCE_STORE(cache, pce, entry) JS_ATOMIC_DWORD_STORE(pce, entry)
|
||||
|
||||
#else /* !HAVE_ATOMIC_DWORD_ACCESS */
|
||||
|
||||
#define PCE_LOAD(cache, pce, entry) \
|
||||
PR_BEGIN_MACRO \
|
||||
JS_BEGIN_MACRO \
|
||||
uint32 _prefills; \
|
||||
uint32 _fills = (cache)->fills; \
|
||||
do { \
|
||||
@@ -81,16 +79,16 @@ struct JSStackFrame {
|
||||
_prefills = _fills; \
|
||||
(entry) = *(pce); \
|
||||
} while ((_fills = (cache)->fills) != _prefills); \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
#define PCE_STORE(cache, pce, entry) \
|
||||
PR_BEGIN_MACRO \
|
||||
JS_BEGIN_MACRO \
|
||||
do { \
|
||||
/* Store until no racing collider stores half or all of pce. */ \
|
||||
*(pce) = (entry); \
|
||||
} while (PCE_OBJECT(*pce) != PCE_OBJECT(entry) || \
|
||||
PCE_PROPERTY(*pce) != PCE_PROPERTY(entry)); \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
#endif /* !HAVE_ATOMIC_DWORD_ACCESS */
|
||||
|
||||
@@ -126,12 +124,12 @@ typedef struct JSPropertyCache {
|
||||
} JSPropertyCache;
|
||||
|
||||
/* Property-not-found lookup results are cached using this invalid pointer. */
|
||||
#define PROP_NOT_FOUND(obj,id) ((JSProperty *) ((prword)(id) | 1))
|
||||
#define PROP_NOT_FOUND_ID(prop) ((jsid) ((prword)(prop) & ~1))
|
||||
#define PROP_FOUND(prop) ((prop) && ((prword)(prop) & 1) == 0)
|
||||
#define PROP_NOT_FOUND(obj,id) ((JSProperty *) ((jsword)(id) | 1))
|
||||
#define PROP_NOT_FOUND_ID(prop) ((jsid) ((jsword)(prop) & ~1))
|
||||
#define PROP_FOUND(prop) ((prop) && ((jsword)(prop) & 1) == 0)
|
||||
|
||||
#define PROPERTY_CACHE_FILL(cx, cache, obj, id, prop) \
|
||||
PR_BEGIN_MACRO \
|
||||
JS_BEGIN_MACRO \
|
||||
uintN _hashIndex = (uintN)PROPERTY_CACHE_HASH(obj, id); \
|
||||
JSPropertyCache *_cache = (cache); \
|
||||
JSPropertyCacheEntry *_pce = &_cache->table[_hashIndex]; \
|
||||
@@ -146,10 +144,10 @@ typedef struct JSPropertyCache {
|
||||
_cache->empty = JS_FALSE; \
|
||||
_cache->fills++; \
|
||||
PCE_STORE(_cache, _pce, _entry); \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
#define PROPERTY_CACHE_TEST(cache, obj, id, prop) \
|
||||
PR_BEGIN_MACRO \
|
||||
JS_BEGIN_MACRO \
|
||||
uintN _hashIndex = (uintN)PROPERTY_CACHE_HASH(obj, id); \
|
||||
JSPropertyCache *_cache = (cache); \
|
||||
JSPropertyCacheEntry *_pce = &_cache->table[_hashIndex]; \
|
||||
@@ -159,7 +157,7 @@ typedef struct JSPropertyCache {
|
||||
_pce_prop = PCE_PROPERTY(_entry); \
|
||||
_cache->tests++; \
|
||||
if (_pce_prop && \
|
||||
(((prword)_pce_prop & 1) \
|
||||
(((jsword)_pce_prop & 1) \
|
||||
? PROP_NOT_FOUND_ID(_pce_prop) \
|
||||
: sym_id(((JSScopeProperty *)_pce_prop)->symbols)) == id && \
|
||||
PCE_OBJECT(_entry) == obj) { \
|
||||
@@ -168,7 +166,7 @@ typedef struct JSPropertyCache {
|
||||
_cache->misses++; \
|
||||
prop = NULL; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
extern void
|
||||
js_FlushPropertyCache(JSContext *cx);
|
||||
|
||||
@@ -25,7 +25,9 @@
|
||||
#include <stdlib.h>
|
||||
#include "jspubtd.h"
|
||||
#include "prthread.h"
|
||||
#include "prlog.h"
|
||||
#include "pratom.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#include "jscntxt.h"
|
||||
#include "jsscope.h"
|
||||
#include "jspubtd.h"
|
||||
@@ -45,18 +47,18 @@ js_UnlockGlobal()
|
||||
PR_Unlock(_global_lock);
|
||||
}
|
||||
|
||||
#define AtomicRead(W) (W)
|
||||
#define ReadWord(W) (W)
|
||||
#define AtomicAddBody(P,I)\
|
||||
prword n;\
|
||||
jsword n;\
|
||||
do {\
|
||||
n = AtomicRead(*(P));\
|
||||
n = ReadWord(*(P));\
|
||||
} while (!js_CompareAndSwap(P, n, n + I));
|
||||
|
||||
#if defined(_WIN32) && !defined(NSPR_LOCK)
|
||||
#pragma warning( disable : 4035 )
|
||||
|
||||
PR_INLINE int
|
||||
js_CompareAndSwap(prword *w, prword ov, prword nv)
|
||||
JS_INLINE int
|
||||
js_CompareAndSwap(jsword *w, jsword ov, jsword nv)
|
||||
{
|
||||
__asm {
|
||||
mov eax,ov
|
||||
@@ -71,17 +73,17 @@ js_CompareAndSwap(prword *w, prword ov, prword nv)
|
||||
#elif defined(SOLARIS) && !defined(NSPR_LOCK)
|
||||
|
||||
#ifndef ULTRA_SPARC
|
||||
PR_INLINE prword
|
||||
js_AtomicRead(prword *p)
|
||||
JS_INLINE jsword
|
||||
js_ReadWord(jsword *p)
|
||||
{
|
||||
prword n;
|
||||
jsword n;
|
||||
while ((n = *p) == -1)
|
||||
;
|
||||
return n;
|
||||
}
|
||||
|
||||
#undef AtomicRead
|
||||
#define AtomicRead(W) js_AtomicRead(&(W))
|
||||
#undef ReadWord
|
||||
#define ReadWord(W) js_ReadWord(&(W))
|
||||
|
||||
static PRLock *_counter_lock;
|
||||
#define UsingCounterLock 1
|
||||
@@ -94,14 +96,15 @@ static PRLock *_counter_lock;
|
||||
|
||||
#endif /* !ULTRA_SPARC */
|
||||
|
||||
PR_INLINE int
|
||||
js_CompareAndSwap(prword *w, prword ov, prword nv)
|
||||
JS_INLINE int
|
||||
js_CompareAndSwap(jsword *w, jsword ov, jsword nv)
|
||||
{
|
||||
#if defined(__GNUC__)
|
||||
unsigned int res;
|
||||
#ifndef ULTRA_SPARC
|
||||
PR_ASSERT(nv >= 0);
|
||||
JS_ASSERT(nv >= 0);
|
||||
asm volatile ("
|
||||
stbar
|
||||
swap [%1],%4
|
||||
1: tst %4
|
||||
bneg,a 1b
|
||||
@@ -117,8 +120,9 @@ mov 0,%0
|
||||
: "=r" (res)
|
||||
: "r" (w), "r" (ov), "r" (nv), "r" (-1));
|
||||
#else /* ULTRA_SPARC */
|
||||
PR_ASSERT(ov != nv);
|
||||
JS_ASSERT(ov != nv);
|
||||
asm volatile ("
|
||||
stbar
|
||||
cas [%1],%2,%3
|
||||
cmp %2,%3
|
||||
be,a 1f
|
||||
@@ -130,36 +134,23 @@ mov 0,%0
|
||||
#endif /* ULTRA_SPARC */
|
||||
return (int)res;
|
||||
#else /* !__GNUC__ */
|
||||
extern int compare_and_swap(prword*,prword,prword);
|
||||
extern int compare_and_swap(jsword*,jsword,jsword);
|
||||
#ifndef ULTRA_SPARC
|
||||
PR_ASSERT(nv >= 0);
|
||||
JS_ASSERT(nv >= 0);
|
||||
#else
|
||||
PR_ASSERT(ov != nv);
|
||||
JS_ASSERT(ov != nv);
|
||||
#endif
|
||||
return compare_and_swap(w,ov,nv);
|
||||
#endif
|
||||
}
|
||||
|
||||
#elif defined(AIX) && !defined(NSPR_LOCK)
|
||||
#include <sys/atomic_op.h>
|
||||
|
||||
PR_INLINE int
|
||||
js_CompareAndSwap(prword *w, prword ov, prword nv)
|
||||
JS_INLINE int
|
||||
js_CompareAndSwap(jsword *w, jsword ov, jsword nv)
|
||||
{
|
||||
/*
|
||||
int i = -1;
|
||||
|
||||
lwarx reg,0,w
|
||||
cmpw reg,ov
|
||||
bne no
|
||||
stwcx. nv,0,w
|
||||
beq yes
|
||||
no:
|
||||
li res,0
|
||||
yes:
|
||||
*/
|
||||
extern int compare_and_swap(int*,int*,int);
|
||||
|
||||
return compare_and_swap(w,&ov,nv);
|
||||
return !_check_lock(w,ov,nv);
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -176,8 +167,8 @@ static PRLock *_counter_lock;
|
||||
static PRLock *_compare_and_swap_lock;
|
||||
#define UsingCompareAndSwapLock 1
|
||||
|
||||
PR_INLINE int
|
||||
js_CompareAndSwap(prword *w, prword ov, prword nv)
|
||||
JS_INLINE int
|
||||
js_CompareAndSwap(jsword *w, jsword ov, jsword nv)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
@@ -192,13 +183,23 @@ js_CompareAndSwap(prword *w, prword ov, prword nv)
|
||||
|
||||
#endif /* arch-tests */
|
||||
|
||||
PR_INLINE void
|
||||
js_AtomicAdd(prword *p, prword i)
|
||||
JS_INLINE void
|
||||
js_AtomicAdd(jsword *p, jsword i)
|
||||
{
|
||||
AtomicAddBody(p,i);
|
||||
}
|
||||
|
||||
prword
|
||||
JS_INLINE jsword
|
||||
js_AtomicSet(jsword *p, jsword n)
|
||||
{
|
||||
jsword o;
|
||||
do {
|
||||
o = ReadWord(*p);
|
||||
} while (!js_CompareAndSwap(p,o,n));
|
||||
return o;
|
||||
}
|
||||
|
||||
jsword
|
||||
js_CurrentThreadId()
|
||||
{
|
||||
return CurrentThreadId();
|
||||
@@ -222,26 +223,26 @@ js_DestroyLock(JSThinLock *p)
|
||||
p->owner = 0xdeadbeef;
|
||||
JS_DESTROY_LOCK(((JSLock*)p->fat));
|
||||
#else
|
||||
PR_ASSERT(p->owner == 0);
|
||||
PR_ASSERT(p->fat == NULL);
|
||||
JS_ASSERT(p->owner == 0);
|
||||
JS_ASSERT(p->fat == NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void js_Dequeue(JSThinLock *);
|
||||
|
||||
PR_INLINE jsval
|
||||
JS_INLINE jsval
|
||||
js_GetSlotWhileLocked(JSContext *cx, JSObject *obj, uint32 slot)
|
||||
{
|
||||
jsval v;
|
||||
#ifndef NSPR_LOCK
|
||||
JSScope *scp = (JSScope *)obj->map;
|
||||
JSThinLock *p = &scp->lock;
|
||||
prword me = cx->thread;
|
||||
jsword me = cx->thread;
|
||||
#endif
|
||||
|
||||
PR_ASSERT(obj->slots && slot < obj->map->freeslot);
|
||||
JS_ASSERT(obj->slots && slot < obj->map->freeslot);
|
||||
#ifndef NSPR_LOCK
|
||||
PR_ASSERT(me == CurrentThreadId());
|
||||
JS_ASSERT(me == CurrentThreadId());
|
||||
if (js_CompareAndSwap(&p->owner, 0, me)) {
|
||||
if (scp == (JSScope *)obj->map) {
|
||||
v = obj->slots[slot];
|
||||
@@ -254,7 +255,7 @@ js_GetSlotWhileLocked(JSContext *cx, JSObject *obj, uint32 slot)
|
||||
if (!js_CompareAndSwap(&p->owner, me, 0))
|
||||
js_Dequeue(p);
|
||||
}
|
||||
else if (Thin_RemoveWait(AtomicRead(p->owner)) == me) {
|
||||
else if (Thin_RemoveWait(ReadWord(p->owner)) == me) {
|
||||
return obj->slots[slot];
|
||||
}
|
||||
#endif
|
||||
@@ -264,18 +265,18 @@ js_GetSlotWhileLocked(JSContext *cx, JSObject *obj, uint32 slot)
|
||||
return v;
|
||||
}
|
||||
|
||||
PR_INLINE void
|
||||
JS_INLINE void
|
||||
js_SetSlotWhileLocked(JSContext *cx, JSObject *obj, uint32 slot, jsval v)
|
||||
{
|
||||
#ifndef NSPR_LOCK
|
||||
JSScope *scp = (JSScope *)obj->map;
|
||||
JSThinLock *p = &scp->lock;
|
||||
prword me = cx->thread;
|
||||
jsword me = cx->thread;
|
||||
#endif
|
||||
|
||||
PR_ASSERT(obj->slots && slot < obj->map->freeslot);
|
||||
JS_ASSERT(obj->slots && slot < obj->map->freeslot);
|
||||
#ifndef NSPR_LOCK
|
||||
PR_ASSERT(me == CurrentThreadId());
|
||||
JS_ASSERT(me == CurrentThreadId());
|
||||
if (js_CompareAndSwap(&p->owner, 0, me)) {
|
||||
if (scp == (JSScope *)obj->map) {
|
||||
obj->slots[slot] = v;
|
||||
@@ -288,7 +289,7 @@ js_SetSlotWhileLocked(JSContext *cx, JSObject *obj, uint32 slot, jsval v)
|
||||
if (!js_CompareAndSwap(&p->owner, me, 0))
|
||||
js_Dequeue(p);
|
||||
}
|
||||
else if (Thin_RemoveWait(AtomicRead(p->owner)) == me) {
|
||||
else if (Thin_RemoveWait(ReadWord(p->owner)) == me) {
|
||||
obj->slots[slot] = v;
|
||||
return;
|
||||
}
|
||||
@@ -302,12 +303,12 @@ static JSFatLock *
|
||||
mallocFatlock()
|
||||
{
|
||||
JSFatLock *fl = (JSFatLock *)malloc(sizeof(JSFatLock)); /* for now */
|
||||
PR_ASSERT(fl);
|
||||
JS_ASSERT(fl);
|
||||
fl->susp = 0;
|
||||
fl->next = NULL;
|
||||
fl->prev = NULL;
|
||||
fl->slock = PR_NewLock();
|
||||
fl->svar = PR_NewCondVar(fl->slock);
|
||||
fl->svar = JS_NewCondVar(fl->slock);
|
||||
return fl;
|
||||
}
|
||||
|
||||
@@ -322,20 +323,24 @@ freeFatlock(JSFatLock *fl)
|
||||
static int
|
||||
js_SuspendThread(JSThinLock *p)
|
||||
{
|
||||
JSFatLock *fl = p->fat;
|
||||
PRStatus stat;
|
||||
JSFatLock *fl;
|
||||
JSStatus stat;
|
||||
|
||||
while ((fl = (JSFatLock*)js_AtomicSet((jsword*)&p->fat,1)) == (JSFatLock*)1) /* busy wait */
|
||||
PR_Sleep(JS_INTERVAL_NO_WAIT);
|
||||
if (fl == NULL)
|
||||
return 1;
|
||||
PR_Lock(fl->slock);
|
||||
js_AtomicSet((jsword*)&p->fat,(jsword)fl);
|
||||
fl->susp++;
|
||||
if (p->fat == NULL || fl->susp<1) {
|
||||
PR_Unlock(fl->slock);
|
||||
return 1;
|
||||
if (fl->susp < 1) {
|
||||
PR_Unlock(fl->slock);
|
||||
return 1;
|
||||
}
|
||||
stat = PR_WaitCondVar(fl->svar,PR_INTERVAL_NO_TIMEOUT);
|
||||
if (stat == PR_FAILURE) {
|
||||
fl->susp--;
|
||||
return 0;
|
||||
stat = PR_WaitCondVar(fl->svar,JS_INTERVAL_NO_TIMEOUT);
|
||||
if (stat == JS_FAILURE) {
|
||||
fl->susp--;
|
||||
return 0;
|
||||
}
|
||||
PR_Unlock(fl->slock);
|
||||
return 1;
|
||||
@@ -344,12 +349,22 @@ js_SuspendThread(JSThinLock *p)
|
||||
static void
|
||||
js_ResumeThread(JSThinLock *p)
|
||||
{
|
||||
JSFatLock *fl = p->fat;
|
||||
PRStatus stat;
|
||||
JSFatLock *fl;
|
||||
JSStatus stat;
|
||||
|
||||
while ((fl = (JSFatLock*)js_AtomicSet((jsword*)&p->fat,1)) == (JSFatLock*)1)
|
||||
PR_Sleep(JS_INTERVAL_NO_WAIT);
|
||||
if (fl == NULL)
|
||||
return;
|
||||
PR_Lock(fl->slock);
|
||||
js_AtomicSet((jsword*)&p->fat,(jsword)fl);
|
||||
fl->susp--;
|
||||
if (fl->susp < 0) {
|
||||
PR_Unlock(fl->slock);
|
||||
return;
|
||||
}
|
||||
stat = PR_NotifyCondVar(fl->svar);
|
||||
PR_ASSERT(stat != PR_FAILURE);
|
||||
JS_ASSERT(stat != JS_FAILURE);
|
||||
PR_Unlock(fl->slock);
|
||||
}
|
||||
|
||||
@@ -360,7 +375,7 @@ listOfFatlocks(int l)
|
||||
JSFatLock *m0;
|
||||
int i;
|
||||
|
||||
PR_ASSERT(l>0);
|
||||
JS_ASSERT(l>0);
|
||||
m0 = m = mallocFatlock();
|
||||
for (i=1; i<l; i++) {
|
||||
m->next = mallocFatlock();
|
||||
@@ -374,8 +389,8 @@ deleteListOfFatlocks(JSFatLock *m)
|
||||
{
|
||||
JSFatLock *m0;
|
||||
for (; m; m=m0) {
|
||||
m0 = m->next;
|
||||
freeFatlock(m);
|
||||
m0 = m->next;
|
||||
freeFatlock(m);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,6 +401,7 @@ allocateFatlock()
|
||||
{
|
||||
JSFatLock *m;
|
||||
|
||||
js_LockGlobal();
|
||||
if (_fl_table.free == NULL) {
|
||||
#ifdef DEBUG
|
||||
printf("Ran out of fat locks!\n");
|
||||
@@ -401,6 +417,7 @@ allocateFatlock()
|
||||
if (_fl_table.taken != NULL)
|
||||
_fl_table.taken->prev = m;
|
||||
_fl_table.taken = m;
|
||||
js_UnlockGlobal();
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -409,6 +426,7 @@ deallocateFatlock(JSFatLock *m)
|
||||
{
|
||||
if (m == NULL)
|
||||
return;
|
||||
js_LockGlobal();
|
||||
if (m->prev != NULL)
|
||||
m->prev->next = m->next;
|
||||
if (m->next != NULL)
|
||||
@@ -417,6 +435,7 @@ deallocateFatlock(JSFatLock *m)
|
||||
_fl_table.taken = m->next;
|
||||
m->next = _fl_table.free;
|
||||
_fl_table.free = m;
|
||||
js_UnlockGlobal();
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(int)
|
||||
@@ -429,14 +448,14 @@ js_SetupLocks(int l)
|
||||
if (_global_lock)
|
||||
return 1;
|
||||
_global_lock = PR_NewLock();
|
||||
PR_ASSERT(_global_lock);
|
||||
JS_ASSERT(_global_lock);
|
||||
#ifdef UsingCounterLock
|
||||
_counter_lock = PR_NewLock();
|
||||
PR_ASSERT(_counter_lock);
|
||||
JS_ASSERT(_counter_lock);
|
||||
#endif
|
||||
#ifdef UsingCompareAndSwapLock
|
||||
_compare_and_swap_lock = PR_NewLock();
|
||||
PR_ASSERT(_compare_and_swap_lock);
|
||||
JS_ASSERT(_compare_and_swap_lock);
|
||||
#endif
|
||||
_fl_table.free = listOfFatlocks(l);
|
||||
_fl_table.taken = NULL;
|
||||
@@ -468,7 +487,7 @@ JS_PUBLIC_API(void)
|
||||
js_InitContextForLocking(JSContext *cx)
|
||||
{
|
||||
cx->thread = CurrentThreadId();
|
||||
PR_ASSERT(Thin_GetWait(cx->thread) == 0);
|
||||
JS_ASSERT(Thin_GetWait(cx->thread) == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -496,20 +515,27 @@ js_InitContextForLocking(JSContext *cx)
|
||||
int
|
||||
emptyFatlock(JSThinLock *p)
|
||||
{
|
||||
JSFatLock *fl = p->fat;
|
||||
int i;
|
||||
JSFatLock *fl;
|
||||
int i;
|
||||
PRLock* lck;
|
||||
|
||||
if (fl == NULL)
|
||||
while ((fl = (JSFatLock*)js_AtomicSet((jsword*)&p->fat,1)) == (JSFatLock*)1)
|
||||
PR_Sleep(JS_INTERVAL_NO_WAIT);
|
||||
if (fl == NULL) {
|
||||
js_AtomicSet((jsword*)&p->fat,(jsword)fl);
|
||||
return 1;
|
||||
PR_Lock(fl->slock);
|
||||
i = fl->susp;
|
||||
if (i < 1) {
|
||||
}
|
||||
lck = fl->slock;
|
||||
PR_Lock(lck);
|
||||
i = fl->susp;
|
||||
if (i < 1) {
|
||||
fl->susp = -1;
|
||||
deallocateFatlock(fl);
|
||||
p->fat = NULL;
|
||||
}
|
||||
PR_Unlock(fl->slock);
|
||||
return i < 1;
|
||||
fl = NULL;
|
||||
}
|
||||
js_AtomicSet((jsword*)&p->fat,(jsword)fl);
|
||||
PR_Unlock(lck);
|
||||
return i < 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -534,103 +560,92 @@ emptyFatlock(JSThinLock *p)
|
||||
uncontended (no one is waiting because the wait bit is not set).
|
||||
|
||||
Furthermore, when enqueueing (after the compare-and-swap has failed
|
||||
to lock the object), a global spin lock is grabbed which serializes
|
||||
changes to an object, and prevents the race condition when a lock is
|
||||
released simultaneously with a thread suspending on it (these two
|
||||
operations are serialized using the spin lock). Thus, a thread is
|
||||
enqueued if the lock is still held by another thread, and otherwise
|
||||
the lock is grabbed using compare-and-swap. When dequeueing, the
|
||||
lock is released, and one of the threads suspended on the lock is
|
||||
notified. If other threads still are waiting, the wait bit is kept, and if
|
||||
not, the fat lock is deallocated (in emptyFatlock()).
|
||||
to lock the object), p->fat is used to serialize the different
|
||||
accesses to the fat lock. The four function thus synchronized are
|
||||
js_Enqueue, emptyFatLock, js_SuspendThread, and js_ResumeThread.
|
||||
|
||||
When dequeueing, the lock is released, and one of the threads
|
||||
suspended on the lock is notified. If other threads still are
|
||||
waiting, the wait bit is kept (in js_Enqueue), and if not, the fat
|
||||
lock is deallocated (in emptyFatlock()).
|
||||
|
||||
p->fat is set to 1 by enqueue and emptyFatlock to signal that the pointer
|
||||
is being accessed.
|
||||
|
||||
*/
|
||||
|
||||
static void
|
||||
js_Enqueue(JSThinLock *p, prword me)
|
||||
js_Enqueue(JSThinLock *p, jsword me)
|
||||
{
|
||||
prword o, n;
|
||||
jsword o, n;
|
||||
|
||||
js_LockGlobal();
|
||||
while (1) {
|
||||
o = AtomicRead(p->owner);
|
||||
while (1) {
|
||||
o = ReadWord(p->owner);
|
||||
n = Thin_SetWait(o);
|
||||
if (o != 0 && js_CompareAndSwap(&p->owner,o,n)) {
|
||||
if (p->fat == NULL)
|
||||
p->fat = allocateFatlock();
|
||||
#ifdef DEBUG_
|
||||
printf("Going to suspend (%x) on {%x,%x}\n",me,p,p->fat);
|
||||
#endif
|
||||
js_UnlockGlobal();
|
||||
js_SuspendThread(p);
|
||||
js_LockGlobal();
|
||||
#ifdef DEBUG_
|
||||
printf("Waking up (%x) on {%x,%x,%d}\n",me,p,p->fat,(p->fat ? p->fat->susp : 42));
|
||||
#endif
|
||||
if (emptyFatlock(p))
|
||||
JSFatLock* fl;
|
||||
while ((fl = (JSFatLock*)js_AtomicSet((jsword*)&p->fat,1)) == (JSFatLock*)1)
|
||||
PR_Sleep(JS_INTERVAL_NO_WAIT);
|
||||
if (fl == NULL)
|
||||
fl = allocateFatlock();
|
||||
js_AtomicSet((jsword*)&p->fat,(jsword)fl);
|
||||
js_SuspendThread(p);
|
||||
if (emptyFatlock(p))
|
||||
me = Thin_RemoveWait(me);
|
||||
else
|
||||
else
|
||||
me = Thin_SetWait(me);
|
||||
}
|
||||
else if (js_CompareAndSwap(&p->owner,0,me)) {
|
||||
js_UnlockGlobal();
|
||||
return;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
js_Dequeue(JSThinLock *p)
|
||||
{
|
||||
js_LockGlobal();
|
||||
PR_ASSERT(Thin_GetWait(AtomicRead(p->owner)));
|
||||
p->owner = 0; /* release it */
|
||||
PR_ASSERT(p->fat);
|
||||
js_ResumeThread(p);
|
||||
js_UnlockGlobal();
|
||||
int o = ReadWord(p->owner);
|
||||
JS_ASSERT(Thin_GetWait(o));
|
||||
if (!js_CompareAndSwap(&p->owner,o,0)) /* release it */
|
||||
JS_ASSERT(0);
|
||||
js_ResumeThread(p);
|
||||
}
|
||||
|
||||
PR_INLINE void
|
||||
js_Lock(JSThinLock *p, prword me)
|
||||
JS_INLINE void
|
||||
js_Lock(JSThinLock *p, jsword me)
|
||||
{
|
||||
#ifdef DEBUG_
|
||||
printf("\nT%x about to lock %x\n",me,p);
|
||||
#endif
|
||||
PR_ASSERT(me == CurrentThreadId());
|
||||
JS_ASSERT(me == CurrentThreadId());
|
||||
if (js_CompareAndSwap(&p->owner, 0, me))
|
||||
return;
|
||||
if (Thin_RemoveWait(AtomicRead(p->owner)) != me)
|
||||
js_Enqueue(p, me);
|
||||
return;
|
||||
if (Thin_RemoveWait(ReadWord(p->owner)) != me)
|
||||
js_Enqueue(p, me);
|
||||
#ifdef DEBUG
|
||||
else
|
||||
PR_ASSERT(0);
|
||||
JS_ASSERT(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
PR_INLINE void
|
||||
js_Unlock(JSThinLock *p, prword me)
|
||||
JS_INLINE void
|
||||
js_Unlock(JSThinLock *p, jsword me)
|
||||
{
|
||||
#ifdef DEBUG_
|
||||
printf("\nT%x about to unlock %p\n",me,p);
|
||||
#endif
|
||||
PR_ASSERT(me == CurrentThreadId());
|
||||
JS_ASSERT(me == CurrentThreadId());
|
||||
if (js_CompareAndSwap(&p->owner, me, 0))
|
||||
return;
|
||||
if (Thin_RemoveWait(AtomicRead(p->owner)) == me)
|
||||
if (Thin_RemoveWait(ReadWord(p->owner)) == me)
|
||||
js_Dequeue(p);
|
||||
#ifdef DEBUG
|
||||
else
|
||||
PR_ASSERT(0);
|
||||
JS_ASSERT(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
js_LockRuntime(JSRuntime *rt)
|
||||
{
|
||||
prword me = CurrentThreadId();
|
||||
jsword me = CurrentThreadId();
|
||||
JSThinLock *p;
|
||||
|
||||
PR_ASSERT(Thin_RemoveWait(AtomicRead(rt->rtLock.owner)) != me);
|
||||
JS_ASSERT(Thin_RemoveWait(ReadWord(rt->rtLock.owner)) != me);
|
||||
p = &rt->rtLock;
|
||||
JS_LOCK0(p,me);
|
||||
}
|
||||
@@ -638,26 +653,26 @@ js_LockRuntime(JSRuntime *rt)
|
||||
void
|
||||
js_UnlockRuntime(JSRuntime *rt)
|
||||
{
|
||||
prword me = CurrentThreadId();
|
||||
jsword me = CurrentThreadId();
|
||||
JSThinLock *p;
|
||||
|
||||
PR_ASSERT(Thin_RemoveWait(AtomicRead(rt->rtLock.owner)) == me);
|
||||
JS_ASSERT(Thin_RemoveWait(ReadWord(rt->rtLock.owner)) == me);
|
||||
p = &rt->rtLock;
|
||||
JS_UNLOCK0(p,me);
|
||||
}
|
||||
|
||||
PR_INLINE void
|
||||
js_LockScope1(JSContext *cx, JSScope *scope, prword me)
|
||||
JS_INLINE void
|
||||
js_LockScope1(JSContext *cx, JSScope *scope, jsword me)
|
||||
{
|
||||
JSThinLock *p;
|
||||
|
||||
if (Thin_RemoveWait(AtomicRead(scope->lock.owner)) == me) {
|
||||
PR_ASSERT(scope->count > 0);
|
||||
if (Thin_RemoveWait(ReadWord(scope->lock.owner)) == me) {
|
||||
JS_ASSERT(scope->count > 0);
|
||||
scope->count++;
|
||||
} else {
|
||||
p = &scope->lock;
|
||||
JS_LOCK0(p,me);
|
||||
PR_ASSERT(scope->count == 0);
|
||||
JS_ASSERT(scope->count == 0);
|
||||
scope->count = 1;
|
||||
}
|
||||
}
|
||||
@@ -665,19 +680,19 @@ js_LockScope1(JSContext *cx, JSScope *scope, prword me)
|
||||
void
|
||||
js_LockScope(JSContext *cx, JSScope *scope)
|
||||
{
|
||||
PR_ASSERT(cx->thread == CurrentThreadId());
|
||||
JS_ASSERT(cx->thread == CurrentThreadId());
|
||||
js_LockScope1(cx,scope,cx->thread);
|
||||
}
|
||||
|
||||
void
|
||||
js_UnlockScope(JSContext *cx, JSScope *scope)
|
||||
{
|
||||
prword me = cx->thread;
|
||||
jsword me = cx->thread;
|
||||
JSThinLock *p;
|
||||
|
||||
PR_ASSERT(scope->count > 0);
|
||||
if (Thin_RemoveWait(AtomicRead(scope->lock.owner)) != me) {
|
||||
PR_ASSERT(0);
|
||||
JS_ASSERT(scope->count > 0);
|
||||
if (Thin_RemoveWait(ReadWord(scope->lock.owner)) != me) {
|
||||
JS_ASSERT(0);
|
||||
return;
|
||||
}
|
||||
if (--scope->count == 0) {
|
||||
@@ -689,10 +704,10 @@ js_UnlockScope(JSContext *cx, JSScope *scope)
|
||||
void
|
||||
js_TransferScopeLock(JSContext *cx, JSScope *oldscope, JSScope *newscope)
|
||||
{
|
||||
prword me;
|
||||
jsword me;
|
||||
JSThinLock *p;
|
||||
|
||||
PR_ASSERT(JS_IS_SCOPE_LOCKED(newscope));
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(newscope));
|
||||
/*
|
||||
* If the last reference to oldscope went away, newscope needs no lock
|
||||
* state update.
|
||||
@@ -700,7 +715,7 @@ js_TransferScopeLock(JSContext *cx, JSScope *oldscope, JSScope *newscope)
|
||||
if (!oldscope) {
|
||||
return;
|
||||
}
|
||||
PR_ASSERT(JS_IS_SCOPE_LOCKED(oldscope));
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(oldscope));
|
||||
/*
|
||||
* Transfer oldscope's entry count to newscope, as it will be unlocked
|
||||
* now via JS_UNLOCK_OBJ(cx,obj) calls made while we unwind the C stack
|
||||
@@ -720,8 +735,8 @@ void
|
||||
js_LockObj(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
JSScope *scope;
|
||||
prword me = cx->thread;
|
||||
PR_ASSERT(me == CurrentThreadId());
|
||||
jsword me = cx->thread;
|
||||
JS_ASSERT(me == CurrentThreadId());
|
||||
for (;;) {
|
||||
scope = (JSScope *) obj->map;
|
||||
js_LockScope1(cx, scope, me);
|
||||
@@ -745,7 +760,7 @@ js_UnlockObj(JSContext *cx, JSObject *obj)
|
||||
JSBool
|
||||
js_IsRuntimeLocked(JSRuntime *rt)
|
||||
{
|
||||
return CurrentThreadId() == Thin_RemoveWait(AtomicRead(rt->rtLock.owner));
|
||||
return CurrentThreadId() == Thin_RemoveWait(ReadWord(rt->rtLock.owner));
|
||||
}
|
||||
|
||||
JSBool
|
||||
@@ -753,14 +768,15 @@ js_IsObjLocked(JSObject *obj)
|
||||
{
|
||||
JSObjectMap *map = obj->map;
|
||||
|
||||
return MAP_IS_NATIVE(map) && CurrentThreadId() == Thin_RemoveWait(AtomicRead(((JSScope *)map)->lock.owner));
|
||||
return MAP_IS_NATIVE(map) && CurrentThreadId() == Thin_RemoveWait(ReadWord(((JSScope *)map)->lock.owner));
|
||||
}
|
||||
|
||||
JSBool
|
||||
js_IsScopeLocked(JSScope *scope)
|
||||
{
|
||||
return CurrentThreadId() == Thin_RemoveWait(AtomicRead(scope->lock.owner));
|
||||
return CurrentThreadId() == Thin_RemoveWait(ReadWord(scope->lock.owner));
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef ReadWord
|
||||
#endif /* JS_THREADSAFE */
|
||||
|
||||
@@ -20,18 +20,20 @@
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "jstypes.h"
|
||||
#include "prlock.h"
|
||||
#include "prcvar.h"
|
||||
#ifndef NSPR20
|
||||
#include "prhash.h"
|
||||
#include "jshash.h"
|
||||
#else
|
||||
#include "plhash.h"
|
||||
/* Removed by JSIFY: #include "JShash.h"
|
||||
*/
|
||||
#include "jshash.h" /* Added by JSIFY */
|
||||
#endif
|
||||
|
||||
#define Thin_GetWait(W) ((prword)(W) & 0x1)
|
||||
#define Thin_SetWait(W) ((prword)(W) | 0x1)
|
||||
#define Thin_RemoveWait(W) ((prword)(W) & ~0x1)
|
||||
#define Thin_GetWait(W) ((jsword)(W) & 0x1)
|
||||
#define Thin_SetWait(W) ((jsword)(W) | 0x1)
|
||||
#define Thin_RemoveWait(W) ((jsword)(W) & ~0x1)
|
||||
|
||||
typedef struct JSFatLock {
|
||||
int susp;
|
||||
@@ -42,7 +44,7 @@ typedef struct JSFatLock {
|
||||
} JSFatLock;
|
||||
|
||||
typedef struct JSThinLock {
|
||||
prword owner;
|
||||
jsword owner;
|
||||
JSFatLock *fat;
|
||||
} JSThinLock;
|
||||
|
||||
@@ -55,7 +57,7 @@ typedef struct JSFatLockTable {
|
||||
|
||||
#define JS_ATOMIC_ADDREF(p, i) js_AtomicAdd(p,i)
|
||||
|
||||
#define CurrentThreadId() (prword)PR_GetCurrentThread()
|
||||
#define CurrentThreadId() (jsword)PR_GetCurrentThread()
|
||||
#define JS_CurrentThreadId() js_CurrentThreadId()
|
||||
#define JS_NEW_LOCK() PR_NewLock()
|
||||
#define JS_DESTROY_LOCK(l) PR_DestroyLock(l)
|
||||
@@ -64,10 +66,10 @@ typedef struct JSFatLockTable {
|
||||
#define JS_LOCK0(P,M) js_Lock(P,M)
|
||||
#define JS_UNLOCK0(P,M) js_Unlock(P,M)
|
||||
|
||||
#define JS_NEW_CONDVAR(l) PR_NewCondVar(l)
|
||||
#define JS_NEW_CONDVAR(l) JS_NewCondVar(l)
|
||||
#define JS_DESTROY_CONDVAR(cv) PR_DestroyCondVar(cv)
|
||||
#define JS_WAIT_CONDVAR(cv,to) PR_WaitCondVar(cv,to)
|
||||
#define JS_NO_TIMEOUT PR_INTERVAL_NO_TIMEOUT
|
||||
#define JS_NO_TIMEOUT JS_INTERVAL_NO_TIMEOUT
|
||||
#define JS_NOTIFY_CONDVAR(cv) PR_NotifyCondVar(cv)
|
||||
#define JS_NOTIFY_ALL_CONDVAR(cv) PR_NotifyAllCondVar(cv)
|
||||
|
||||
@@ -78,7 +80,7 @@ typedef struct JSFatLockTable {
|
||||
_SET_SCOPE_INFO(((JSScope*)obj->map),f,l)
|
||||
|
||||
#define _SET_SCOPE_INFO(scope,f,l) \
|
||||
(PR_ASSERT(scope->count > 0 && scope->count <= 4), \
|
||||
(JS_ASSERT(scope->count > 0 && scope->count <= 4), \
|
||||
scope->file[scope->count-1] = f, \
|
||||
scope->line[scope->count-1] = l)
|
||||
#endif /* DEBUG */
|
||||
@@ -93,11 +95,11 @@ typedef struct JSFatLockTable {
|
||||
#define JS_UNLOCK_SCOPE(cx,scope) js_UnlockScope(cx, scope)
|
||||
#define JS_TRANSFER_SCOPE_LOCK(cx, scope, newscope) js_TransferScopeLock(cx, scope, newscope)
|
||||
|
||||
extern prword js_CurrentThreadId();
|
||||
extern PR_INLINE void js_Lock(JSThinLock *, prword);
|
||||
extern PR_INLINE void js_Unlock(JSThinLock *, prword);
|
||||
extern int js_CompareAndSwap(prword *, prword, prword);
|
||||
extern void js_AtomicAdd(prword*, prword);
|
||||
extern jsword js_CurrentThreadId();
|
||||
extern JS_INLINE void js_Lock(JSThinLock *, jsword);
|
||||
extern JS_INLINE void js_Unlock(JSThinLock *, jsword);
|
||||
extern int js_CompareAndSwap(jsword *, jsword, jsword);
|
||||
extern void js_AtomicAdd(jsword*, jsword);
|
||||
extern void js_LockRuntime(JSRuntime *rt);
|
||||
extern void js_UnlockRuntime(JSRuntime *rt);
|
||||
extern void js_LockObj(JSContext *cx, JSObject *obj);
|
||||
@@ -132,17 +134,17 @@ extern JSBool js_IsScopeLocked(JSScope *scope);
|
||||
#endif /* DEBUG */
|
||||
|
||||
#define JS_LOCK_OBJ_VOID(cx, obj, e) \
|
||||
PR_BEGIN_MACRO \
|
||||
JS_BEGIN_MACRO \
|
||||
js_LockObj(cx, obj); \
|
||||
e; \
|
||||
js_UnlockObj(cx, obj); \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
#define JS_LOCK_VOID(cx, e) \
|
||||
PR_BEGIN_MACRO \
|
||||
JS_BEGIN_MACRO \
|
||||
JSRuntime *_rt = (cx)->runtime; \
|
||||
JS_LOCK_RUNTIME_VOID(_rt, e); \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
#if defined(JS_ONLY_NSPR_LOCKS) || !(defined(_WIN32) || defined(SOLARIS) || defined(AIX))
|
||||
|
||||
@@ -189,11 +191,11 @@ extern JSBool js_IsScopeLocked(JSScope *scope);
|
||||
#endif /* !JS_THREADSAFE */
|
||||
|
||||
#define JS_LOCK_RUNTIME_VOID(rt,e) \
|
||||
PR_BEGIN_MACRO \
|
||||
JS_BEGIN_MACRO \
|
||||
JS_LOCK_RUNTIME(rt); \
|
||||
e; \
|
||||
JS_UNLOCK_RUNTIME(rt); \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
#define JS_LOCK_GC(rt) JS_ACQUIRE_LOCK((rt)->gcLock)
|
||||
#define JS_UNLOCK_GC(rt) JS_RELEASE_LOCK((rt)->gcLock)
|
||||
|
||||
@@ -16,22 +16,23 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef prlog_h___
|
||||
#define prlog_h___
|
||||
#ifndef jslog_h___
|
||||
#define jslog_h___
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "jstypes.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
** prlog.h -- Declare interfaces to NSPR's Logging service
|
||||
/* Removed by JSIFY: ** prlog.h -- Declare interfaces to NSPR's Logging service */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
**
|
||||
** NSPR provides a logging service that is used by NSPR itself and is
|
||||
** available to client programs.
|
||||
**
|
||||
** To use the service from a client program, you should create a
|
||||
** PRLogModuleInfo structure by calling PR_NewLogModule(). After
|
||||
** creating the LogModule, you can write to the log using the PR_LOG()
|
||||
** PRLogModuleInfo structure by calling JS_NewLogModule(). After
|
||||
** creating the LogModule, you can write to the log using the JS_LOG()
|
||||
** macro.
|
||||
**
|
||||
** Initialization of the log service is handled by NSPR initialization.
|
||||
@@ -45,17 +46,17 @@ PR_BEGIN_EXTERN_C
|
||||
** <moduleName>:<value>[, <moduleName>:<value>]*
|
||||
**
|
||||
** Where:
|
||||
** <moduleName> is the name passed to PR_NewLogModule().
|
||||
** <moduleName> is the name passed to JS_NewLogModule().
|
||||
** <value> is a numeric constant, e.g. 5. This value is the maximum
|
||||
** value of a log event, enumerated by PRLogModuleLevel, that you want
|
||||
** written to the log.
|
||||
**
|
||||
** For example: to record all events of greater value than or equal to
|
||||
** PR_LOG_ERROR for a LogModule names "gizmo", say:
|
||||
** JS_LOG_ERROR for a LogModule names "gizmo", say:
|
||||
**
|
||||
** set NSPR_LOG_MODULES=gizmo:2
|
||||
**
|
||||
** Note that you must specify the numeric value of PR_LOG_ERROR.
|
||||
** Note that you must specify the numeric value of JS_LOG_ERROR.
|
||||
**
|
||||
** Special LogModule names are provided for controlling NSPR's log
|
||||
** service at execution time. These controls should be set in the
|
||||
@@ -63,7 +64,7 @@ PR_BEGIN_EXTERN_C
|
||||
** NSPR's log service for your application.
|
||||
**
|
||||
** The special LogModule "all" enables all LogModules. To enable all
|
||||
** LogModule calls to PR_LOG(), say:
|
||||
** LogModule calls to JS_LOG(), say:
|
||||
**
|
||||
** set NSPR_LOG_MODULES=all:5
|
||||
**
|
||||
@@ -76,9 +77,9 @@ PR_BEGIN_EXTERN_C
|
||||
** The environment variable NSPR_LOG_FILE specifies the log file to use
|
||||
** unless the default of "stderr" is acceptable.
|
||||
**
|
||||
** To put log messages in your programs, use the PR_LOG macro:
|
||||
** To put log messages in your programs, use the JS_LOG macro:
|
||||
**
|
||||
** PR_LOG(<module>, <level>, (<printfString>, <args>*));
|
||||
** JS_LOG(<module>, <level>, (<printfString>, <args>*));
|
||||
**
|
||||
** Where <module> is the address of a PRLogModuleInfo structure, and
|
||||
** <level> is one of the levels defined by the enumeration:
|
||||
@@ -88,14 +89,14 @@ PR_BEGIN_EXTERN_C
|
||||
** Example:
|
||||
**
|
||||
** main() {
|
||||
** PRIntn one = 1;
|
||||
** PRLogModuleInfo * myLm = PR_NewLogModule("gizmo");
|
||||
** PR_LOG( myLm, PR_LOG_ALWAYS, ("Log this! %d\n", one));
|
||||
** JSIntn one = 1;
|
||||
** PRLogModuleInfo * myLm = JS_NewLogModule("gizmo");
|
||||
** JS_LOG( myLm, JS_LOG_ALWAYS, ("Log this! %d\n", one));
|
||||
** return;
|
||||
** }
|
||||
**
|
||||
** Note the use of printf() style arguments as the third agrument(s) to
|
||||
** PR_LOG().
|
||||
** JS_LOG().
|
||||
**
|
||||
** After compiling and linking you application, set the environment:
|
||||
**
|
||||
@@ -112,16 +113,16 @@ PR_BEGIN_EXTERN_C
|
||||
*/
|
||||
|
||||
typedef enum PRLogModuleLevel {
|
||||
PR_LOG_NONE = 0, /* nothing */
|
||||
PR_LOG_ALWAYS = 1, /* always printed */
|
||||
PR_LOG_ERROR = 2, /* error messages */
|
||||
PR_LOG_WARNING = 3, /* warning messages */
|
||||
PR_LOG_DEBUG = 4, /* debug messages */
|
||||
JS_LOG_NONE = 0, /* nothing */
|
||||
JS_LOG_ALWAYS = 1, /* always printed */
|
||||
JS_LOG_ERROR = 2, /* error messages */
|
||||
JS_LOG_WARNING = 3, /* warning messages */
|
||||
JS_LOG_DEBUG = 4, /* debug messages */
|
||||
|
||||
PR_LOG_NOTICE = PR_LOG_DEBUG, /* notice messages */
|
||||
PR_LOG_WARN = PR_LOG_WARNING, /* warning messages */
|
||||
PR_LOG_MIN = PR_LOG_DEBUG, /* minimal debugging messages */
|
||||
PR_LOG_MAX = PR_LOG_DEBUG /* maximal debugging messages */
|
||||
JS_LOG_NOTICE = JS_LOG_DEBUG, /* notice messages */
|
||||
JS_LOG_WARN = JS_LOG_WARNING, /* warning messages */
|
||||
JS_LOG_MIN = JS_LOG_DEBUG, /* minimal debugging messages */
|
||||
JS_LOG_MAX = JS_LOG_DEBUG /* maximal debugging messages */
|
||||
} PRLogModuleLevel;
|
||||
|
||||
/*
|
||||
@@ -138,19 +139,19 @@ typedef struct PRLogModuleInfo {
|
||||
/*
|
||||
** Create a new log module.
|
||||
*/
|
||||
PR_EXTERN(PRLogModuleInfo*) PR_NewLogModule(const char *name);
|
||||
EXTERN(PRLogModuleInfo*) JS_NewLogModule(const char *name);
|
||||
|
||||
/*
|
||||
** Set the file to use for logging. Returns PR_FALSE if the file cannot
|
||||
** Set the file to use for logging. Returns JS_FALSE if the file cannot
|
||||
** be created
|
||||
*/
|
||||
PR_EXTERN(PRBool) PR_SetLogFile(const char *name);
|
||||
EXTERN(JSBool) JS_SetLogFile(const char *name);
|
||||
|
||||
/*
|
||||
** Set the size of the logging buffer. If "buffer_size" is zero then the
|
||||
** logging becomes "synchronous" (or unbuffered).
|
||||
*/
|
||||
PR_EXTERN(void) PR_SetLogBuffering(PRIntn buffer_size);
|
||||
EXTERN(void) JS_SetLogBuffering(JSIntn buffer_size);
|
||||
|
||||
/*
|
||||
** Print a string to the log. "fmt" is a PR_snprintf format type. All
|
||||
@@ -158,21 +159,21 @@ PR_EXTERN(void) PR_SetLogBuffering(PRIntn buffer_size);
|
||||
** and a time stamp. Also, the routine provides a missing newline if one
|
||||
** is not provided.
|
||||
*/
|
||||
PR_EXTERN(void) PR_LogPrint(const char *fmt, ...);
|
||||
EXTERN(void) JS_LogPrint(const char *fmt, ...);
|
||||
|
||||
/*
|
||||
** Flush the log to its file.
|
||||
*/
|
||||
PR_EXTERN(void) PR_LogFlush(void);
|
||||
EXTERN(void) JS_LogFlush(void);
|
||||
|
||||
/*
|
||||
** Windoze 16 can't support a large static string space for all of the
|
||||
** various debugging strings so logging is not enabled for it.
|
||||
*/
|
||||
#if (defined(DEBUG) || defined(FORCE_PR_LOG)) && !defined(WIN16)
|
||||
#define PR_LOGGING 1
|
||||
#define JS_LOGGING 1
|
||||
|
||||
#define PR_LOG_TEST(_module,_level) \
|
||||
#define JS_LOG_TEST(_module,_level) \
|
||||
((_module)->level >= (_level))
|
||||
|
||||
/*
|
||||
@@ -182,51 +183,51 @@ PR_EXTERN(void) PR_LogFlush(void);
|
||||
** "args" is a variable length list of arguments to print, in the following
|
||||
** format: ("printf style format string", ...)
|
||||
*/
|
||||
#define PR_LOG(_module,_level,_args) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (PR_LOG_TEST(_module,_level)) { \
|
||||
PR_LogPrint _args; \
|
||||
#define JS_LOG(_module,_level,_args) \
|
||||
JS_BEGIN_MACRO \
|
||||
if (JS_LOG_TEST(_module,_level)) { \
|
||||
JS_LogPrint _args; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
#else /* (defined(DEBUG) || defined(FORCE_PR_LOG)) && !defined(WIN16) */
|
||||
|
||||
#undef PR_LOGGING
|
||||
#define PR_LOG_TEST(module,level) 0
|
||||
#define PR_LOG(module,level,args)
|
||||
#undef JS_LOGGING
|
||||
#define JS_LOG_TEST(module,level) 0
|
||||
#define JS_LOG(module,level,args)
|
||||
|
||||
#endif /* (defined(DEBUG) || defined(FORCE_PR_LOG)) && !defined(WIN16) */
|
||||
|
||||
#ifndef NO_NSPR_10_SUPPORT
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
#define PR_LOG_BEGIN PR_LOG
|
||||
#define PR_LOG_END PR_LOG
|
||||
#define PR_LOG_DEFINE PR_NewLogModule
|
||||
#ifdef JS_LOGGING
|
||||
#define JS_LOG_BEGIN JS_LOG
|
||||
#define JS_LOG_END JS_LOG
|
||||
#define JS_LOG_DEFINE JS_NewLogModule
|
||||
#else
|
||||
#define PR_LOG_BEGIN(module,level,args)
|
||||
#define PR_LOG_END(module,level,args)
|
||||
#define PR_LOG_DEFINE(_name) NULL
|
||||
#endif /* PR_LOGGING */
|
||||
#define JS_LOG_BEGIN(module,level,args)
|
||||
#define JS_LOG_END(module,level,args)
|
||||
#define JS_LOG_DEFINE(_name) NULL
|
||||
#endif /* JS_LOGGING */
|
||||
|
||||
#endif /* NO_NSPR_10_SUPPORT */
|
||||
|
||||
#if defined(DEBUG)
|
||||
#ifdef DEBUG
|
||||
|
||||
PR_EXTERN(void) PR_Assert(const char *s, const char *file, PRIntn ln);
|
||||
#define PR_ASSERT(_expr) \
|
||||
((_expr)?((void)0):PR_Assert(# _expr,__FILE__,__LINE__))
|
||||
EXTERN(void) JS_Assert(const char *s, const char *file, JSIntn ln);
|
||||
#define JS_ASSERT(_expr) \
|
||||
((_expr)?((void)0):JS_Assert(# _expr,__FILE__,__LINE__))
|
||||
|
||||
#define PR_NOT_REACHED(_reasonStr) \
|
||||
PR_Assert(_reasonStr,__FILE__,__LINE__)
|
||||
#define JS_NOT_REACHED(_reasonStr) \
|
||||
JS_Assert(_reasonStr,__FILE__,__LINE__)
|
||||
|
||||
#else
|
||||
|
||||
#define PR_ASSERT(expr) ((void) 0)
|
||||
#define PR_NOT_REACHED(reasonStr)
|
||||
#define JS_ASSERT(expr) ((void) 0)
|
||||
#define JS_NOT_REACHED(reasonStr)
|
||||
|
||||
#endif /* defined(DEBUG) */
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* prlog_h___ */
|
||||
#endif /* jslog_h___ */
|
||||
@@ -16,14 +16,14 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "prbit.h"
|
||||
#include "jsbit.h"
|
||||
|
||||
/*
|
||||
** Compute the log of the least power of 2 greater than or equal to n
|
||||
*/
|
||||
PR_IMPLEMENT(PRIntn) PR_CeilingLog2(PRUint32 n)
|
||||
IMPLEMENT(JSIntn) JS_CeilingLog2(JSUint32 n)
|
||||
{
|
||||
PRIntn log2 = 0;
|
||||
JSIntn log2 = 0;
|
||||
|
||||
if (n & (n-1))
|
||||
log2++;
|
||||
@@ -44,9 +44,9 @@ PR_IMPLEMENT(PRIntn) PR_CeilingLog2(PRUint32 n)
|
||||
** Compute the log of the greatest power of 2 less than or equal to n.
|
||||
** This really just finds the highest set bit in the word.
|
||||
*/
|
||||
PR_IMPLEMENT(PRIntn) PR_FloorLog2(PRUint32 n)
|
||||
IMPLEMENT(JSIntn) JS_FloorLog2(JSUint32 n)
|
||||
{
|
||||
PRIntn log2 = 0;
|
||||
JSIntn log2 = 0;
|
||||
|
||||
if (n >> 16)
|
||||
log2 += 16, n >>= 16;
|
||||
@@ -16,38 +16,34 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifdef MINI_NSPR
|
||||
#include "prtypes.h"
|
||||
#include "prlong.h"
|
||||
#else
|
||||
#include "primpl.h"
|
||||
#endif
|
||||
#include "jstypes.h"
|
||||
#include "jslong.h"
|
||||
|
||||
static PRInt64 ll_zero = LL_INIT( 0x00000000,0x00000000 );
|
||||
static PRInt64 ll_maxint = LL_INIT( 0x7fffffff, 0xffffffff );
|
||||
static PRInt64 ll_minint = LL_INIT( 0x80000000, 0x00000000 );
|
||||
static JSInt64 ll_zero = JSLL_INIT( 0x00000000,0x00000000 );
|
||||
static JSInt64 ll_maxint = JSLL_INIT( 0x7fffffff, 0xffffffff );
|
||||
static JSInt64 ll_minint = JSLL_INIT( 0x80000000, 0x00000000 );
|
||||
|
||||
#if defined(HAVE_WATCOM_BUG_2)
|
||||
PRInt64 __pascal __loadds __export
|
||||
LL_Zero(void) { return ll_zero; }
|
||||
PRInt64 __pascal __loadds __export
|
||||
LL_MaxInt(void) { return ll_maxint; }
|
||||
PRInt64 __pascal __loadds __export
|
||||
LL_MinInt(void) { return ll_minint; }
|
||||
#ifdef HAVE_WATCOM_BUG_2
|
||||
JSInt64 __pascal __loadds __export
|
||||
JSLL_Zero(void) { return ll_zero; }
|
||||
JSInt64 __pascal __loadds __export
|
||||
JSLL_MaxInt(void) { return ll_maxint; }
|
||||
JSInt64 __pascal __loadds __export
|
||||
JSLL_MinInt(void) { return ll_minint; }
|
||||
#else
|
||||
PR_IMPLEMENT(PRInt64) LL_Zero(void) { return ll_zero; }
|
||||
PR_IMPLEMENT(PRInt64) LL_MaxInt(void) { return ll_maxint; }
|
||||
PR_IMPLEMENT(PRInt64) LL_MinInt(void) { return ll_minint; }
|
||||
IMPLEMENT(JSInt64) JSLL_Zero(void) { return ll_zero; }
|
||||
IMPLEMENT(JSInt64) JSLL_MaxInt(void) { return ll_maxint; }
|
||||
IMPLEMENT(JSInt64) JSLL_MinInt(void) { return ll_minint; }
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_LONG_LONG
|
||||
/*
|
||||
** Divide 64-bit a by 32-bit b, which must be normalized so its high bit is 1.
|
||||
*/
|
||||
static void norm_udivmod32(PRUint32 *qp, PRUint32 *rp, PRUint64 a, PRUint32 b)
|
||||
static void norm_udivmod32(JSUint32 *qp, JSUint32 *rp, JSUint64 a, JSUint32 b)
|
||||
{
|
||||
PRUint32 d1, d0, q1, q0;
|
||||
PRUint32 r1, r0, m;
|
||||
JSUint32 d1, d0, q1, q0;
|
||||
JSUint32 r1, r0, m;
|
||||
|
||||
d1 = _hi16(b);
|
||||
d0 = _lo16(b);
|
||||
@@ -78,10 +74,10 @@ static void norm_udivmod32(PRUint32 *qp, PRUint32 *rp, PRUint64 a, PRUint32 b)
|
||||
*rp = r0 - m;
|
||||
}
|
||||
|
||||
static PRUint32 CountLeadingZeros(PRUint32 a)
|
||||
static JSUint32 CountLeadingZeros(JSUint32 a)
|
||||
{
|
||||
PRUint32 t;
|
||||
PRUint32 r = 32;
|
||||
JSUint32 t;
|
||||
JSUint32 r = 32;
|
||||
|
||||
if ((t = a >> 16) != 0)
|
||||
r -= 16, a = t;
|
||||
@@ -98,11 +94,11 @@ static PRUint32 CountLeadingZeros(PRUint32 a)
|
||||
return r;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(void) ll_udivmod(PRUint64 *qp, PRUint64 *rp, PRUint64 a, PRUint64 b)
|
||||
IMPLEMENT(void) ll_udivmod(JSUint64 *qp, JSUint64 *rp, JSUint64 a, JSUint64 b)
|
||||
{
|
||||
PRUint32 n0, n1, n2;
|
||||
PRUint32 q0, q1;
|
||||
PRUint32 rsh, lsh;
|
||||
JSUint32 n0, n1, n2;
|
||||
JSUint32 q0, q1;
|
||||
JSUint32 rsh, lsh;
|
||||
|
||||
n0 = a.lo;
|
||||
n1 = a.hi;
|
||||
@@ -210,7 +206,7 @@ PR_IMPLEMENT(void) ll_udivmod(PRUint64 *qp, PRUint64 *rp, PRUint64 a, PRUint64 b
|
||||
if (n1 > b.hi || n0 >= b.lo) {
|
||||
q0 = 1;
|
||||
a.lo = n0, a.hi = n1;
|
||||
LL_SUB(a, a, b);
|
||||
JSLL_SUB(a, a, b);
|
||||
} else {
|
||||
q0 = 0;
|
||||
}
|
||||
@@ -221,7 +217,7 @@ PR_IMPLEMENT(void) ll_udivmod(PRUint64 *qp, PRUint64 *rp, PRUint64 a, PRUint64 b
|
||||
rp->hi = n1;
|
||||
}
|
||||
} else {
|
||||
PRInt64 m;
|
||||
JSInt64 m;
|
||||
|
||||
/*
|
||||
* Normalize.
|
||||
@@ -236,11 +232,11 @@ PR_IMPLEMENT(void) ll_udivmod(PRUint64 *qp, PRUint64 *rp, PRUint64 a, PRUint64 b
|
||||
|
||||
a.lo = n1, a.hi = n2;
|
||||
norm_udivmod32(&q0, &n1, a, b.hi);
|
||||
LL_MUL32(m, q0, b.lo);
|
||||
JSLL_MUL32(m, q0, b.lo);
|
||||
|
||||
if ((m.hi > n1) || ((m.hi == n1) && (m.lo > n0))) {
|
||||
q0--;
|
||||
LL_SUB(m, m, b);
|
||||
JSLL_SUB(m, m, b);
|
||||
}
|
||||
|
||||
q1 = 0;
|
||||
@@ -248,7 +244,7 @@ PR_IMPLEMENT(void) ll_udivmod(PRUint64 *qp, PRUint64 *rp, PRUint64 a, PRUint64 b
|
||||
/* Remainder is ((n1 n0) - (m1 m0)) >> lsh */
|
||||
if (rp) {
|
||||
a.lo = n0, a.hi = n1;
|
||||
LL_SUB(a, a, m);
|
||||
JSLL_SUB(a, a, m);
|
||||
rp->lo = (a.hi << rsh) | (a.lo >> lsh);
|
||||
rp->hi = a.hi >> lsh;
|
||||
}
|
||||
409
mozilla/js/src/jslong.h
Normal file
409
mozilla/js/src/jslong.h
Normal file
@@ -0,0 +1,409 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
** File: jslong.h
|
||||
** Description: Portable access to 64 bit numerics
|
||||
**
|
||||
** Long-long (64-bit signed integer type) support. Some C compilers
|
||||
** don't support 64 bit integers yet, so we use these macros to
|
||||
** support both machines that do and don't.
|
||||
**/
|
||||
#ifndef jslong_h___
|
||||
#define jslong_h___
|
||||
|
||||
#include "jstypes.h"
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/***********************************************************************
|
||||
** DEFINES: JSLL_MaxInt
|
||||
** JSLL_MinInt
|
||||
** JSLL_Zero
|
||||
** DESCRIPTION:
|
||||
** Various interesting constants and static variable
|
||||
** initializer
|
||||
***********************************************************************/
|
||||
#ifdef HAVE_WATCOM_BUG_2
|
||||
JSInt64 __pascal __loadds __export
|
||||
JSLL_MaxInt(void);
|
||||
JSInt64 __pascal __loadds __export
|
||||
JSLL_MinInt(void);
|
||||
JSInt64 __pascal __loadds __export
|
||||
JSLL_Zero(void);
|
||||
#else
|
||||
EXTERN(JSInt64) JSLL_MaxInt(void);
|
||||
EXTERN(JSInt64) JSLL_MinInt(void);
|
||||
EXTERN(JSInt64) JSLL_Zero(void);
|
||||
#endif
|
||||
|
||||
#define JSLL_MAXINT JSLL_MaxInt()
|
||||
#define JSLL_MININT JSLL_MinInt()
|
||||
#define JSLL_ZERO JSLL_Zero()
|
||||
|
||||
#ifdef HAVE_LONG_LONG
|
||||
|
||||
#if JS_BYTES_PER_LONG == 8
|
||||
#define JSLL_INIT(hi, lo) ((hi ## L << 32) + lo ## L)
|
||||
#elif defined(WIN32) || defined(WIN16)
|
||||
#define JSLL_INIT(hi, lo) ((hi ## i64 << 32) + lo ## i64)
|
||||
#else
|
||||
#define JSLL_INIT(hi, lo) ((hi ## LL << 32) + lo ## LL)
|
||||
#endif
|
||||
|
||||
/***********************************************************************
|
||||
** MACROS: JSLL_*
|
||||
** DESCRIPTION:
|
||||
** The following macros define portable access to the 64 bit
|
||||
** math facilities.
|
||||
**
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
** MACROS: JSLL_<relational operators>
|
||||
**
|
||||
** JSLL_IS_ZERO Test for zero
|
||||
** JSLL_EQ Test for equality
|
||||
** JSLL_NE Test for inequality
|
||||
** JSLL_GE_ZERO Test for zero or positive
|
||||
** JSLL_CMP Compare two values
|
||||
***********************************************************************/
|
||||
#define JSLL_IS_ZERO(a) ((a) == 0)
|
||||
#define JSLL_EQ(a, b) ((a) == (b))
|
||||
#define JSLL_NE(a, b) ((a) != (b))
|
||||
#define JSLL_GE_ZERO(a) ((a) >= 0)
|
||||
#define JSLL_CMP(a, op, b) ((JSInt64)(a) op (JSInt64)(b))
|
||||
#define JSLL_UCMP(a, op, b) ((JSUint64)(a) op (JSUint64)(b))
|
||||
|
||||
/***********************************************************************
|
||||
** MACROS: JSLL_<logical operators>
|
||||
**
|
||||
** JSLL_AND Logical and
|
||||
** JSLL_OR Logical or
|
||||
** JSLL_XOR Logical exclusion
|
||||
** JSLL_OR2 A disgusting deviation
|
||||
** JSLL_NOT Negation (one's compliment)
|
||||
***********************************************************************/
|
||||
#define JSLL_AND(r, a, b) ((r) = (a) & (b))
|
||||
#define JSLL_OR(r, a, b) ((r) = (a) | (b))
|
||||
#define JSLL_XOR(r, a, b) ((r) = (a) ^ (b))
|
||||
#define JSLL_OR2(r, a) ((r) = (r) | (a))
|
||||
#define JSLL_NOT(r, a) ((r) = ~(a))
|
||||
|
||||
/***********************************************************************
|
||||
** MACROS: JSLL_<mathematical operators>
|
||||
**
|
||||
** JSLL_NEG Negation (two's compliment)
|
||||
** JSLL_ADD Summation (two's compliment)
|
||||
** JSLL_SUB Difference (two's compliment)
|
||||
***********************************************************************/
|
||||
#define JSLL_NEG(r, a) ((r) = -(a))
|
||||
#define JSLL_ADD(r, a, b) ((r) = (a) + (b))
|
||||
#define JSLL_SUB(r, a, b) ((r) = (a) - (b))
|
||||
|
||||
/***********************************************************************
|
||||
** MACROS: JSLL_<mathematical operators>
|
||||
**
|
||||
** JSLL_MUL Product (two's compliment)
|
||||
** JSLL_DIV Quotient (two's compliment)
|
||||
** JSLL_MOD Modulus (two's compliment)
|
||||
***********************************************************************/
|
||||
#define JSLL_MUL(r, a, b) ((r) = (a) * (b))
|
||||
#define JSLL_DIV(r, a, b) ((r) = (a) / (b))
|
||||
#define JSLL_MOD(r, a, b) ((r) = (a) % (b))
|
||||
|
||||
/***********************************************************************
|
||||
** MACROS: JSLL_<shifting operators>
|
||||
**
|
||||
** JSLL_SHL Shift left [0..64] bits
|
||||
** JSLL_SHR Shift right [0..64] bits with sign extension
|
||||
** JSLL_USHR Unsigned shift right [0..64] bits
|
||||
** JSLL_ISHL Signed shift left [0..64] bits
|
||||
***********************************************************************/
|
||||
#define JSLL_SHL(r, a, b) ((r) = (JSInt64)(a) << (b))
|
||||
#define JSLL_SHR(r, a, b) ((r) = (JSInt64)(a) >> (b))
|
||||
#define JSLL_USHR(r, a, b) ((r) = (JSUint64)(a) >> (b))
|
||||
#define JSLL_ISHL(r, a, b) ((r) = (JSInt64)(a) << (b))
|
||||
|
||||
/***********************************************************************
|
||||
** MACROS: JSLL_<conversion operators>
|
||||
**
|
||||
** JSLL_L2I Convert to signed 32 bit
|
||||
** JSLL_L2UI Convert to unsigned 32 bit
|
||||
** JSLL_L2F Convert to floating point
|
||||
** JSLL_L2D Convert to floating point
|
||||
** JSLL_I2L Convert signed to 64 bit
|
||||
** JSLL_UI2L Convert unsigned to 64 bit
|
||||
** JSLL_F2L Convert float to 64 bit
|
||||
** JSLL_D2L Convert float to 64 bit
|
||||
***********************************************************************/
|
||||
#define JSLL_L2I(i, l) ((i) = (JSInt32)(l))
|
||||
#define JSLL_L2UI(ui, l) ((ui) = (JSUint32)(l))
|
||||
#define JSLL_L2F(f, l) ((f) = (JSFloat64)(l))
|
||||
#define JSLL_L2D(d, l) ((d) = (JSFloat64)(l))
|
||||
|
||||
#define JSLL_I2L(l, i) ((l) = (JSInt64)(i))
|
||||
#define JSLL_UI2L(l, ui) ((l) = (JSInt64)(ui))
|
||||
#define JSLL_F2L(l, f) ((l) = (JSInt64)(f))
|
||||
#define JSLL_D2L(l, d) ((l) = (JSInt64)(d))
|
||||
|
||||
/***********************************************************************
|
||||
** MACROS: JSLL_UDIVMOD
|
||||
** DESCRIPTION:
|
||||
** Produce both a quotient and a remainder given an unsigned
|
||||
** INPUTS: JSUint64 a: The dividend of the operation
|
||||
** JSUint64 b: The quotient of the operation
|
||||
** OUTPUTS: JSUint64 *qp: pointer to quotient
|
||||
** JSUint64 *rp: pointer to remainder
|
||||
***********************************************************************/
|
||||
#define JSLL_UDIVMOD(qp, rp, a, b) \
|
||||
(*(qp) = ((JSUint64)(a) / (b)), \
|
||||
*(rp) = ((JSUint64)(a) % (b)))
|
||||
|
||||
#else /* !HAVE_LONG_LONG */
|
||||
|
||||
#ifdef IS_LITTLE_ENDIAN
|
||||
#define JSLL_INIT(hi, lo) {JS_INT32(lo), JS_INT32(hi)}
|
||||
#else
|
||||
#define JSLL_INIT(hi, lo) {JS_INT32(hi), JS_INT32(lo)}
|
||||
#endif
|
||||
|
||||
#define JSLL_IS_ZERO(a) (((a).hi == 0) && ((a).lo == 0))
|
||||
#define JSLL_EQ(a, b) (((a).hi == (b).hi) && ((a).lo == (b).lo))
|
||||
#define JSLL_NE(a, b) (((a).hi != (b).hi) || ((a).lo != (b).lo))
|
||||
#define JSLL_GE_ZERO(a) (((a).hi >> 31) == 0)
|
||||
|
||||
#define JSLL_CMP(a, op, b) (((JSInt32)(a).hi op (JSInt32)(b).hi) || \
|
||||
(((a).hi == (b).hi) && ((a).lo op (b).lo)))
|
||||
#define JSLL_UCMP(a, op, b) (((a).hi op (b).hi) || \
|
||||
(((a).hi == (b).hi) && ((a).lo op (b).lo)))
|
||||
|
||||
#define JSLL_AND(r, a, b) ((r).lo = (a).lo & (b).lo, \
|
||||
(r).hi = (a).hi & (b).hi)
|
||||
#define JSLL_OR(r, a, b) ((r).lo = (a).lo | (b).lo, \
|
||||
(r).hi = (a).hi | (b).hi)
|
||||
#define JSLL_XOR(r, a, b) ((r).lo = (a).lo ^ (b).lo, \
|
||||
(r).hi = (a).hi ^ (b).hi)
|
||||
#define JSLL_OR2(r, a) ((r).lo = (r).lo | (a).lo, \
|
||||
(r).hi = (r).hi | (a).hi)
|
||||
#define JSLL_NOT(r, a) ((r).lo = ~(a).lo, \
|
||||
(r).hi = ~(a).hi)
|
||||
|
||||
#define JSLL_NEG(r, a) ((r).lo = -(JSInt32)(a).lo, \
|
||||
(r).hi = -(JSInt32)(a).hi - ((r).lo != 0))
|
||||
#define JSLL_ADD(r, a, b) { \
|
||||
JSInt64 _a, _b; \
|
||||
_a = a; _b = b; \
|
||||
(r).lo = _a.lo + _b.lo; \
|
||||
(r).hi = _a.hi + _b.hi + ((r).lo < _b.lo); \
|
||||
}
|
||||
|
||||
#define JSLL_SUB(r, a, b) { \
|
||||
JSInt64 _a, _b; \
|
||||
_a = a; _b = b; \
|
||||
(r).lo = _a.lo - _b.lo; \
|
||||
(r).hi = _a.hi - _b.hi - (_a.lo < _b.lo); \
|
||||
}
|
||||
|
||||
#define JSLL_MUL(r, a, b) { \
|
||||
JSInt64 _a, _b; \
|
||||
_a = a; _b = b; \
|
||||
JSLL_MUL32(r, _a.lo, _b.lo); \
|
||||
(r).hi += _a.hi * _b.lo + _a.lo * _b.hi; \
|
||||
}
|
||||
|
||||
#define _lo16(a) ((a) & JS_BITMASK(16))
|
||||
#define _hi16(a) ((a) >> 16)
|
||||
|
||||
#define JSLL_MUL32(r, a, b) { \
|
||||
JSUint32 _a1, _a0, _b1, _b0, _y0, _y1, _y2, _y3; \
|
||||
_a1 = _hi16(a), _a0 = _lo16(a); \
|
||||
_b1 = _hi16(b), _b0 = _lo16(b); \
|
||||
_y0 = _a0 * _b0; \
|
||||
_y1 = _a0 * _b1; \
|
||||
_y2 = _a1 * _b0; \
|
||||
_y3 = _a1 * _b1; \
|
||||
_y1 += _hi16(_y0); /* can't carry */ \
|
||||
_y1 += _y2; /* might carry */ \
|
||||
if (_y1 < _y2) \
|
||||
_y3 += (JSUint32)(JS_BIT(16)); /* propagate */ \
|
||||
(r).lo = (_lo16(_y1) << 16) + _lo16(_y0); \
|
||||
(r).hi = _y3 + _hi16(_y1); \
|
||||
}
|
||||
|
||||
#define JSLL_UDIVMOD(qp, rp, a, b) ll_udivmod(qp, rp, a, b)
|
||||
|
||||
EXTERN(void) ll_udivmod(JSUint64 *qp, JSUint64 *rp, JSUint64 a, JSUint64 b);
|
||||
|
||||
#define JSLL_DIV(r, a, b) { \
|
||||
JSInt64 _a, _b; \
|
||||
JSUint32 _negative = (JSInt32)(a).hi < 0; \
|
||||
if (_negative) { \
|
||||
JSLL_NEG(_a, a); \
|
||||
} else { \
|
||||
_a = a; \
|
||||
} \
|
||||
if ((JSInt32)(b).hi < 0) { \
|
||||
_negative ^= 1; \
|
||||
JSLL_NEG(_b, b); \
|
||||
} else { \
|
||||
_b = b; \
|
||||
} \
|
||||
JSLL_UDIVMOD(&(r), 0, _a, _b); \
|
||||
if (_negative) \
|
||||
JSLL_NEG(r, r); \
|
||||
}
|
||||
|
||||
#define JSLL_MOD(r, a, b) { \
|
||||
JSInt64 _a, _b; \
|
||||
JSUint32 _negative = (JSInt32)(a).hi < 0; \
|
||||
if (_negative) { \
|
||||
JSLL_NEG(_a, a); \
|
||||
} else { \
|
||||
_a = a; \
|
||||
} \
|
||||
if ((JSInt32)(b).hi < 0) { \
|
||||
JSLL_NEG(_b, b); \
|
||||
} else { \
|
||||
_b = b; \
|
||||
} \
|
||||
JSLL_UDIVMOD(0, &(r), _a, _b); \
|
||||
if (_negative) \
|
||||
JSLL_NEG(r, r); \
|
||||
}
|
||||
|
||||
#define JSLL_SHL(r, a, b) { \
|
||||
if (b) { \
|
||||
JSInt64 _a; \
|
||||
_a = a; \
|
||||
if ((b) < 32) { \
|
||||
(r).lo = _a.lo << ((b) & 31); \
|
||||
(r).hi = (_a.hi << ((b) & 31)) | (_a.lo >> (32 - (b))); \
|
||||
} else { \
|
||||
(r).lo = 0; \
|
||||
(r).hi = _a.lo << ((b) & 31); \
|
||||
} \
|
||||
} else { \
|
||||
(r) = (a); \
|
||||
} \
|
||||
}
|
||||
|
||||
/* a is an JSInt32, b is JSInt32, r is JSInt64 */
|
||||
#define JSLL_ISHL(r, a, b) { \
|
||||
if (b) { \
|
||||
JSInt64 _a; \
|
||||
_a.lo = (a); \
|
||||
_a.hi = 0; \
|
||||
if ((b) < 32) { \
|
||||
(r).lo = (a) << ((b) & 31); \
|
||||
(r).hi = ((a) >> (32 - (b))); \
|
||||
} else { \
|
||||
(r).lo = 0; \
|
||||
(r).hi = (a) << ((b) & 31); \
|
||||
} \
|
||||
} else { \
|
||||
(r).lo = (a); \
|
||||
(r).hi = 0; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define JSLL_SHR(r, a, b) { \
|
||||
if (b) { \
|
||||
JSInt64 _a; \
|
||||
_a = a; \
|
||||
if ((b) < 32) { \
|
||||
(r).lo = (_a.hi << (32 - (b))) | (_a.lo >> ((b) & 31)); \
|
||||
(r).hi = (JSInt32)_a.hi >> ((b) & 31); \
|
||||
} else { \
|
||||
(r).lo = (JSInt32)_a.hi >> ((b) & 31); \
|
||||
(r).hi = (JSInt32)_a.hi >> 31; \
|
||||
} \
|
||||
} else { \
|
||||
(r) = (a); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define JSLL_USHR(r, a, b) { \
|
||||
if (b) { \
|
||||
JSInt64 _a; \
|
||||
_a = a; \
|
||||
if ((b) < 32) { \
|
||||
(r).lo = (_a.hi << (32 - (b))) | (_a.lo >> ((b) & 31)); \
|
||||
(r).hi = _a.hi >> ((b) & 31); \
|
||||
} else { \
|
||||
(r).lo = _a.hi >> ((b) & 31); \
|
||||
(r).hi = 0; \
|
||||
} \
|
||||
} else { \
|
||||
(r) = (a); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define JSLL_L2I(i, l) ((i) = (l).lo)
|
||||
#define JSLL_L2UI(ui, l) ((ui) = (l).lo)
|
||||
#define JSLL_L2F(f, l) { double _d; JSLL_L2D(_d, l); (f) = (JSFloat64)_d; }
|
||||
|
||||
#define JSLL_L2D(d, l) { \
|
||||
int _negative; \
|
||||
JSInt64 _absval; \
|
||||
\
|
||||
_negative = (l).hi >> 31; \
|
||||
if (_negative) { \
|
||||
JSLL_NEG(_absval, l); \
|
||||
} else { \
|
||||
_absval = l; \
|
||||
} \
|
||||
(d) = (double)_absval.hi * 4.294967296e9 + _absval.lo; \
|
||||
if (_negative) \
|
||||
(d) = -(d); \
|
||||
}
|
||||
|
||||
#define JSLL_I2L(l, i) { JSInt32 _i = (i) >> 31; (l).lo = (i); (l).hi = _i; }
|
||||
#define JSLL_UI2L(l, ui) ((l).lo = (ui), (l).hi = 0)
|
||||
#define JSLL_F2L(l, f) { double _d = (double)f; JSLL_D2L(l, _d); }
|
||||
|
||||
#define JSLL_D2L(l, d) { \
|
||||
int _negative; \
|
||||
double _absval, _d_hi; \
|
||||
JSInt64 _lo_d; \
|
||||
\
|
||||
_negative = ((d) < 0); \
|
||||
_absval = _negative ? -(d) : (d); \
|
||||
\
|
||||
(l).hi = _absval / 4.294967296e9; \
|
||||
(l).lo = 0; \
|
||||
JSLL_L2D(_d_hi, l); \
|
||||
_absval -= _d_hi; \
|
||||
_lo_d.hi = 0; \
|
||||
if (_absval < 0) { \
|
||||
_lo_d.lo = -_absval; \
|
||||
JSLL_SUB(l, l, _lo_d); \
|
||||
} else { \
|
||||
_lo_d.lo = _absval; \
|
||||
JSLL_ADD(l, l, _lo_d); \
|
||||
} \
|
||||
\
|
||||
if (_negative) \
|
||||
JSLL_NEG(l, l); \
|
||||
}
|
||||
|
||||
#endif /* !HAVE_LONG_LONG */
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jslong_h___ */
|
||||
@@ -16,15 +16,15 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef prmacos_h___
|
||||
#define prmacos_h___
|
||||
#ifndef jsmacos_h___
|
||||
#define jsmacos_h___
|
||||
//
|
||||
// This file contains all changes and additions that need to be made to the
|
||||
// runtime for the Macintosh platform hosting the Metrowerks environment.
|
||||
// This file should only be included in Macintosh builds.
|
||||
//
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -32,6 +32,6 @@ extern void* reallocSmaller(void* block, size_t newSize);
|
||||
|
||||
extern char* strdup(const char* str);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* prmacos_h___ */
|
||||
#endif /* jsmacos_h___ */
|
||||
@@ -22,8 +22,8 @@
|
||||
#include "jsstddef.h"
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include "prtypes.h"
|
||||
#include "prlong.h"
|
||||
#include "jstypes.h"
|
||||
#include "jslong.h"
|
||||
#include "prmjtime.h"
|
||||
#include "jsapi.h"
|
||||
#include "jsatom.h"
|
||||
@@ -237,10 +237,10 @@ random_setSeed(JSRuntime *rt, int64 seed)
|
||||
{
|
||||
int64 tmp;
|
||||
|
||||
LL_I2L(tmp, 1000);
|
||||
LL_DIV(seed, seed, tmp);
|
||||
LL_XOR(tmp, seed, rt->rngMultiplier);
|
||||
LL_AND(rt->rngSeed, tmp, rt->rngMask);
|
||||
JSLL_I2L(tmp, 1000);
|
||||
JSLL_DIV(seed, seed, tmp);
|
||||
JSLL_XOR(tmp, seed, rt->rngMultiplier);
|
||||
JSLL_AND(rt->rngSeed, tmp, rt->rngMask);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -254,21 +254,21 @@ random_init(JSRuntime *rt)
|
||||
rt->rngInitialized = JS_TRUE;
|
||||
|
||||
/* rt->rngMultiplier = 0x5DEECE66DL */
|
||||
LL_ISHL(tmp, 0x5D, 32);
|
||||
LL_UI2L(tmp2, 0xEECE66DL);
|
||||
LL_OR(rt->rngMultiplier, tmp, tmp2);
|
||||
JSLL_ISHL(tmp, 0x5D, 32);
|
||||
JSLL_UI2L(tmp2, 0xEECE66DL);
|
||||
JSLL_OR(rt->rngMultiplier, tmp, tmp2);
|
||||
|
||||
/* rt->rngAddend = 0xBL */
|
||||
LL_I2L(rt->rngAddend, 0xBL);
|
||||
JSLL_I2L(rt->rngAddend, 0xBL);
|
||||
|
||||
/* rt->rngMask = (1L << 48) - 1 */
|
||||
LL_I2L(tmp, 1);
|
||||
LL_SHL(tmp2, tmp, 48);
|
||||
LL_SUB(rt->rngMask, tmp2, tmp);
|
||||
JSLL_I2L(tmp, 1);
|
||||
JSLL_SHL(tmp2, tmp, 48);
|
||||
JSLL_SUB(rt->rngMask, tmp2, tmp);
|
||||
|
||||
/* rt->rngDscale = (jsdouble)(1L << 54) */
|
||||
LL_SHL(tmp2, tmp, 54);
|
||||
LL_L2D(rt->rngDscale, tmp2);
|
||||
JSLL_SHL(tmp2, tmp, 54);
|
||||
JSLL_L2D(rt->rngDscale, tmp2);
|
||||
|
||||
/* Finally, set the seed from current time. */
|
||||
random_setSeed(rt, PRMJ_Now());
|
||||
@@ -280,12 +280,12 @@ random_next(JSRuntime *rt, int bits)
|
||||
int64 nextseed, tmp;
|
||||
uint32 retval;
|
||||
|
||||
LL_MUL(nextseed, rt->rngSeed, rt->rngMultiplier);
|
||||
LL_ADD(nextseed, nextseed, rt->rngAddend);
|
||||
LL_AND(nextseed, nextseed, rt->rngMask);
|
||||
JSLL_MUL(nextseed, rt->rngSeed, rt->rngMultiplier);
|
||||
JSLL_ADD(nextseed, nextseed, rt->rngAddend);
|
||||
JSLL_AND(nextseed, nextseed, rt->rngMask);
|
||||
rt->rngSeed = nextseed;
|
||||
LL_USHR(tmp, nextseed, 48 - bits);
|
||||
LL_L2I(retval, tmp);
|
||||
JSLL_USHR(tmp, nextseed, 48 - bits);
|
||||
JSLL_L2I(retval, tmp);
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -295,10 +295,10 @@ random_nextDouble(JSRuntime *rt)
|
||||
int64 tmp, tmp2;
|
||||
jsdouble d;
|
||||
|
||||
LL_ISHL(tmp, random_next(rt, 27), 27);
|
||||
LL_UI2L(tmp2, random_next(rt, 27));
|
||||
LL_ADD(tmp, tmp, tmp2);
|
||||
LL_L2D(d, tmp);
|
||||
JSLL_ISHL(tmp, random_next(rt, 27), 27);
|
||||
JSLL_UI2L(tmp2, random_next(rt, 27));
|
||||
JSLL_ADD(tmp, tmp, tmp2);
|
||||
JSLL_L2D(d, tmp);
|
||||
return d / rt->rngDscale;
|
||||
}
|
||||
|
||||
@@ -405,7 +405,7 @@ js_InitMathClass(JSContext *cx, JSObject *obj)
|
||||
JSObject *proto;
|
||||
|
||||
proto = JS_InitClass(cx, obj, NULL, &math_class, NULL, 0,
|
||||
NULL, math_methods, NULL, math_static_methods);
|
||||
NULL, math_methods, NULL, math_static_methods);
|
||||
if (!proto)
|
||||
return NULL;
|
||||
if (!JS_DefineConstDoubles(cx, proto, math_constants))
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
* JS math functions.
|
||||
*/
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
extern JSObject *
|
||||
js_InitMathClass(JSContext *cx, JSObject *obj);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsmath_h___ */
|
||||
|
||||
@@ -27,10 +27,11 @@
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "prlog.h"
|
||||
#include "prdtoa.h"
|
||||
#include "prprf.h"
|
||||
#include "jstypes.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#include "jsdtoa.h"
|
||||
#include "jsprf.h"
|
||||
#include "jsapi.h"
|
||||
#include "jsatom.h"
|
||||
#include "jscntxt.h"
|
||||
@@ -86,10 +87,10 @@ num_parseFloat(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
if (!js_strtod(cx, str->chars, &ep, &d))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
if (ep == str->chars) {
|
||||
*rval = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
|
||||
return JS_TRUE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
return js_NewNumberValue(cx, d, rval);
|
||||
}
|
||||
@@ -111,17 +112,17 @@ num_parseInt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
if (!js_ValueToECMAInt32(cx, argv[1], &radix))
|
||||
return JS_FALSE;
|
||||
} else
|
||||
radix = 0;
|
||||
radix = 0;
|
||||
|
||||
if (radix != 0 && (radix < 2 || radix > 36)) {
|
||||
*rval = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
|
||||
return JS_TRUE;
|
||||
*rval = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
|
||||
return JS_TRUE;
|
||||
}
|
||||
if (!js_strtointeger(cx, str->chars, &ep, radix, &d))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
if (ep == str->chars) {
|
||||
*rval = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
|
||||
return JS_TRUE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
return js_NewNumberValue(cx, d, rval);
|
||||
}
|
||||
@@ -180,11 +181,11 @@ num_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
if (!JSVAL_IS_NUMBER(v))
|
||||
return js_obj_toSource(cx, obj, argc, argv, rval);
|
||||
d = JSVAL_IS_INT(v) ? (jsdouble)JSVAL_TO_INT(v) : *JSVAL_TO_DOUBLE(v);
|
||||
i = PR_snprintf(buf, sizeof buf, "(new %s(", number_class.name);
|
||||
i = JS_snprintf(buf, sizeof buf, "(new %s(", number_class.name);
|
||||
|
||||
PR_cnvtf(buf + i, sizeof buf - i, 20, d);
|
||||
i = strlen(buf);
|
||||
PR_snprintf(buf + i, sizeof buf - i, "))");
|
||||
JS_snprintf(buf + i, sizeof buf - i, "))");
|
||||
str = JS_NewStringCopyZ(cx, buf);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
@@ -212,7 +213,10 @@ num_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
if (!js_ValueToECMAInt32(cx, argv[0], &base))
|
||||
return JS_FALSE;
|
||||
if (base < 2 || base > 36) {
|
||||
JS_ReportError(cx, "illegal radix %d", base);
|
||||
char numBuf[12];
|
||||
JS_snprintf(numBuf, sizeof numBuf, "%ld", (long) base);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_RADIX,
|
||||
numBuf);
|
||||
return JS_FALSE;
|
||||
}
|
||||
if (base != 10 && JSDOUBLE_IS_FINITE(d)) {
|
||||
@@ -427,7 +431,7 @@ js_NumberToString(JSContext *cx, jsdouble d)
|
||||
char buf[32];
|
||||
|
||||
if (JSDOUBLE_IS_INT(d, i)) {
|
||||
PR_snprintf(buf, sizeof buf, "%ld", (long)i);
|
||||
JS_snprintf(buf, sizeof buf, "%ld", (long)i);
|
||||
} else {
|
||||
PR_cnvtf(buf, sizeof buf, 20, d);
|
||||
}
|
||||
@@ -473,8 +477,9 @@ js_ValueToNumber(JSContext *cx, jsval v, jsdouble *dp)
|
||||
str = js_DecompileValueGenerator(cx, v, NULL);
|
||||
badstr:
|
||||
if (str) {
|
||||
JS_ReportError(cx, "%s is not a number",
|
||||
JS_GetStringBytes(str));
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NAN,
|
||||
JS_GetStringBytes(str));
|
||||
|
||||
}
|
||||
return JS_FALSE;
|
||||
#else
|
||||
@@ -491,7 +496,7 @@ js_ValueToECMAInt32(JSContext *cx, jsval v, int32 *ip)
|
||||
jsdouble d;
|
||||
|
||||
if (!js_ValueToNumber(cx, v, &d))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
return js_DoubleToECMAInt32(cx, d, ip);
|
||||
}
|
||||
|
||||
@@ -502,15 +507,15 @@ js_DoubleToECMAInt32(JSContext *cx, jsdouble d, int32 *ip)
|
||||
jsdouble two31 = 2147483648.0;
|
||||
|
||||
if (!JSDOUBLE_IS_FINITE(d) || d == 0) {
|
||||
*ip = 0;
|
||||
return JS_TRUE;
|
||||
*ip = 0;
|
||||
return JS_TRUE;
|
||||
}
|
||||
d = fmod(d, two32);
|
||||
d = d >= 0 ? d : d + two32;
|
||||
if (d >= two31)
|
||||
*ip = (int32)(d - two32);
|
||||
*ip = (int32)(d - two32);
|
||||
else
|
||||
*ip = (int32)d;
|
||||
*ip = (int32)d;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
@@ -520,7 +525,7 @@ js_ValueToECMAUint32(JSContext *cx, jsval v, uint32 *ip)
|
||||
jsdouble d;
|
||||
|
||||
if (!js_ValueToNumber(cx, v, &d))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
return js_DoubleToECMAUint32(cx, d, ip);
|
||||
}
|
||||
|
||||
@@ -531,8 +536,8 @@ js_DoubleToECMAUint32(JSContext *cx, jsdouble d, uint32 *ip)
|
||||
jsdouble two32 = 4294967296.0;
|
||||
|
||||
if (!JSDOUBLE_IS_FINITE(d) || d == 0) {
|
||||
*ip = 0;
|
||||
return JS_TRUE;
|
||||
*ip = 0;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
neg = (d < 0);
|
||||
@@ -557,8 +562,9 @@ js_ValueToInt32(JSContext *cx, jsval v, int32 *ip)
|
||||
if (JSDOUBLE_IS_NaN(d) || d <= -2147483649.0 || 2147483648.0 <= d) {
|
||||
str = js_DecompileValueGenerator(cx, v, NULL);
|
||||
if (str) {
|
||||
JS_ReportError(cx, "can't convert %s to an integer",
|
||||
JS_GetStringBytes(str));
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_CANT_CONVERT, JS_GetStringBytes(str));
|
||||
|
||||
}
|
||||
return JS_FALSE;
|
||||
}
|
||||
@@ -587,7 +593,7 @@ js_ValueToUint16(JSContext *cx, jsval v, uint16 *ip)
|
||||
neg = (d < 0);
|
||||
d = floor(neg ? -d : d);
|
||||
d = neg ? -d : d;
|
||||
m = PR_BIT(16);
|
||||
m = JS_BIT(16);
|
||||
d = fmod(d, m);
|
||||
if (d < 0)
|
||||
d += m;
|
||||
@@ -636,10 +642,10 @@ js_strtod(JSContext *cx, const jschar *s, const jschar **ep, jsdouble *dp)
|
||||
|
||||
istr = cstr;
|
||||
if ((negative = (*istr == '-')) != 0 || *istr == '+')
|
||||
istr++;
|
||||
istr++;
|
||||
if (!strncmp(istr, "Infinity", 8)) {
|
||||
d = *(negative ? cx->runtime->jsNegativeInfinity : cx->runtime->jsPositiveInfinity);
|
||||
estr = istr + 8;
|
||||
d = *(negative ? cx->runtime->jsNegativeInfinity : cx->runtime->jsPositiveInfinity);
|
||||
estr = istr + 8;
|
||||
} else {
|
||||
errno = 0;
|
||||
d = PR_strtod(cstr, &estr);
|
||||
@@ -648,6 +654,16 @@ js_strtod(JSContext *cx, const jschar *s, const jschar **ep, jsdouble *dp)
|
||||
d = *cx->runtime->jsPositiveInfinity;
|
||||
else if (d == -HUGE_VAL)
|
||||
d = *cx->runtime->jsNegativeInfinity;
|
||||
#ifdef HPUX
|
||||
if (d == 0.0 && negative) {
|
||||
/*
|
||||
* "-0", "-1e-2000" come out as positive zero
|
||||
* here on HPUX. Force a negative zero instead.
|
||||
*/
|
||||
JSDOUBLE_HI32(d) = JSDOUBLE_HI32_SIGNBIT;
|
||||
JSDOUBLE_LO32(d) = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
free(cstr);
|
||||
@@ -672,18 +688,18 @@ static intN GetNextBinaryDigit(struct BinaryDigitReader *bdr)
|
||||
intN bit;
|
||||
|
||||
if (bdr->digitMask == 0) {
|
||||
uintN c;
|
||||
uintN c;
|
||||
|
||||
if (bdr->digits == bdr->end)
|
||||
return -1;
|
||||
if (bdr->digits == bdr->end)
|
||||
return -1;
|
||||
|
||||
c = *bdr->digits++;
|
||||
if ('0' <= c && c <= '9')
|
||||
bdr->digit = c - '0';
|
||||
else if ('a' <= c && c <= 'z')
|
||||
bdr->digit = c - 'a' + 10;
|
||||
else bdr->digit = c - 'A' + 10;
|
||||
bdr->digitMask = bdr->base >> 1;
|
||||
c = *bdr->digits++;
|
||||
if ('0' <= c && c <= '9')
|
||||
bdr->digit = c - '0';
|
||||
else if ('a' <= c && c <= 'z')
|
||||
bdr->digit = c - 'a' + 10;
|
||||
else bdr->digit = c - 'A' + 10;
|
||||
bdr->digitMask = bdr->base >> 1;
|
||||
}
|
||||
bit = (bdr->digit & bdr->digitMask) != 0;
|
||||
bdr->digitMask >>= 1;
|
||||
@@ -699,22 +715,22 @@ js_strtointeger(JSContext *cx, const jschar *s, const jschar **ep, jsint base, j
|
||||
const jschar *s1 = js_SkipWhiteSpace(s);
|
||||
|
||||
if ((negative = (*s1 == '-')) != 0 || *s1 == '+')
|
||||
s1++;
|
||||
s1++;
|
||||
|
||||
if (base == 0)
|
||||
/* No base supplied, or some base that evaluated to 0. */
|
||||
if (*s1 == '0')
|
||||
/* It's either hex or octal; only increment char if str isn't '0' */
|
||||
if (s1[1] == 'X' || s1[1] == 'x') { /* Hex */
|
||||
s1 += 2;
|
||||
base = 16;
|
||||
} else /* Octal */
|
||||
base = 8;
|
||||
else
|
||||
base = 10; /* Default to decimal. */
|
||||
/* No base supplied, or some base that evaluated to 0. */
|
||||
if (*s1 == '0')
|
||||
/* It's either hex or octal; only increment char if str isn't '0' */
|
||||
if (s1[1] == 'X' || s1[1] == 'x') { /* Hex */
|
||||
s1 += 2;
|
||||
base = 16;
|
||||
} else /* Octal */
|
||||
base = 8;
|
||||
else
|
||||
base = 10; /* Default to decimal. */
|
||||
else if (base == 16 && *s1 == '0' && (s1[1] == 'X' || s1[1] == 'x'))
|
||||
/* If base is 16, ignore hex prefix. */
|
||||
s1 += 2;
|
||||
/* If base is 16, ignore hex prefix. */
|
||||
s1 += 2;
|
||||
|
||||
/* Done with the preliminaries; find some prefix of the string that's
|
||||
* a number in the given base.
|
||||
@@ -722,24 +738,24 @@ js_strtointeger(JSContext *cx, const jschar *s, const jschar **ep, jsint base, j
|
||||
start = s1; /* Mark - if string is empty, we return NaN. */
|
||||
value = 0.0;
|
||||
while (1) {
|
||||
uintN digit;
|
||||
jschar c = *s1;
|
||||
if ('0' <= c && c <= '9')
|
||||
digit = c - '0';
|
||||
else if ('a' <= c && c <= 'z')
|
||||
digit = c - 'a' + 10;
|
||||
else if ('A' <= c && c <= 'Z')
|
||||
digit = c - 'A' + 10;
|
||||
else
|
||||
break;
|
||||
if (digit >= (uintN)base)
|
||||
break;
|
||||
value = value*base + digit;
|
||||
s1++;
|
||||
uintN digit;
|
||||
jschar c = *s1;
|
||||
if ('0' <= c && c <= '9')
|
||||
digit = c - '0';
|
||||
else if ('a' <= c && c <= 'z')
|
||||
digit = c - 'a' + 10;
|
||||
else if ('A' <= c && c <= 'Z')
|
||||
digit = c - 'A' + 10;
|
||||
else
|
||||
break;
|
||||
if (digit >= (uintN)base)
|
||||
break;
|
||||
value = value*base + digit;
|
||||
s1++;
|
||||
}
|
||||
|
||||
if (value >= 9007199254740992.0)
|
||||
if (base == 10) {
|
||||
if (base == 10) {
|
||||
/* If we're accumulating a decimal number and the number is >= 2^53, then
|
||||
* the result from the repeated multiply-add above may be inaccurate. Call
|
||||
* PR_strtod to get the correct answer.
|
||||
@@ -750,15 +766,15 @@ js_strtointeger(JSContext *cx, const jschar *s, const jschar **ep, jsint base, j
|
||||
char *estr;
|
||||
|
||||
if (!cstr)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
for (i = 0; i != length; i++)
|
||||
cstr[i] = (char)start[i];
|
||||
cstr[i] = (char)start[i];
|
||||
cstr[length] = 0;
|
||||
|
||||
errno = 0;
|
||||
value = PR_strtod(cstr, &estr);
|
||||
if (errno == ERANGE && value == HUGE_VAL)
|
||||
value = *cx->runtime->jsPositiveInfinity;
|
||||
value = *cx->runtime->jsPositiveInfinity;
|
||||
free(cstr);
|
||||
|
||||
} else if (base == 2 || base == 4 || base == 8 || base == 16 || base == 32) {
|
||||
@@ -783,43 +799,43 @@ js_strtointeger(JSContext *cx, const jschar *s, const jschar **ep, jsint base, j
|
||||
|
||||
/* Skip leading zeros. */
|
||||
do {
|
||||
bit = GetNextBinaryDigit(&bdr);
|
||||
bit = GetNextBinaryDigit(&bdr);
|
||||
} while (bit == 0);
|
||||
|
||||
if (bit == 1) {
|
||||
/* Gather the 53 significant bits (including the leading 1) */
|
||||
value = 1.0;
|
||||
for (j = 52; j; j--) {
|
||||
bit = GetNextBinaryDigit(&bdr);
|
||||
if (bit < 0)
|
||||
goto done;
|
||||
value = value*2 + bit;
|
||||
}
|
||||
/* bit2 is the 54th bit (the first dropped from the mantissa) */
|
||||
bit2 = GetNextBinaryDigit(&bdr);
|
||||
if (bit2 >= 0) {
|
||||
jsdouble factor = 2.0;
|
||||
intN sticky = 0; /* sticky is 1 if any bit beyond the 54th is 1 */
|
||||
intN bit3;
|
||||
/* Gather the 53 significant bits (including the leading 1) */
|
||||
value = 1.0;
|
||||
for (j = 52; j; j--) {
|
||||
bit = GetNextBinaryDigit(&bdr);
|
||||
if (bit < 0)
|
||||
goto done;
|
||||
value = value*2 + bit;
|
||||
}
|
||||
/* bit2 is the 54th bit (the first dropped from the mantissa) */
|
||||
bit2 = GetNextBinaryDigit(&bdr);
|
||||
if (bit2 >= 0) {
|
||||
jsdouble factor = 2.0;
|
||||
intN sticky = 0; /* sticky is 1 if any bit beyond the 54th is 1 */
|
||||
intN bit3;
|
||||
|
||||
while ((bit3 = GetNextBinaryDigit(&bdr)) >= 0) {
|
||||
sticky |= bit3;
|
||||
factor *= 2;
|
||||
}
|
||||
value += bit2 & (bit | sticky);
|
||||
value *= factor;
|
||||
}
|
||||
while ((bit3 = GetNextBinaryDigit(&bdr)) >= 0) {
|
||||
sticky |= bit3;
|
||||
factor *= 2;
|
||||
}
|
||||
value += bit2 & (bit | sticky);
|
||||
value *= factor;
|
||||
}
|
||||
done:;
|
||||
}
|
||||
}
|
||||
/* We don't worry about inaccurate numbers for any other base. */
|
||||
|
||||
if (s1 == start) {
|
||||
*dp = 0.0;
|
||||
*ep = s;
|
||||
*dp = 0.0;
|
||||
*ep = s;
|
||||
} else {
|
||||
*dp = negative ? -value : value;
|
||||
*ep = s1;
|
||||
*dp = negative ? -value : value;
|
||||
*ep = s1;
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
* wraps it with a JSObject whose valueOf method returns the unwrapped number.
|
||||
*/
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
#ifdef IS_LITTLE_ENDIAN
|
||||
#define JSDOUBLE_HI32(x) (((uint32 *)&(x))[1])
|
||||
@@ -64,7 +64,7 @@ PR_BEGIN_EXTERN_C
|
||||
* comparisons under MSVC.
|
||||
*/
|
||||
#define JSDOUBLE_IS_INT(d, i) (JSDOUBLE_IS_FINITE(d) && !JSDOUBLE_IS_NEGZERO(d) \
|
||||
&& ((d) == (i = (jsint)(d))))
|
||||
&& ((d) == (i = (jsint)(d))))
|
||||
|
||||
/* Initialize the Number class, returning its prototype object. */
|
||||
extern JSObject *
|
||||
@@ -162,6 +162,6 @@ js_strtod(JSContext *cx, const jschar *s, const jschar **ep, jsdouble *dp);
|
||||
extern JSBool
|
||||
js_strtointeger(JSContext *cx, const jschar *s, const jschar **ep, jsint radix, jsdouble *dp);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsnum_h___ */
|
||||
|
||||
@@ -22,19 +22,24 @@
|
||||
#include "jsstddef.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "jstypes.h"
|
||||
#ifndef NSPR20
|
||||
#include "prarena.h"
|
||||
#include "jsarena.h"
|
||||
#else
|
||||
#include "plarena.h"
|
||||
/* Removed by JSIFY: #include "plarena.h"
|
||||
*/
|
||||
#include "jsarena.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "prlog.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#ifndef NSPR20
|
||||
#include "prhash.h"
|
||||
#include "jshash.h"
|
||||
#else
|
||||
#include "plhash.h"
|
||||
/* Removed by JSIFY: #include "JShash.h"
|
||||
*/
|
||||
#include "jshash.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "prprf.h"
|
||||
#include "jsprf.h"
|
||||
#include "jsapi.h"
|
||||
#include "jsatom.h"
|
||||
#include "jsbool.h"
|
||||
@@ -99,7 +104,7 @@ JSClass js_ObjectClass = {
|
||||
static JSBool
|
||||
obj_getSlot(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
|
||||
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
STATIC_DLL_CALLBACK(JSBool)
|
||||
obj_setSlot(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
|
||||
|
||||
static JSBool
|
||||
@@ -134,7 +139,7 @@ obj_getSlot(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
STATIC_DLL_CALLBACK(JSBool)
|
||||
obj_setSlot(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
JSObject *obj2;
|
||||
@@ -146,7 +151,8 @@ obj_setSlot(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
slot = JSVAL_TO_INT(id);
|
||||
while (obj2) {
|
||||
if (obj2 == obj) {
|
||||
JS_ReportError(cx, "cyclic %s value", object_props[slot].name);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_CYCLIC_VALUE, object_props[slot].name);
|
||||
return JS_FALSE;
|
||||
}
|
||||
obj2 = JSVAL_TO_OBJECT(OBJ_GET_SLOT(cx, obj2, slot));
|
||||
@@ -165,17 +171,17 @@ obj_getCount(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
|
||||
/* Get the number of properties to enumerate. */
|
||||
if (!OBJ_ENUMERATE(cx, obj, JSENUMERATE_INIT, &iter_state, &num_properties))
|
||||
goto error;
|
||||
goto error;
|
||||
if (!JSVAL_IS_INT(num_properties)) {
|
||||
PR_ASSERT(0);
|
||||
goto error;
|
||||
JS_ASSERT(0);
|
||||
goto error;
|
||||
}
|
||||
*vp = num_properties;
|
||||
return JS_TRUE;
|
||||
|
||||
error:
|
||||
if (iter_state != JSVAL_NULL)
|
||||
OBJ_ENUMERATE(cx, obj, JSENUMERATE_DESTROY, &iter_state, 0);
|
||||
OBJ_ENUMERATE(cx, obj, JSENUMERATE_DESTROY, &iter_state, 0);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@@ -185,19 +191,19 @@ error:
|
||||
|
||||
#endif /* !JS_HAS_OBJ_PROTO_PROP */
|
||||
|
||||
PR_STATIC_CALLBACK(PRHashNumber)
|
||||
STATIC_DLL_CALLBACK(JSHashNumber)
|
||||
js_hash_object(const void *key)
|
||||
{
|
||||
return (PRHashNumber)key >> JSVAL_TAGBITS;
|
||||
return (JSHashNumber)key >> JSVAL_TAGBITS;
|
||||
}
|
||||
|
||||
static PRHashEntry *
|
||||
static JSHashEntry *
|
||||
MarkSharpObjects(JSContext *cx, JSObject *obj, JSIdArray **idap)
|
||||
{
|
||||
JSSharpObjectMap *map;
|
||||
PRHashTable *table;
|
||||
PRHashNumber hash;
|
||||
PRHashEntry **hep, *he;
|
||||
JSHashTable *table;
|
||||
JSHashNumber hash;
|
||||
JSHashEntry **hep, *he;
|
||||
jsatomid sharpid;
|
||||
JSIdArray *ida;
|
||||
JSBool ok;
|
||||
@@ -207,11 +213,11 @@ MarkSharpObjects(JSContext *cx, JSObject *obj, JSIdArray **idap)
|
||||
map = &cx->sharpObjectMap;
|
||||
table = map->table;
|
||||
hash = js_hash_object(obj);
|
||||
hep = PR_HashTableRawLookup(table, hash, obj);
|
||||
hep = JS_HashTableRawLookup(table, hash, obj);
|
||||
he = *hep;
|
||||
if (!he) {
|
||||
sharpid = 0;
|
||||
he = PR_HashTableRawAdd(table, hep, hash, obj, (void *)sharpid);
|
||||
he = JS_HashTableRawAdd(table, hep, hash, obj, (void *)sharpid);
|
||||
if (!he) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return NULL;
|
||||
@@ -223,7 +229,7 @@ MarkSharpObjects(JSContext *cx, JSObject *obj, JSIdArray **idap)
|
||||
for (i = 0, length = ida->length; i < length; i++) {
|
||||
ok = OBJ_GET_PROPERTY(cx, obj, ida->vector[i], &val);
|
||||
if (!ok)
|
||||
break;
|
||||
break;
|
||||
if (!JSVAL_IS_PRIMITIVE(val) &&
|
||||
!MarkSharpObjects(cx, JSVAL_TO_OBJECT(val), NULL)) {
|
||||
ok = JS_FALSE;
|
||||
@@ -247,15 +253,15 @@ MarkSharpObjects(JSContext *cx, JSObject *obj, JSIdArray **idap)
|
||||
return he;
|
||||
}
|
||||
|
||||
PRHashEntry *
|
||||
JSHashEntry *
|
||||
js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap,
|
||||
jschar **sp)
|
||||
{
|
||||
JSSharpObjectMap *map;
|
||||
PRHashTable *table;
|
||||
JSHashTable *table;
|
||||
JSIdArray *ida;
|
||||
PRHashNumber hash;
|
||||
PRHashEntry *he, **hep;
|
||||
JSHashNumber hash;
|
||||
JSHashEntry *he, **hep;
|
||||
jsatomid sharpid;
|
||||
char buf[20];
|
||||
size_t len;
|
||||
@@ -263,8 +269,8 @@ js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap,
|
||||
map = &cx->sharpObjectMap;
|
||||
table = map->table;
|
||||
if (!table) {
|
||||
table = PR_NewHashTable(8, js_hash_object, PR_CompareValues,
|
||||
PR_CompareValues, NULL, NULL);
|
||||
table = JS_NewHashTable(8, js_hash_object, JS_CompareValues,
|
||||
JS_CompareValues, NULL, NULL);
|
||||
if (!table) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return NULL;
|
||||
@@ -277,37 +283,37 @@ js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap,
|
||||
he = MarkSharpObjects(cx, obj, &ida);
|
||||
if (!he)
|
||||
return NULL;
|
||||
PR_ASSERT((((jsatomid) he->value) & SHARP_BIT) == 0);
|
||||
JS_ASSERT((((jsatomid) he->value) & SHARP_BIT) == 0);
|
||||
if (!idap) {
|
||||
JS_DestroyIdArray(cx, ida);
|
||||
ida = NULL;
|
||||
}
|
||||
} else {
|
||||
hash = js_hash_object(obj);
|
||||
hep = PR_HashTableRawLookup(table, hash, obj);
|
||||
he = *hep;
|
||||
hash = js_hash_object(obj);
|
||||
hep = JS_HashTableRawLookup(table, hash, obj);
|
||||
he = *hep;
|
||||
|
||||
/*
|
||||
* It's possible that the value of a property has changed from the
|
||||
* first time the object's properties are traversed (when the property
|
||||
* ids are entered into the hash table) to the second (when they are
|
||||
* converted to strings), i.e. the getProperty() call is not
|
||||
* idempotent.
|
||||
*/
|
||||
if (!he) {
|
||||
he = PR_HashTableRawAdd(table, hep, hash, obj, (void *)0);
|
||||
/*
|
||||
* It's possible that the value of a property has changed from the
|
||||
* first time the object's properties are traversed (when the property
|
||||
* ids are entered into the hash table) to the second (when they are
|
||||
* converted to strings), i.e. the getProperty() call is not
|
||||
* idempotent.
|
||||
*/
|
||||
if (!he) {
|
||||
he = JS_HashTableRawAdd(table, hep, hash, obj, (void *)0);
|
||||
if (!he)
|
||||
JS_ReportOutOfMemory(cx);
|
||||
*sp = NULL;
|
||||
goto out;
|
||||
}
|
||||
JS_ReportOutOfMemory(cx);
|
||||
*sp = NULL;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
sharpid = (jsatomid) he->value;
|
||||
if (sharpid == 0) {
|
||||
*sp = NULL;
|
||||
} else {
|
||||
len = PR_snprintf(buf, sizeof buf, "#%u%c",
|
||||
len = JS_snprintf(buf, sizeof buf, "#%u%c",
|
||||
sharpid >> 1, (sharpid & SHARP_BIT) ? '#' : '=');
|
||||
*sp = js_InflateString(cx, buf, len);
|
||||
if (!*sp) {
|
||||
@@ -319,7 +325,7 @@ js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap,
|
||||
|
||||
out:
|
||||
if ((sharpid & SHARP_BIT) == 0) {
|
||||
if (idap && !ida) {
|
||||
if (idap && !ida) {
|
||||
ida = JS_Enumerate(cx, obj);
|
||||
if (!ida) {
|
||||
if (*sp) {
|
||||
@@ -344,10 +350,10 @@ js_LeaveSharpObject(JSContext *cx, JSIdArray **idap)
|
||||
JSIdArray *ida;
|
||||
|
||||
map = &cx->sharpObjectMap;
|
||||
PR_ASSERT(map->depth > 0);
|
||||
JS_ASSERT(map->depth > 0);
|
||||
if (--map->depth == 0) {
|
||||
map->sharpgen = 0;
|
||||
PR_HashTableDestroy(map->table);
|
||||
JS_HashTableDestroy(map->table);
|
||||
map->table = NULL;
|
||||
}
|
||||
if (idap) {
|
||||
@@ -366,7 +372,7 @@ JSBool
|
||||
js_obj_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *rval)
|
||||
{
|
||||
PRHashEntry *he;
|
||||
JSHashEntry *he;
|
||||
JSIdArray *ida;
|
||||
jschar *chars, *ochars, *vchars, *vsharp;
|
||||
size_t nchars, vlength, vsharplength;
|
||||
@@ -381,7 +387,7 @@ js_obj_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
if (!he)
|
||||
return JS_FALSE;
|
||||
if (IS_SHARP(he)) { /* we didn't enter -- obj is already sharp */
|
||||
PR_ASSERT(!ida);
|
||||
JS_ASSERT(!ida);
|
||||
#if JS_HAS_SHARP_VARS
|
||||
nchars = js_strlen(chars);
|
||||
#else
|
||||
@@ -392,7 +398,7 @@ js_obj_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
#endif
|
||||
goto make_string;
|
||||
}
|
||||
PR_ASSERT(ida);
|
||||
JS_ASSERT(ida);
|
||||
ok = JS_TRUE;
|
||||
|
||||
/* Allocate 2 + 1 for "{}" and the terminator. */
|
||||
@@ -461,8 +467,8 @@ js_obj_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
goto done;
|
||||
}
|
||||
if (IS_SHARP(he)) {
|
||||
vchars = vsharp;
|
||||
vlength = js_strlen(vchars);
|
||||
vchars = vsharp;
|
||||
vlength = js_strlen(vchars);
|
||||
} else {
|
||||
if (vsharp) {
|
||||
vsharplength = js_strlen(vsharp);
|
||||
@@ -609,9 +615,9 @@ obj_eval(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
*/
|
||||
scopeobj = NULL;
|
||||
if (argc >= 2) {
|
||||
if (!js_ValueToObject(cx, argv[1], &scopeobj))
|
||||
if (!js_ValueToObject(cx, argv[1], &scopeobj))
|
||||
return JS_FALSE;
|
||||
argv[1] = OBJECT_TO_JSVAL(scopeobj);
|
||||
argv[1] = OBJECT_TO_JSVAL(scopeobj);
|
||||
}
|
||||
if (!scopeobj)
|
||||
#endif
|
||||
@@ -755,15 +761,15 @@ static JSBool
|
||||
Object(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
if (argc == 0) {
|
||||
/* Trigger logic below to construct a blank object. */
|
||||
obj = NULL;
|
||||
/* Trigger logic below to construct a blank object. */
|
||||
obj = NULL;
|
||||
} else {
|
||||
/* If argv[0] is null or undefined, obj comes back null. */
|
||||
if (!js_ValueToObject(cx, argv[0], &obj))
|
||||
return JS_FALSE;
|
||||
}
|
||||
if (!obj) {
|
||||
PR_ASSERT(!argc || JSVAL_IS_NULL(argv[0]) || JSVAL_IS_VOID(argv[0]));
|
||||
JS_ASSERT(!argc || JSVAL_IS_NULL(argv[0]) || JSVAL_IS_VOID(argv[0]));
|
||||
if (cx->fp->constructing)
|
||||
return JS_TRUE;
|
||||
obj = js_NewObject(cx, &js_ObjectClass, NULL, NULL);
|
||||
@@ -787,7 +793,7 @@ with_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
|
||||
{
|
||||
JSObject *proto = OBJ_GET_PROTO(cx, obj);
|
||||
if (!proto)
|
||||
return js_LookupProperty(cx, obj, id, objp, propp);
|
||||
return js_LookupProperty(cx, obj, id, objp, propp);
|
||||
return OBJ_LOOKUP_PROPERTY(cx, proto, id, objp, propp);
|
||||
}
|
||||
|
||||
@@ -796,7 +802,7 @@ with_GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
{
|
||||
JSObject *proto = OBJ_GET_PROTO(cx, obj);
|
||||
if (!proto)
|
||||
return js_GetProperty(cx, obj, id, vp);
|
||||
return js_GetProperty(cx, obj, id, vp);
|
||||
return OBJ_GET_PROPERTY(cx, proto, id, vp);
|
||||
}
|
||||
|
||||
@@ -805,7 +811,7 @@ with_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
{
|
||||
JSObject *proto = OBJ_GET_PROTO(cx, obj);
|
||||
if (!proto)
|
||||
return js_SetProperty(cx, obj, id, vp);
|
||||
return js_SetProperty(cx, obj, id, vp);
|
||||
return OBJ_SET_PROPERTY(cx, proto, id, vp);
|
||||
}
|
||||
|
||||
@@ -815,7 +821,7 @@ with_GetAttributes(JSContext *cx, JSObject *obj, jsid id, JSProperty *prop,
|
||||
{
|
||||
JSObject *proto = OBJ_GET_PROTO(cx, obj);
|
||||
if (!proto)
|
||||
return js_GetAttributes(cx, obj, id, prop, attrsp);
|
||||
return js_GetAttributes(cx, obj, id, prop, attrsp);
|
||||
return OBJ_GET_ATTRIBUTES(cx, proto, id, prop, attrsp);
|
||||
}
|
||||
|
||||
@@ -825,7 +831,7 @@ with_SetAttributes(JSContext *cx, JSObject *obj, jsid id, JSProperty *prop,
|
||||
{
|
||||
JSObject *proto = OBJ_GET_PROTO(cx, obj);
|
||||
if (!proto)
|
||||
return js_SetAttributes(cx, obj, id, prop, attrsp);
|
||||
return js_SetAttributes(cx, obj, id, prop, attrsp);
|
||||
return OBJ_SET_ATTRIBUTES(cx, proto, id, prop, attrsp);
|
||||
}
|
||||
|
||||
@@ -834,7 +840,7 @@ with_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, jsval *rval)
|
||||
{
|
||||
JSObject *proto = OBJ_GET_PROTO(cx, obj);
|
||||
if (!proto)
|
||||
return js_DeleteProperty(cx, obj, id, rval);
|
||||
return js_DeleteProperty(cx, obj, id, rval);
|
||||
return OBJ_DELETE_PROPERTY(cx, proto, id, rval);
|
||||
}
|
||||
|
||||
@@ -849,11 +855,11 @@ with_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp)
|
||||
|
||||
static JSBool
|
||||
with_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
jsval *statep, jsid *idp)
|
||||
jsval *statep, jsid *idp)
|
||||
{
|
||||
JSObject *proto = OBJ_GET_PROTO(cx, obj);
|
||||
if (!proto)
|
||||
return js_Enumerate(cx, obj, enum_op, statep, idp);
|
||||
return js_Enumerate(cx, obj, enum_op, statep, idp);
|
||||
return OBJ_ENUMERATE(cx, proto, enum_op, statep, idp);
|
||||
}
|
||||
|
||||
@@ -863,7 +869,7 @@ with_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
|
||||
{
|
||||
JSObject *proto = OBJ_GET_PROTO(cx, obj);
|
||||
if (!proto)
|
||||
return js_CheckAccess(cx, obj, id, mode, vp, attrsp);
|
||||
return js_CheckAccess(cx, obj, id, mode, vp, attrsp);
|
||||
return OBJ_CHECK_ACCESS(cx, proto, id, mode, vp, attrsp);
|
||||
}
|
||||
|
||||
@@ -872,11 +878,11 @@ with_ThisObject(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
JSObject *proto = OBJ_GET_PROTO(cx, obj);
|
||||
if (!proto)
|
||||
return obj;
|
||||
return obj;
|
||||
return OBJ_THIS_OBJECT(cx, proto);
|
||||
}
|
||||
|
||||
static JSObjectOps with_object_ops = {
|
||||
JS_FRIEND_DATA(JSObjectOps) js_WithObjectOps = {
|
||||
js_NewObjectMap, js_DestroyObjectMap,
|
||||
with_LookupProperty, js_DefineProperty,
|
||||
with_GetProperty, with_SetProperty,
|
||||
@@ -889,7 +895,7 @@ static JSObjectOps with_object_ops = {
|
||||
static JSObjectOps *
|
||||
with_getObjectOps(JSContext *cx, JSClass *clasp)
|
||||
{
|
||||
return &with_object_ops;
|
||||
return &js_WithObjectOps;
|
||||
}
|
||||
|
||||
JSClass js_WithClass = {
|
||||
@@ -937,7 +943,7 @@ js_InitObjectClass(JSContext *cx, JSObject *obj)
|
||||
JSObject *proto;
|
||||
|
||||
#if JS_HAS_SHARP_VARS
|
||||
PR_ASSERT(sizeof(jsatomid) * PR_BITS_PER_BYTE >= ATOM_INDEX_LIMIT_LOG2 + 1);
|
||||
JS_ASSERT(sizeof(jsatomid) * JS_BITS_PER_BYTE >= ATOM_INDEX_LIMIT_LOG2 + 1);
|
||||
#endif
|
||||
|
||||
proto = JS_InitClass(cx, obj, NULL, &js_ObjectClass, Object, 1,
|
||||
@@ -977,7 +983,7 @@ js_DestroyObjectMap(JSContext *cx, JSObjectMap *map)
|
||||
JSObjectMap *
|
||||
js_HoldObjectMap(JSContext *cx, JSObjectMap *map)
|
||||
{
|
||||
PR_ASSERT(map->nrefs >= 0);
|
||||
JS_ASSERT(map->nrefs >= 0);
|
||||
JS_ATOMIC_ADDREF(&map->nrefs, 1);
|
||||
return map;
|
||||
}
|
||||
@@ -985,7 +991,7 @@ js_HoldObjectMap(JSContext *cx, JSObjectMap *map)
|
||||
JSObjectMap *
|
||||
js_DropObjectMap(JSContext *cx, JSObjectMap *map, JSObject *obj)
|
||||
{
|
||||
PR_ASSERT(map->nrefs > 0);
|
||||
JS_ASSERT(map->nrefs > 0);
|
||||
JS_ATOMIC_ADDREF(&map->nrefs, -1);
|
||||
if (map->nrefs == 0) {
|
||||
map->ops->destroyObjectMap(cx, map);
|
||||
@@ -1032,7 +1038,7 @@ js_NewObject(JSContext *cx, JSClass *clasp, JSObject *proto, JSObject *parent)
|
||||
goto bad;
|
||||
}
|
||||
if (JSVAL_IS_OBJECT(cval) && (ctor = JSVAL_TO_OBJECT(cval)) != NULL)
|
||||
parent = OBJ_GET_PARENT(cx, ctor);
|
||||
parent = OBJ_GET_PARENT(cx, ctor);
|
||||
}
|
||||
|
||||
/* Share the given prototype's map. */
|
||||
@@ -1096,7 +1102,7 @@ FindConstructor(JSContext *cx, const char *name, jsval *vp)
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
PR_ASSERT(OBJ_IS_NATIVE(pobj));
|
||||
JS_ASSERT(OBJ_IS_NATIVE(pobj));
|
||||
*vp = OBJ_GET_SLOT(cx, pobj, sprop->slot);
|
||||
OBJ_DROP_PROPERTY(cx, pobj, (JSProperty *)sprop);
|
||||
return JS_TRUE;
|
||||
@@ -1114,7 +1120,7 @@ js_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto,
|
||||
|
||||
ok = FindConstructor(cx, clasp->name, &cval);
|
||||
if (!ok)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* If proto or parent are NULL, set them to Constructor.prototype and/or
|
||||
@@ -1122,15 +1128,15 @@ js_ConstructObject(JSContext *cx, JSClass *clasp, JSObject *proto,
|
||||
*/
|
||||
ctor = JSVAL_TO_OBJECT(cval);
|
||||
if (!parent)
|
||||
parent = OBJ_GET_PARENT(cx, ctor);
|
||||
parent = OBJ_GET_PARENT(cx, ctor);
|
||||
if (!proto) {
|
||||
if (!OBJ_GET_PROPERTY(cx, ctor,
|
||||
(jsid)cx->runtime->atomState.classPrototypeAtom,
|
||||
&rval)) {
|
||||
return NULL;
|
||||
}
|
||||
if (JSVAL_IS_OBJECT(rval))
|
||||
proto = JSVAL_TO_OBJECT(rval);
|
||||
if (!OBJ_GET_PROPERTY(cx, ctor,
|
||||
(jsid)cx->runtime->atomState.classPrototypeAtom,
|
||||
&rval)) {
|
||||
return NULL;
|
||||
}
|
||||
if (JSVAL_IS_OBJECT(rval))
|
||||
proto = JSVAL_TO_OBJECT(rval);
|
||||
}
|
||||
|
||||
obj = js_NewObject(cx, clasp, proto, parent);
|
||||
@@ -1197,7 +1203,7 @@ js_AllocSlot(JSContext *cx, JSObject *obj, uint32 *slotp)
|
||||
map = obj->map;
|
||||
nslots = map->nslots;
|
||||
if (map->freeslot >= nslots) {
|
||||
nslots = PR_MAX(map->freeslot, nslots);
|
||||
nslots = JS_MAX(map->freeslot, nslots);
|
||||
if (nslots < JS_INITIAL_NSLOTS)
|
||||
nslots = JS_INITIAL_NSLOTS;
|
||||
else
|
||||
@@ -1257,10 +1263,10 @@ js_FreeSlot(JSContext *cx, JSObject *obj, uint32 slot)
|
||||
|
||||
#if JS_BUG_EMPTY_INDEX_ZERO
|
||||
#define CHECK_FOR_EMPTY_INDEX(id) \
|
||||
PR_BEGIN_MACRO \
|
||||
JS_BEGIN_MACRO \
|
||||
if (_str->length == 0) \
|
||||
id = JSVAL_ZERO; \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
#else
|
||||
#define CHECK_FOR_EMPTY_INDEX(id) /* nothing */
|
||||
#endif
|
||||
@@ -1269,35 +1275,35 @@ js_FreeSlot(JSContext *cx, JSObject *obj, uint32 slot)
|
||||
#define JSVAL_INT_MAX_STRING "1073741823"
|
||||
|
||||
#define CHECK_FOR_FUNNY_INDEX(id) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (!JSVAL_IS_INT(id)) { \
|
||||
JS_BEGIN_MACRO \
|
||||
if (!JSVAL_IS_INT(id)) { \
|
||||
JSAtom *_atom = (JSAtom *)id; \
|
||||
JSString *_str = ATOM_TO_STRING(_atom); \
|
||||
const jschar *_cp = _str->chars; \
|
||||
if (JS7_ISDEC(*_cp) && \
|
||||
_str->length <= sizeof(JSVAL_INT_MAX_STRING)-1) \
|
||||
{ \
|
||||
_str->length <= sizeof(JSVAL_INT_MAX_STRING)-1) \
|
||||
{ \
|
||||
jsuint _index = JS7_UNDEC(*_cp++); \
|
||||
jsuint _oldIndex = 0; \
|
||||
jsuint _c; \
|
||||
if (_index != 0) { \
|
||||
while (JS7_ISDEC(*_cp)) { \
|
||||
_oldIndex = _index; \
|
||||
_c = JS7_UNDEC(*_cp); \
|
||||
_index = 10*_index + _c; \
|
||||
_cp++; \
|
||||
} \
|
||||
} \
|
||||
if (*_cp == 0 && \
|
||||
(_oldIndex < (JSVAL_INT_MAX / 10) || \
|
||||
(_oldIndex == (JSVAL_INT_MAX / 10) && \
|
||||
_c < (JSVAL_INT_MAX % 10)))) \
|
||||
jsuint _oldIndex = 0; \
|
||||
jsuint _c; \
|
||||
if (_index != 0) { \
|
||||
while (JS7_ISDEC(*_cp)) { \
|
||||
_oldIndex = _index; \
|
||||
_c = JS7_UNDEC(*_cp); \
|
||||
_index = 10*_index + _c; \
|
||||
_cp++; \
|
||||
} \
|
||||
} \
|
||||
if (*_cp == 0 && \
|
||||
(_oldIndex < (JSVAL_INT_MAX / 10) || \
|
||||
(_oldIndex == (JSVAL_INT_MAX / 10) && \
|
||||
_c < (JSVAL_INT_MAX % 10)))) \
|
||||
id = INT_TO_JSVAL(_index); \
|
||||
} else { \
|
||||
CHECK_FOR_EMPTY_INDEX(id); \
|
||||
} \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
|
||||
JSBool
|
||||
@@ -1348,7 +1354,7 @@ js_DefineProperty(JSContext *cx, JSObject *obj, jsid id, jsval value,
|
||||
#ifdef JS_THREADSAFE
|
||||
js_HoldScopeProperty(cx, scope, sprop);
|
||||
#endif
|
||||
*propp = (JSProperty *) sprop;
|
||||
*propp = (JSProperty *) sprop;
|
||||
} else {
|
||||
JS_UNLOCK_OBJ(cx, obj);
|
||||
}
|
||||
@@ -1369,7 +1375,7 @@ js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
|
||||
JSProperty **propp)
|
||||
#endif
|
||||
{
|
||||
PRHashNumber hash;
|
||||
JSHashNumber hash;
|
||||
JSScope *prevscope, *scope;
|
||||
JSSymbol *sym;
|
||||
JSClass *clasp;
|
||||
@@ -1432,7 +1438,7 @@ js_LookupProperty(JSContext *cx, JSObject *obj, jsid id, JSObject **objp,
|
||||
}
|
||||
}
|
||||
if (sym && (sprop = sym_property(sym)) != NULL) {
|
||||
PR_ASSERT((JSScope *)obj->map == scope);
|
||||
JS_ASSERT((JSScope *)obj->map == scope);
|
||||
*objp = scope->object; /* XXXbe hide in jsscope.[ch] */
|
||||
#ifdef JS_THREADSAFE
|
||||
js_HoldScopeProperty(cx, scope, sprop);
|
||||
@@ -1470,7 +1476,7 @@ js_FindProperty(JSContext *cx, jsid id, JSObject **objp, JSObject **pobjp,
|
||||
PROPERTY_CACHE_TEST(&rt->propertyCache, obj, id, prop);
|
||||
if (PROP_FOUND(prop)) {
|
||||
#ifdef JS_THREADSAFE
|
||||
PR_ASSERT(OBJ_IS_NATIVE(obj));
|
||||
JS_ASSERT(OBJ_IS_NATIVE(obj));
|
||||
JS_LOCK_OBJ(cx, obj);
|
||||
JS_ATOMIC_ADDREF(&((JSScopeProperty *)prop)->nrefs, 1);
|
||||
#endif
|
||||
@@ -1526,7 +1532,7 @@ js_FindVariable(JSContext *cx, jsid id, JSObject **objp, JSObject **pobjp,
|
||||
* same scope as cx->globalObject for cross-context function calls.
|
||||
*/
|
||||
obj = *objp;
|
||||
PR_ASSERT(obj);
|
||||
JS_ASSERT(obj);
|
||||
|
||||
/*
|
||||
* Make a top-level variable.
|
||||
@@ -1566,8 +1572,8 @@ js_FindVariableScope(JSContext *cx, JSFunction **funp)
|
||||
if (fp)
|
||||
obj = js_GetCallObject(cx, fp, parent, withobj);
|
||||
} else if (clasp == &js_CallClass) {
|
||||
fp = (JSStackFrame *) JS_GetPrivate(cx, obj);
|
||||
fun = fp->fun;
|
||||
fp = (JSStackFrame *) JS_GetPrivate(cx, obj);
|
||||
fun = fp->fun;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1585,8 +1591,8 @@ js_GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
if (!js_LookupProperty(cx, obj, id, &obj2, (JSProperty **)&sprop))
|
||||
return JS_FALSE;
|
||||
if (!sprop) {
|
||||
/* Handle old bug that treated empty string as zero index.
|
||||
* Also convert string indices to numbers if applicable. */
|
||||
/* Handle old bug that treated empty string as zero index.
|
||||
* Also convert string indices to numbers if applicable. */
|
||||
CHECK_FOR_FUNNY_INDEX(id);
|
||||
|
||||
#if JS_BUG_NULL_INDEX_PROPS
|
||||
@@ -1604,7 +1610,7 @@ js_GetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
|
||||
if (!OBJ_IS_NATIVE(obj2)) {
|
||||
OBJ_DROP_PROPERTY(cx, obj2, (JSProperty *)sprop);
|
||||
return OBJ_GET_PROPERTY(cx, obj2, id, vp);
|
||||
return OBJ_GET_PROPERTY(cx, obj2, id, vp);
|
||||
}
|
||||
|
||||
/* Unlock obj2 before calling getter, relock after to avoid deadlock. */
|
||||
@@ -1630,7 +1636,7 @@ js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
JSRuntime *rt;
|
||||
JSScope *scope, *protoscope;
|
||||
JSScopeProperty *sprop, *protosprop;
|
||||
PRHashNumber hash;
|
||||
JSHashNumber hash;
|
||||
JSSymbol *sym, *protosym;
|
||||
JSObject *proto, *tmp, *assignobj;
|
||||
jsval protoid;
|
||||
@@ -1779,7 +1785,7 @@ js_SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
}
|
||||
|
||||
/* Get the current property value from its slot. */
|
||||
PR_ASSERT(sprop->slot < obj->map->freeslot);
|
||||
JS_ASSERT(sprop->slot < obj->map->freeslot);
|
||||
slot = sprop->slot;
|
||||
pval = LOCKED_OBJ_GET_SLOT(obj, slot);
|
||||
|
||||
@@ -1814,7 +1820,8 @@ _readonly:
|
||||
return JS_TRUE;
|
||||
str = js_DecompileValueGenerator(cx, js_IdToValue(id), NULL);
|
||||
if (str)
|
||||
JS_ReportError(cx, "%s is read-only", JS_GetStringBytes(str));
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_READ_ONLY, JS_GetStringBytes(str));
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@@ -1949,8 +1956,10 @@ js_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, jsval *rval)
|
||||
return JS_TRUE;
|
||||
}
|
||||
str = js_DecompileValueGenerator(cx, js_IdToValue(id), NULL);
|
||||
if (str)
|
||||
JS_ReportError(cx, "%s is permanent", JS_GetStringBytes(str));
|
||||
if (str) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_PERMANENT, JS_GetStringBytes(str));
|
||||
}
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@@ -1984,7 +1993,7 @@ js_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, jsval *rval)
|
||||
if (sym_id(sym) == id) {
|
||||
sym->entry.value = NULL;
|
||||
sprop = js_DropScopeProperty(cx, scope, sprop);
|
||||
PR_ASSERT(sprop);
|
||||
JS_ASSERT(sprop);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@@ -2017,58 +2026,59 @@ js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp)
|
||||
if (!OBJ_GET_CLASS(cx, obj)->convert(cx, obj, hint, &v))
|
||||
return JS_FALSE;
|
||||
|
||||
/*
|
||||
* JS1.2 never failed (except for malloc failure) to convert an
|
||||
* object to a string. ECMA requires an error if both toString
|
||||
* and valueOf fail to produce a primitive value.
|
||||
*/
|
||||
if (!JSVAL_IS_PRIMITIVE(v) && cx->version == JSVERSION_1_2) {
|
||||
char *bytes = PR_smprintf("[object %s]",
|
||||
OBJ_GET_CLASS(cx, obj)->name);
|
||||
if (!bytes)
|
||||
return JS_FALSE;
|
||||
str = JS_NewString(cx, bytes, strlen(bytes));
|
||||
if (!str) {
|
||||
free(bytes);
|
||||
return JS_FALSE;
|
||||
}
|
||||
v = STRING_TO_JSVAL(str);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
break;
|
||||
/*
|
||||
* JS1.2 never failed (except for malloc failure) to convert an
|
||||
* object to a string. ECMA requires an error if both toString
|
||||
* and valueOf fail to produce a primitive value.
|
||||
*/
|
||||
if (!JSVAL_IS_PRIMITIVE(v) && cx->version == JSVERSION_1_2) {
|
||||
char *bytes = JS_smprintf("[object %s]",
|
||||
OBJ_GET_CLASS(cx, obj)->name);
|
||||
if (!bytes)
|
||||
return JS_FALSE;
|
||||
str = JS_NewString(cx, bytes, strlen(bytes));
|
||||
if (!str) {
|
||||
free(bytes);
|
||||
return JS_FALSE;
|
||||
}
|
||||
v = STRING_TO_JSVAL(str);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!OBJ_GET_CLASS(cx, obj)->convert(cx, obj, hint, &v))
|
||||
return JS_FALSE;
|
||||
if (!JSVAL_IS_PRIMITIVE(v)) {
|
||||
if (JS_TypeOfValue(cx, v) == hint)
|
||||
goto out;
|
||||
goto out;
|
||||
/* Don't convert to string (source object literal) for JS1.2. */
|
||||
if (cx->version == JSVERSION_1_2 && hint == JSTYPE_BOOLEAN)
|
||||
goto out;
|
||||
goto out;
|
||||
js_TryMethod(cx, obj, cx->runtime->atomState.toStringAtom, 0, NULL,
|
||||
&v);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
if (!JSVAL_IS_PRIMITIVE(v)) {
|
||||
/* Avoid recursive death through js_DecompileValueGenerator. */
|
||||
if (hint == JSTYPE_STRING) {
|
||||
str = JS_InternString(cx, OBJ_GET_CLASS(cx, obj)->name);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
} else {
|
||||
str = NULL;
|
||||
}
|
||||
*vp = OBJECT_TO_JSVAL(obj);
|
||||
str = js_DecompileValueGenerator(cx, v, str);
|
||||
if (str) {
|
||||
JS_ReportError(cx, "can't convert %s to %s",
|
||||
JS_GetStringBytes(str),
|
||||
(hint == JSTYPE_VOID)
|
||||
? "primitive type"
|
||||
: js_type_str[hint]);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_CANT_CONVERT_TO,
|
||||
JS_GetStringBytes(str),
|
||||
(hint == JSTYPE_VOID)
|
||||
? "primitive type"
|
||||
: js_type_str[hint]);
|
||||
}
|
||||
return JS_FALSE;
|
||||
}
|
||||
@@ -2084,7 +2094,7 @@ js_NewIdArray(JSContext *cx, jsint length)
|
||||
|
||||
ida = JS_malloc(cx, sizeof(JSIdArray) + (length - 1) * sizeof(jsval));
|
||||
if (ida)
|
||||
ida->length = length;
|
||||
ida->length = length;
|
||||
return ida;
|
||||
}
|
||||
|
||||
@@ -2101,7 +2111,7 @@ typedef struct JSNativeIteratorState {
|
||||
*/
|
||||
JSBool
|
||||
js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
jsval *statep, jsid *idp)
|
||||
jsval *statep, jsid *idp)
|
||||
{
|
||||
JSObject *proto_obj;
|
||||
JSClass *clasp;
|
||||
@@ -2115,22 +2125,22 @@ js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
clasp = OBJ_GET_CLASS(cx, obj);
|
||||
enumerate = clasp->enumerate;
|
||||
if (clasp->flags & JSCLASS_NEW_ENUMERATE)
|
||||
return ((JSNewEnumerateOp) enumerate)(cx, obj, enum_op, statep, idp);
|
||||
return ((JSNewEnumerateOp) enumerate)(cx, obj, enum_op, statep, idp);
|
||||
|
||||
switch (enum_op) {
|
||||
|
||||
case JSENUMERATE_INIT:
|
||||
if (!enumerate(cx, obj))
|
||||
goto init_error;
|
||||
length = 0;
|
||||
if (!enumerate(cx, obj))
|
||||
goto init_error;
|
||||
length = 0;
|
||||
|
||||
/*
|
||||
* The set of all property ids is pre-computed when the iterator
|
||||
* is initialized so as to avoid problems with properties being
|
||||
* deleted during the iteration.
|
||||
*/
|
||||
JS_LOCK_OBJ(cx, obj);
|
||||
scope = (JSScope *) obj->map;
|
||||
/*
|
||||
* The set of all property ids is pre-computed when the iterator
|
||||
* is initialized so as to avoid problems with properties being
|
||||
* deleted during the iteration.
|
||||
*/
|
||||
JS_LOCK_OBJ(cx, obj);
|
||||
scope = (JSScope *) obj->map;
|
||||
|
||||
/*
|
||||
* If this object shares a scope with its prototype, don't enumerate
|
||||
@@ -2158,46 +2168,46 @@ js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
i = 0;
|
||||
for (sprop = scope->props; sprop; sprop = sprop->next) {
|
||||
if ((sprop->attrs & JSPROP_ENUMERATE) && sprop->symbols) {
|
||||
PR_ASSERT(i < length);
|
||||
JS_ASSERT(i < length);
|
||||
ida->vector[i++] = sym_id(sprop->symbols);
|
||||
}
|
||||
}
|
||||
}
|
||||
JS_UNLOCK_OBJ(cx, obj);
|
||||
JS_UNLOCK_OBJ(cx, obj);
|
||||
|
||||
state = JS_malloc(cx, sizeof(JSNativeIteratorState));
|
||||
if (!state) {
|
||||
JS_DestroyIdArray(cx, ida);
|
||||
goto init_error;
|
||||
}
|
||||
state->ida = ida;
|
||||
state->next_index = 0;
|
||||
*statep = PRIVATE_TO_JSVAL(state);
|
||||
if (idp)
|
||||
*idp = INT_TO_JSVAL(length);
|
||||
return JS_TRUE;
|
||||
state = JS_malloc(cx, sizeof(JSNativeIteratorState));
|
||||
if (!state) {
|
||||
JS_DestroyIdArray(cx, ida);
|
||||
goto init_error;
|
||||
}
|
||||
state->ida = ida;
|
||||
state->next_index = 0;
|
||||
*statep = PRIVATE_TO_JSVAL(state);
|
||||
if (idp)
|
||||
*idp = INT_TO_JSVAL(length);
|
||||
return JS_TRUE;
|
||||
|
||||
case JSENUMERATE_NEXT:
|
||||
state = JSVAL_TO_PRIVATE(*statep);
|
||||
ida = state->ida;
|
||||
length = ida->length;
|
||||
if (state->next_index != length) {
|
||||
*idp = ida->vector[state->next_index++];
|
||||
return JS_TRUE;
|
||||
}
|
||||
state = JSVAL_TO_PRIVATE(*statep);
|
||||
ida = state->ida;
|
||||
length = ida->length;
|
||||
if (state->next_index != length) {
|
||||
*idp = ida->vector[state->next_index++];
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/* Fall through ... */
|
||||
/* Fall through ... */
|
||||
|
||||
case JSENUMERATE_DESTROY:
|
||||
state = JSVAL_TO_PRIVATE(*statep);
|
||||
JS_DestroyIdArray(cx, state->ida);
|
||||
JS_free(cx, state);
|
||||
*statep = JSVAL_NULL;
|
||||
return JS_TRUE;
|
||||
state = JSVAL_TO_PRIVATE(*statep);
|
||||
JS_DestroyIdArray(cx, state->ida);
|
||||
JS_free(cx, state);
|
||||
*statep = JSVAL_NULL;
|
||||
return JS_TRUE;
|
||||
|
||||
default:
|
||||
PR_ASSERT(0);
|
||||
return JS_FALSE;
|
||||
JS_ASSERT(0);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
init_error:
|
||||
@@ -2375,7 +2385,7 @@ js_ValueToObject(JSContext *cx, jsval v, JSObject **objp)
|
||||
} else if (JSVAL_IS_DOUBLE(v)) {
|
||||
obj = js_NumberToObject(cx, *JSVAL_TO_DOUBLE(v));
|
||||
} else {
|
||||
PR_ASSERT(JSVAL_IS_BOOLEAN(v));
|
||||
JS_ASSERT(JSVAL_IS_BOOLEAN(v));
|
||||
obj = js_BooleanToObject(cx, JSVAL_TO_BOOLEAN(v));
|
||||
}
|
||||
if (!obj)
|
||||
@@ -2396,8 +2406,8 @@ js_ValueToNonNullObject(JSContext *cx, jsval v)
|
||||
if (!obj) {
|
||||
str = js_DecompileValueGenerator(cx, v, NULL);
|
||||
if (str) {
|
||||
JS_ReportError(cx, "%s has no properties",
|
||||
JS_GetStringBytes(str));
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_NO_PROPERTIES, JS_GetStringBytes(str));
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
@@ -2482,7 +2492,10 @@ js_XDRObject(JSXDRState *xdr, JSObject **objp)
|
||||
} else {
|
||||
clasp = JS_FindClassById(xdr, classId);
|
||||
if (!clasp) {
|
||||
JS_ReportError(cx, "can't find class id %ld", (long)classId);
|
||||
char numBuf[12];
|
||||
JS_snprintf(numBuf, sizeof numBuf, "%ld", (long)classId);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_CANT_FIND_CLASS, numBuf);
|
||||
ok = JS_FALSE;
|
||||
goto out;
|
||||
}
|
||||
@@ -2490,7 +2503,8 @@ js_XDRObject(JSXDRState *xdr, JSObject **objp)
|
||||
}
|
||||
|
||||
if (!clasp->xdrObject) {
|
||||
JS_ReportError(cx, "can't XDR class %s", clasp->name);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_CANT_XDR_CLASS, clasp->name);
|
||||
ok = JS_FALSE;
|
||||
} else {
|
||||
ok = clasp->xdrObject(xdr, objp);
|
||||
@@ -2510,7 +2524,7 @@ out:
|
||||
void printChar(jschar *cp) {
|
||||
fprintf(stderr, "jschar* (0x%x) \"", cp);
|
||||
while (*cp)
|
||||
fputc(*cp++, stderr);
|
||||
fputc(*cp++, stderr);
|
||||
fputc('"', stderr);
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
@@ -2519,7 +2533,7 @@ void printString(JSString *str) {
|
||||
jsuint i;
|
||||
fprintf(stderr, "string (0x%x) \"", str);
|
||||
for (i=0; i < str->length; i++)
|
||||
fputc(str->chars[i], stderr);
|
||||
fputc(str->chars[i], stderr);
|
||||
fputc('"', stderr);
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
@@ -2527,22 +2541,22 @@ void printString(JSString *str) {
|
||||
void printVal(jsval val) {
|
||||
fprintf(stderr, "val %d (0x%x) = ", val, val);
|
||||
if (JSVAL_IS_NULL(val)) {
|
||||
fprintf(stderr, "null\n");
|
||||
fprintf(stderr, "null\n");
|
||||
} else if (JSVAL_IS_VOID(val)) {
|
||||
fprintf(stderr, "undefined\n");
|
||||
fprintf(stderr, "undefined\n");
|
||||
} else if (JSVAL_IS_OBJECT(val)) {
|
||||
/* XXX can do more here */
|
||||
fprintf(stderr, "object\n");
|
||||
/* XXX can do more here */
|
||||
fprintf(stderr, "object\n");
|
||||
} else if (JSVAL_IS_INT(val)) {
|
||||
fprintf(stderr, "(int) %d\n", JSVAL_TO_INT(val));
|
||||
fprintf(stderr, "(int) %d\n", JSVAL_TO_INT(val));
|
||||
} else if (JSVAL_IS_STRING(val)) {
|
||||
printString(JSVAL_TO_STRING(val));
|
||||
printString(JSVAL_TO_STRING(val));
|
||||
} else if (JSVAL_IS_DOUBLE(val)) {
|
||||
fprintf(stderr, "(double) %g\n", *JSVAL_TO_DOUBLE(val));
|
||||
fprintf(stderr, "(double) %g\n", *JSVAL_TO_DOUBLE(val));
|
||||
} else {
|
||||
PR_ASSERT(JSVAL_IS_BOOLEAN(val));
|
||||
fprintf(stderr, "(boolean) %s\n",
|
||||
JSVAL_TO_BOOLEAN(val) ? "true" : "false");
|
||||
JS_ASSERT(JSVAL_IS_BOOLEAN(val));
|
||||
fprintf(stderr, "(boolean) %s\n",
|
||||
JSVAL_TO_BOOLEAN(val) ? "true" : "false");
|
||||
}
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
@@ -28,15 +28,17 @@
|
||||
*/
|
||||
#ifdef NETSCAPE_INTERNAL
|
||||
#ifndef NSPR20
|
||||
#include "prhash.h"
|
||||
#include "jshash.h"
|
||||
#else
|
||||
#include "plhash.h"
|
||||
/* Removed by JSIFY: #include "JShash.h"
|
||||
*/
|
||||
#include "jshash.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#endif
|
||||
#include "jsprvtd.h"
|
||||
#include "jspubtd.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
struct JSObjectMap {
|
||||
jsrefcount nrefs; /* count of all referencing objects */
|
||||
@@ -101,7 +103,7 @@ struct JSObject {
|
||||
|
||||
#ifdef DEBUG
|
||||
#define MAP_CHECK_SLOT(map,slot) \
|
||||
PR_ASSERT((uint32)slot < PR_MAX((map)->nslots, (map)->freeslot))
|
||||
JS_ASSERT((uint32)slot < JS_MAX((map)->nslots, (map)->freeslot))
|
||||
#define OBJ_CHECK_SLOT(obj,slot) \
|
||||
MAP_CHECK_SLOT((obj)->map, slot)
|
||||
#else
|
||||
@@ -148,24 +150,26 @@ struct JSObject {
|
||||
((JSClass *)JSVAL_TO_PRIVATE(OBJ_GET_SLOT(cx, obj, JSSLOT_CLASS)))
|
||||
|
||||
/* Test whether a map or object is native. */
|
||||
#define MAP_IS_NATIVE(map) ((map)->ops == &js_ObjectOps)
|
||||
#define MAP_IS_NATIVE(map) ((map)->ops == &js_ObjectOps || \
|
||||
(map)->ops == &js_WithObjectOps)
|
||||
#define OBJ_IS_NATIVE(obj) MAP_IS_NATIVE((obj)->map)
|
||||
|
||||
extern JS_FRIEND_DATA(JSObjectOps) js_ObjectOps;
|
||||
extern JS_FRIEND_DATA(JSObjectOps) js_WithObjectOps;
|
||||
extern JSClass js_ObjectClass;
|
||||
extern JSClass js_WithClass;
|
||||
|
||||
struct JSSharpObjectMap {
|
||||
jsrefcount depth;
|
||||
jsatomid sharpgen;
|
||||
PRHashTable *table;
|
||||
JSHashTable *table;
|
||||
};
|
||||
|
||||
#define SHARP_BIT 1
|
||||
#define IS_SHARP(he) ((jsatomid)(he)->value & SHARP_BIT)
|
||||
#define MAKE_SHARP(he) ((he)->value = (void*)((jsatomid)(he)->value|SHARP_BIT))
|
||||
|
||||
extern PRHashEntry *
|
||||
extern JSHashEntry *
|
||||
js_EnterSharpObject(JSContext *cx, JSObject *obj, JSIdArray **idap,
|
||||
jschar **sp);
|
||||
|
||||
@@ -178,7 +182,7 @@ js_obj_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
|
||||
extern JSBool
|
||||
js_obj_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *rval);
|
||||
jsval *rval);
|
||||
|
||||
extern JSObject *
|
||||
js_InitObjectClass(JSContext *cx, JSObject *obj);
|
||||
@@ -281,7 +285,7 @@ js_DefaultValue(JSContext *cx, JSObject *obj, JSType hint, jsval *vp);
|
||||
|
||||
extern JSBool
|
||||
js_Enumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
jsval *statep, jsid *idp);
|
||||
jsval *statep, jsid *idp);
|
||||
|
||||
extern JSBool
|
||||
js_CheckAccess(JSContext *cx, JSObject *obj, jsid id, JSAccessMode mode,
|
||||
@@ -326,6 +330,6 @@ js_XDRObject(JSXDRState *xdr, JSObject **objp);
|
||||
extern JSIdArray *
|
||||
js_NewIdArray(JSContext *cx, jsint length);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsobj_h___ */
|
||||
|
||||
@@ -25,15 +25,18 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "jstypes.h"
|
||||
#ifndef NSPR20
|
||||
#include "prarena.h"
|
||||
#include "jsarena.h"
|
||||
#else
|
||||
#include "plarena.h"
|
||||
/* Removed by JSIFY: #include "plarena.h"
|
||||
*/
|
||||
#include "jsarena.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "prlog.h"
|
||||
#include "prdtoa.h"
|
||||
#include "prprf.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#include "jsdtoa.h"
|
||||
#include "jsprf.h"
|
||||
#include "jsapi.h"
|
||||
#include "jsarray.h"
|
||||
#include "jsatom.h"
|
||||
@@ -76,7 +79,7 @@ char *js_incop_str[] = {"++", "--"};
|
||||
JSCodeSpec FAR js_CodeSpec[] = {
|
||||
#define OPDEF(op,val,name,token,length,nuses,ndefs,prec,format) \
|
||||
{name,token,length,nuses,ndefs,prec,format},
|
||||
#include "jsopcode.def"
|
||||
#include "jsopcode.tbl"
|
||||
#undef OPDEF
|
||||
};
|
||||
|
||||
@@ -115,7 +118,11 @@ js_Disassemble1(JSContext *cx, JSScript *script, jsbytecode *pc, uintN loc,
|
||||
|
||||
op = (JSOp)*pc;
|
||||
if (op >= JSOP_LIMIT) {
|
||||
JS_ReportError(cx, "bytecode %d too large (limit %d)", op, JSOP_LIMIT);
|
||||
char numBuf1[12], numBuf2[12];
|
||||
JS_snprintf(numBuf1, sizeof numBuf1, "%d", op);
|
||||
JS_snprintf(numBuf2, sizeof numBuf2, "%d", JSOP_LIMIT);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_BYTECODE_TOO_BIG, numBuf1, numBuf2);
|
||||
return 0;
|
||||
}
|
||||
cs = &js_CodeSpec[op];
|
||||
@@ -191,7 +198,7 @@ js_Disassemble1(JSContext *cx, JSScript *script, jsbytecode *pc, uintN loc,
|
||||
pc2 += JUMP_OFFSET_LEN;
|
||||
npairs = (uintN) GET_ATOM_INDEX(pc2);
|
||||
pc2 += ATOM_INDEX_LEN;
|
||||
fprintf(fp, " defaultOffset %d npairs %u", off, npairs);
|
||||
fprintf(fp, " offset %d npairs %u", off, npairs);
|
||||
while (npairs) {
|
||||
atom = GET_ATOM(cx, script, pc2);
|
||||
pc2 += ATOM_INDEX_LEN;
|
||||
@@ -225,9 +232,13 @@ js_Disassemble1(JSContext *cx, JSScript *script, jsbytecode *pc, uintN loc,
|
||||
fprintf(fp, " %u", GET_VARNO(pc));
|
||||
break;
|
||||
|
||||
default:
|
||||
JS_ReportError(cx, "unknown bytecode format %x", cs->format);
|
||||
default: {
|
||||
char numBuf[12];
|
||||
JS_snprintf(numBuf, sizeof numBuf, "%lx", (unsigned long) cs->format);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_UNKNOWN_FORMAT, numBuf);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
fputs("\n", fp);
|
||||
return len;
|
||||
@@ -242,7 +253,7 @@ js_Disassemble1(JSContext *cx, JSScript *script, jsbytecode *pc, uintN loc,
|
||||
*/
|
||||
typedef struct Sprinter {
|
||||
JSContext *context; /* context executing the decompiler */
|
||||
PRArenaPool *pool; /* string allocation pool */
|
||||
JSArenaPool *pool; /* string allocation pool */
|
||||
char *base; /* base address of buffer in pool */
|
||||
size_t size; /* size of buffer allocated at base */
|
||||
ptrdiff_t offset; /* offset of next free char in buffer */
|
||||
@@ -259,9 +270,9 @@ static JSBool
|
||||
SprintAlloc(Sprinter *sp, size_t nb)
|
||||
{
|
||||
if (!sp->base) {
|
||||
PR_ARENA_ALLOCATE(sp->base, sp->pool, nb);
|
||||
JS_ARENA_ALLOCATE(sp->base, sp->pool, nb);
|
||||
} else {
|
||||
PR_ARENA_GROW(sp->base, sp->pool, sp->size, nb);
|
||||
JS_ARENA_GROW(sp->base, sp->pool, sp->size, nb);
|
||||
}
|
||||
if (!sp->base) {
|
||||
JS_ReportOutOfMemory(sp->context);
|
||||
@@ -299,7 +310,7 @@ Sprint(Sprinter *sp, const char *format, ...)
|
||||
ptrdiff_t offset;
|
||||
|
||||
va_start(ap, format);
|
||||
bp = PR_vsmprintf(format, ap); /* XXX vsaprintf */
|
||||
bp = JS_vsmprintf(format, ap); /* XXX vsaprintf */
|
||||
va_end(ap);
|
||||
if (!bp) {
|
||||
JS_ReportOutOfMemory(sp->context);
|
||||
@@ -377,11 +388,11 @@ js_QuoteString(JSContext *cx, JSString *str, jschar quote)
|
||||
char *bytes;
|
||||
JSString *escstr;
|
||||
|
||||
mark = PR_ARENA_MARK(&cx->tempPool);
|
||||
mark = JS_ARENA_MARK(&cx->tempPool);
|
||||
INIT_SPRINTER(cx, &sprinter, &cx->tempPool, 0);
|
||||
bytes = QuoteString(&sprinter, str, quote);
|
||||
escstr = bytes ? JS_NewStringCopyZ(cx, bytes) : NULL;
|
||||
PR_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
return escstr;
|
||||
}
|
||||
|
||||
@@ -389,7 +400,7 @@ js_QuoteString(JSContext *cx, JSString *str, jschar quote)
|
||||
|
||||
struct JSPrinter {
|
||||
Sprinter sprinter; /* base class state */
|
||||
PRArenaPool pool; /* string allocation pool */
|
||||
JSArenaPool pool; /* string allocation pool */
|
||||
uintN indent; /* indentation in spaces */
|
||||
JSScript *script; /* script being printed */
|
||||
JSScope *scope; /* script function scope */
|
||||
@@ -407,7 +418,7 @@ js_NewPrinter(JSContext *cx, const char *name, uintN indent)
|
||||
if (!jp)
|
||||
return NULL;
|
||||
INIT_SPRINTER(cx, &jp->sprinter, &jp->pool, 0);
|
||||
PR_InitArenaPool(&jp->pool, name, 256, 1);
|
||||
JS_InitArenaPool(&jp->pool, name, 256, 1);
|
||||
jp->indent = indent;
|
||||
jp->script = NULL;
|
||||
jp->scope = NULL;
|
||||
@@ -417,7 +428,7 @@ js_NewPrinter(JSContext *cx, const char *name, uintN indent)
|
||||
map = obj->map;
|
||||
if (map->ops == &js_ObjectOps) {
|
||||
if (OBJ_GET_CLASS(cx, obj) == &js_CallClass) {
|
||||
obj = fp->fun ? fp->fun->object : NULL;
|
||||
obj = fp->fun ? fp->fun->object : NULL;
|
||||
if (obj)
|
||||
map = obj->map;
|
||||
}
|
||||
@@ -430,7 +441,7 @@ js_NewPrinter(JSContext *cx, const char *name, uintN indent)
|
||||
void
|
||||
js_DestroyPrinter(JSPrinter *jp)
|
||||
{
|
||||
PR_FinishArenaPool(&jp->pool);
|
||||
JS_FinishArenaPool(&jp->pool);
|
||||
JS_free(jp->sprinter.context, jp);
|
||||
}
|
||||
|
||||
@@ -446,7 +457,7 @@ js_GetPrinterOutput(JSPrinter *jp)
|
||||
str = JS_NewStringCopyZ(cx, jp->sprinter.base);
|
||||
if (!str)
|
||||
return NULL;
|
||||
PR_FreeArenaPool(&jp->pool);
|
||||
JS_FreeArenaPool(&jp->pool);
|
||||
INIT_SPRINTER(cx, &jp->sprinter, &jp->pool, 0);
|
||||
return str;
|
||||
}
|
||||
@@ -468,7 +479,7 @@ js_printf(JSPrinter *jp, char *format, ...)
|
||||
}
|
||||
|
||||
/* Allocate temp space, convert format, and put. */
|
||||
bp = PR_vsmprintf(format, ap); /* XXX vsaprintf */
|
||||
bp = JS_vsmprintf(format, ap); /* XXX vsaprintf */
|
||||
if (!bp) {
|
||||
JS_ReportOutOfMemory(jp->sprinter.context);
|
||||
return -1;
|
||||
@@ -512,10 +523,10 @@ typedef struct SprintStack {
|
||||
static JSBool
|
||||
PushOff(SprintStack *ss, ptrdiff_t off, JSOp op)
|
||||
{
|
||||
PR_ASSERT(JSOP_LIMIT <= 254);
|
||||
JS_ASSERT(JSOP_LIMIT <= 254);
|
||||
if (!SprintAlloc(&ss->sprinter, PAREN_SLOP))
|
||||
return JS_FALSE;
|
||||
PR_ASSERT(ss->top < ss->printer->script->depth);
|
||||
JS_ASSERT(ss->top < ss->printer->script->depth);
|
||||
ss->offsets[ss->top] = off;
|
||||
ss->opcodes[ss->top++] = (op >= 128) ? op - 128 : op;
|
||||
ss->sprinter.offset += PAREN_SLOP;
|
||||
@@ -562,13 +573,14 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb);
|
||||
|
||||
static JSBool
|
||||
DecompileSwitch(SprintStack *ss, TableEntry *table, uintN tableLength,
|
||||
jsbytecode *pc, ptrdiff_t switchLength, ptrdiff_t defaultOffset)
|
||||
jsbytecode *pc, ptrdiff_t switchLength,
|
||||
ptrdiff_t defaultOffset, JSBool isCondSwitch)
|
||||
{
|
||||
JSContext *cx;
|
||||
JSPrinter *jp;
|
||||
char *lval, *rval;
|
||||
uintN i;
|
||||
ptrdiff_t diff, off, off2;
|
||||
ptrdiff_t diff, off, off2, caseExprOff;
|
||||
jsval key;
|
||||
JSString *str;
|
||||
|
||||
@@ -588,25 +600,53 @@ DecompileSwitch(SprintStack *ss, TableEntry *table, uintN tableLength,
|
||||
return JS_FALSE;
|
||||
jp->indent -= 4;
|
||||
}
|
||||
|
||||
if (isCondSwitch)
|
||||
caseExprOff = (ptrdiff_t) js_CodeSpec[JSOP_CONDSWITCH].length;
|
||||
|
||||
for (i = 0; i < tableLength; i++) {
|
||||
off = table[i].offset;
|
||||
if (i + 1 < tableLength)
|
||||
off2 = table[i + 1].offset;
|
||||
else
|
||||
off2 = switchLength;
|
||||
|
||||
key = table[i].key;
|
||||
str = js_ValueToString(cx, key);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
jp->indent += 2;
|
||||
if (JSVAL_IS_STRING(key)) {
|
||||
rval = QuoteString(&ss->sprinter, str, '"');
|
||||
if (!rval)
|
||||
if (isCondSwitch) {
|
||||
ptrdiff_t nextCaseExprOff;
|
||||
|
||||
/*
|
||||
* key encodes the JSOP_CASE bytecode's offset from switchtop.
|
||||
* The next case expression follows immediately, unless we are
|
||||
* at the last case.
|
||||
*/
|
||||
nextCaseExprOff = (ptrdiff_t)
|
||||
(JSVAL_TO_INT(key) + js_CodeSpec[JSOP_CASE].length);
|
||||
jp->indent += 2;
|
||||
if (!Decompile(ss, pc + caseExprOff,
|
||||
nextCaseExprOff - caseExprOff)) {
|
||||
return JS_FALSE;
|
||||
} else {
|
||||
rval = JS_GetStringBytes(str);
|
||||
}
|
||||
caseExprOff = nextCaseExprOff;
|
||||
} else {
|
||||
/*
|
||||
* key comes from an atom, not the decompiler, so we need to
|
||||
* quote it if it's a string literal.
|
||||
*/
|
||||
str = js_ValueToString(cx, key);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
jp->indent += 2;
|
||||
if (JSVAL_IS_STRING(key)) {
|
||||
rval = QuoteString(&ss->sprinter, str, '"');
|
||||
if (!rval)
|
||||
return JS_FALSE;
|
||||
} else {
|
||||
rval = JS_GetStringBytes(str);
|
||||
}
|
||||
js_printf(jp, "\tcase %s:\n", rval);
|
||||
}
|
||||
js_printf(jp, "\tcase %s:\n", rval);
|
||||
|
||||
jp->indent += 2;
|
||||
if (off <= defaultOffset && defaultOffset < off2) {
|
||||
diff = defaultOffset - off;
|
||||
@@ -624,6 +664,7 @@ DecompileSwitch(SprintStack *ss, TableEntry *table, uintN tableLength,
|
||||
jp->indent -= 4;
|
||||
}
|
||||
}
|
||||
|
||||
if (defaultOffset == switchLength) {
|
||||
jp->indent += 2;
|
||||
js_printf(jp, "\tdefault:\n");
|
||||
@@ -660,7 +701,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
JSOp op, lastop, saveop;
|
||||
JSCodeSpec *cs, *topcs;
|
||||
jssrcnote *sn;
|
||||
const char *lval, *rval=NULL, *xval;
|
||||
const char *lval, *rval = NULL, *xval;
|
||||
jsint i, argc;
|
||||
char **argv;
|
||||
JSAtom *atom;
|
||||
@@ -673,7 +714,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
*/
|
||||
#define DECOMPILE_CODE(pc,nb) if (!Decompile(ss, pc, nb)) return JS_FALSE
|
||||
#define POP_STR() OFF2STR(&ss->sprinter, PopOff(ss, op))
|
||||
#define LOCAL_ASSERT(expr) PR_ASSERT(expr); if (!(expr)) return JS_FALSE
|
||||
#define LOCAL_ASSERT(expr) JS_ASSERT(expr); if (!(expr)) return JS_FALSE
|
||||
|
||||
cx = ss->sprinter.context;
|
||||
jp = ss->printer;
|
||||
@@ -790,7 +831,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
/* Do the loop body. */
|
||||
js_puts(jp, ") {\n");
|
||||
jp->indent += 4;
|
||||
oplen = js_CodeSpec[pc[cond]].length;
|
||||
oplen = (cond) ? js_CodeSpec[pc[cond]].length : 0;
|
||||
DECOMPILE_CODE(pc + cond + oplen, next - cond - oplen);
|
||||
jp->indent -= 4;
|
||||
js_printf(jp, "\t}\n");
|
||||
@@ -840,7 +881,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
len = js_GetSrcNoteOffset(sn, 0);
|
||||
pc += 4; /* initprop, enterwith */
|
||||
if (len) {
|
||||
js_printf(jp, " if ");
|
||||
js_printf(jp, " : ");
|
||||
DECOMPILE_CODE(pc, len - 3); /* don't decompile ifeq */
|
||||
js_printf(jp, "%s", POP_STR());
|
||||
pc += len;
|
||||
@@ -857,7 +898,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
|
||||
atom = js_GetAtom(cx, &jp->script->atomMap,
|
||||
(jsatomid) js_GetSrcNoteOffset(sn, 0));
|
||||
PR_ASSERT(ATOM_IS_OBJECT(atom));
|
||||
JS_ASSERT(ATOM_IS_OBJECT(atom));
|
||||
obj = ATOM_TO_OBJECT(atom);
|
||||
fun = JS_GetPrivate(cx, obj);
|
||||
jp2 = js_NewPrinter(cx, JS_GetFunctionName(fun),
|
||||
@@ -883,8 +924,10 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
todo = Sprint(&ss->sprinter, "");
|
||||
break;
|
||||
|
||||
case JSOP_JSR:
|
||||
#if JS_HAS_EXCEPTIONS
|
||||
case JSOP_GOSUB:
|
||||
case JSOP_RETSUB:
|
||||
case JSOP_SETSP:
|
||||
todo = -2;
|
||||
break;
|
||||
|
||||
@@ -893,6 +936,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
if (sn && SN_TYPE(sn) == SRC_HIDDEN)
|
||||
todo = -2;
|
||||
break;
|
||||
#endif /* JS_HAS_EXCEPTIONS */
|
||||
|
||||
case JSOP_POP:
|
||||
case JSOP_POPV:
|
||||
@@ -903,7 +947,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
todo = -2;
|
||||
goto do_forloop;
|
||||
|
||||
case SRC_COMMA:
|
||||
case SRC_PCDELTA:
|
||||
/* Pop and save to avoid blowing stack depth budget. */
|
||||
lval = JS_strdup(cx, POP_STR());
|
||||
if (!lval)
|
||||
@@ -974,6 +1018,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
todo = -2;
|
||||
break;
|
||||
|
||||
#if JS_HAS_EXCEPTIONS
|
||||
case JSOP_THROW:
|
||||
sn = js_GetSrcNote(jp->script, pc);
|
||||
todo = -2;
|
||||
@@ -982,6 +1027,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
rval = POP_STR();
|
||||
js_printf(jp, "\t%s %s;\n", cs->name, rval);
|
||||
break;
|
||||
#endif /* JS_HAS_EXCEPTIONS */
|
||||
|
||||
case JSOP_GOTO:
|
||||
sn = js_GetSrcNote(jp->script, pc);
|
||||
@@ -1524,7 +1570,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
} else if (JSVAL_IS_OBJECT(key)) {
|
||||
#if JS_HAS_LEXICAL_CLOSURE
|
||||
if (JSVAL_IS_FUNCTION(cx, key))
|
||||
goto do_closure;
|
||||
goto do_closure;
|
||||
#endif
|
||||
str = js_ValueToString(cx, key);
|
||||
if (!str)
|
||||
@@ -1546,7 +1592,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
TableEntry *table;
|
||||
|
||||
sn = js_GetSrcNote(jp->script, pc);
|
||||
PR_ASSERT(sn && SN_TYPE(sn) == SRC_SWITCH);
|
||||
JS_ASSERT(sn && SN_TYPE(sn) == SRC_SWITCH);
|
||||
len = js_GetSrcNoteOffset(sn, 0);
|
||||
pc2 = pc;
|
||||
off = GET_JUMP_OFFSET(pc2);
|
||||
@@ -1574,7 +1620,8 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
}
|
||||
js_qsort(table, (size_t)j, sizeof *table, CompareOffsets, NULL);
|
||||
|
||||
ok = DecompileSwitch(ss, table, (uintN)j, pc, len, off);
|
||||
ok = DecompileSwitch(ss, table, (uintN)j, pc, len, off,
|
||||
JS_FALSE);
|
||||
JS_free(cx, table);
|
||||
if (!ok)
|
||||
return ok;
|
||||
@@ -1584,14 +1631,15 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
|
||||
case JSOP_LOOKUPSWITCH:
|
||||
{
|
||||
jsbytecode *pc2 = pc;
|
||||
jsbytecode *pc2;
|
||||
ptrdiff_t off, off2;
|
||||
jsint npairs;
|
||||
TableEntry *table;
|
||||
|
||||
sn = js_GetSrcNote(jp->script, pc);
|
||||
PR_ASSERT(sn && SN_TYPE(sn) == SRC_SWITCH);
|
||||
JS_ASSERT(sn && SN_TYPE(sn) == SRC_SWITCH);
|
||||
len = js_GetSrcNoteOffset(sn, 0);
|
||||
pc2 = pc;
|
||||
off = GET_JUMP_OFFSET(pc2);
|
||||
pc2 += JUMP_OFFSET_LEN;
|
||||
npairs = (jsint) GET_ATOM_INDEX(pc2);
|
||||
@@ -1609,13 +1657,97 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
table[i].offset = off2;
|
||||
}
|
||||
|
||||
ok = DecompileSwitch(ss, table, (uintN)npairs, pc, len, off);
|
||||
ok = DecompileSwitch(ss, table, (uintN)npairs, pc, len, off,
|
||||
JS_FALSE);
|
||||
JS_free(cx, table);
|
||||
if (!ok)
|
||||
return ok;
|
||||
todo = -2;
|
||||
break;
|
||||
}
|
||||
|
||||
case JSOP_CONDSWITCH:
|
||||
{
|
||||
jsbytecode *pc2;
|
||||
ptrdiff_t off, off2, caseOff;
|
||||
jsint ncases;
|
||||
TableEntry *table;
|
||||
|
||||
sn = js_GetSrcNote(jp->script, pc);
|
||||
JS_ASSERT(sn && SN_TYPE(sn) == SRC_SWITCH);
|
||||
len = js_GetSrcNoteOffset(sn, 0);
|
||||
off = js_GetSrcNoteOffset(sn, 1);
|
||||
|
||||
/*
|
||||
* Count the cases using offsets from switch to first case,
|
||||
* and case to case, stored in srcnote immediates.
|
||||
*/
|
||||
pc2 = pc;
|
||||
off2 = off;
|
||||
for (ncases = 0; off2 != 0; ncases++) {
|
||||
pc2 += off2;
|
||||
JS_ASSERT(*pc2 == JSOP_CASE || *pc2 == JSOP_DEFAULT);
|
||||
if (*pc2 == JSOP_DEFAULT) {
|
||||
/* End of cases, but count default as a case. */
|
||||
off2 = 0;
|
||||
} else {
|
||||
sn = js_GetSrcNote(jp->script, pc2);
|
||||
JS_ASSERT(sn && SN_TYPE(sn) == SRC_PCDELTA);
|
||||
off2 = js_GetSrcNoteOffset(sn, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate table and rescan the cases using their srcnotes,
|
||||
* stashing each case's delta from switch top in table[i].key,
|
||||
* and the distance to its statements in table[i].offset.
|
||||
*/
|
||||
table = JS_malloc(cx, (size_t)ncases * sizeof *table);
|
||||
if (!table)
|
||||
return JS_FALSE;
|
||||
pc2 = pc;
|
||||
off2 = off;
|
||||
for (i = 0; i < ncases; i++) {
|
||||
pc2 += off2;
|
||||
JS_ASSERT(*pc2 == JSOP_CASE || *pc2 == JSOP_DEFAULT);
|
||||
caseOff = pc2 - pc;
|
||||
table[i].key = INT_TO_JSVAL((jsint) caseOff);
|
||||
table[i].offset = caseOff + GET_JUMP_OFFSET(pc2);
|
||||
if (*pc2 == JSOP_CASE) {
|
||||
sn = js_GetSrcNote(jp->script, pc2);
|
||||
JS_ASSERT(sn && SN_TYPE(sn) == SRC_PCDELTA);
|
||||
off2 = js_GetSrcNoteOffset(sn, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Find offset of default code by fetching the default offset
|
||||
* from the end of table. JSOP_CONDSWITCH always has a default
|
||||
* case at the end.
|
||||
*/
|
||||
off = JSVAL_TO_INT(table[ncases-1].key);
|
||||
pc2 = pc + off;
|
||||
off += GET_JUMP_OFFSET(pc2);
|
||||
|
||||
ok = DecompileSwitch(ss, table, (uintN)ncases, pc, len, off,
|
||||
JS_TRUE);
|
||||
JS_free(cx, table);
|
||||
if (!ok)
|
||||
return ok;
|
||||
todo = -2;
|
||||
break;
|
||||
}
|
||||
|
||||
case JSOP_CASE:
|
||||
{
|
||||
lval = POP_STR();
|
||||
if (!lval)
|
||||
return JS_FALSE;
|
||||
js_printf(jp, "\tcase %s:\n", lval);
|
||||
todo = -2;
|
||||
break;
|
||||
}
|
||||
|
||||
#endif /* JS_HAS_SWITCH_STATEMENT */
|
||||
|
||||
#if !JS_BUG_FALLIBLE_EQOPS
|
||||
@@ -1642,7 +1774,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
JSPrinter *jp2;
|
||||
|
||||
atom = GET_ATOM(cx, jp->script, pc);
|
||||
PR_ASSERT(ATOM_IS_OBJECT(atom));
|
||||
JS_ASSERT(ATOM_IS_OBJECT(atom));
|
||||
do_closure:
|
||||
obj = ATOM_TO_OBJECT(atom);
|
||||
fun = JS_GetPrivate(cx, obj);
|
||||
@@ -1739,7 +1871,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
sn = js_GetSrcNote(jp->script, pc);
|
||||
todo = Sprint(&ss->sprinter, "%s%s%c",
|
||||
rval,
|
||||
(sn && SN_TYPE(sn) == SRC_COMMA) ? ", " : "",
|
||||
(sn && SN_TYPE(sn) == SRC_CONTINUE) ? ", " : "",
|
||||
/* [balance */
|
||||
(*rval == '{') ? '}' : ']');
|
||||
break;
|
||||
@@ -1773,7 +1905,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
i = (jsint) GET_ATOM_INDEX(pc);
|
||||
rval = POP_STR();
|
||||
todo = Sprint(&ss->sprinter, "#%u=%s", (unsigned) i, rval);
|
||||
break;
|
||||
break;
|
||||
|
||||
case JSOP_USESHARP:
|
||||
i = (jsint) GET_ATOM_INDEX(pc);
|
||||
@@ -1784,7 +1916,7 @@ Decompile(SprintStack *ss, jsbytecode *pc, intN nb)
|
||||
|
||||
#if JS_HAS_DEBUGGER_KEYWORD
|
||||
case JSOP_DEBUGGER:
|
||||
js_printf(jp, "\tdebugger;\n");
|
||||
js_printf(jp, "\tdebugger;\n");
|
||||
todo = -2;
|
||||
break;
|
||||
#endif /* JS_HAS_DEBUGGER_KEYWORD */
|
||||
@@ -1830,7 +1962,7 @@ js_DecompileCode(JSPrinter *jp, JSScript *script, jsbytecode *pc, uintN len)
|
||||
/* Initialize a sprinter for use with the offset stack. */
|
||||
ss.printer = jp;
|
||||
cx = jp->sprinter.context;
|
||||
mark = PR_ARENA_MARK(&cx->tempPool);
|
||||
mark = JS_ARENA_MARK(&cx->tempPool);
|
||||
INIT_SPRINTER(cx, &ss.sprinter, &cx->tempPool, PAREN_SLOP);
|
||||
|
||||
/* Initialize the offset and opcode stacks. */
|
||||
@@ -1860,7 +1992,7 @@ js_DecompileCode(JSPrinter *jp, JSScript *script, jsbytecode *pc, uintN len)
|
||||
/* Free and clear temporary stuff. */
|
||||
JS_free(cx, ss.offsets);
|
||||
JS_free(cx, ss.opcodes);
|
||||
PR_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -1887,36 +2019,36 @@ js_DecompileFunction(JSPrinter *jp, JSFunction *fun, JSBool newlines)
|
||||
js_printf(jp, "function %s(", fun->atom ? ATOM_BYTES(fun->atom) : "");
|
||||
|
||||
if (fun->script && fun->object) {
|
||||
/* Print the parameters.
|
||||
*
|
||||
* This code is complicated by the need to handle duplicate parameter names.
|
||||
* A duplicate parameter is stored as a property with id equal to the parameter
|
||||
* number, but will not be in order in the linked list of symbols. So for each
|
||||
* parameter we search the list of symbols for the appropriately numbered
|
||||
* parameter, which we can then print.
|
||||
*/
|
||||
for (i=0;;i++) {
|
||||
jsid id;
|
||||
atom = NULL;
|
||||
scope = (JSScope *)fun->object->map;
|
||||
for (sprop = scope->props; sprop; sprop = snext) {
|
||||
snext = sprop->next;
|
||||
if (sprop->getter != js_GetArgument)
|
||||
continue;
|
||||
if (JSVAL_IS_INT(sprop->id) && JSVAL_TO_INT(sprop->id) == i) {
|
||||
atom = sym_atom(sprop->symbols);
|
||||
break;
|
||||
}
|
||||
id = (jsid) sym_atom(sprop->symbols);
|
||||
if (JSVAL_IS_INT(id) && JSVAL_TO_INT(id) == i) {
|
||||
atom = (JSAtom *) sprop->id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (atom == NULL)
|
||||
break;
|
||||
js_printf(jp, (i > 0 ? ", %s" : "%s"), ATOM_BYTES(atom));
|
||||
}
|
||||
/* Print the parameters.
|
||||
*
|
||||
* This code is complicated by the need to handle duplicate parameter names.
|
||||
* A duplicate parameter is stored as a property with id equal to the parameter
|
||||
* number, but will not be in order in the linked list of symbols. So for each
|
||||
* parameter we search the list of symbols for the appropriately numbered
|
||||
* parameter, which we can then print.
|
||||
*/
|
||||
for (i=0;;i++) {
|
||||
jsid id;
|
||||
atom = NULL;
|
||||
scope = (JSScope *)fun->object->map;
|
||||
for (sprop = scope->props; sprop; sprop = snext) {
|
||||
snext = sprop->next;
|
||||
if (sprop->getter != js_GetArgument)
|
||||
continue;
|
||||
if (JSVAL_IS_INT(sprop->id) && JSVAL_TO_INT(sprop->id) == i) {
|
||||
atom = sym_atom(sprop->symbols);
|
||||
break;
|
||||
}
|
||||
id = (jsid) sym_atom(sprop->symbols);
|
||||
if (JSVAL_IS_INT(id) && JSVAL_TO_INT(id) == i) {
|
||||
atom = (JSAtom *) sprop->id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (atom == NULL)
|
||||
break;
|
||||
js_printf(jp, (i > 0 ? ", %s" : "%s"), ATOM_BYTES(atom));
|
||||
}
|
||||
}
|
||||
js_puts(jp, ") {\n");
|
||||
indent = jp->indent;
|
||||
@@ -1995,15 +2127,15 @@ js_DecompileValueGenerator(JSContext *cx, jsval v, JSString *fallback)
|
||||
base = fp->vars
|
||||
? fp->vars + fp->nvars
|
||||
: (jsval *) cx->stackPool.current->base;
|
||||
if (PR_UPTRDIFF(sp - depth, base) < PR_UPTRDIFF(limit, base))
|
||||
if (JS_UPTRDIFF(sp - depth, base) < JS_UPTRDIFF(limit, base))
|
||||
pc = (jsbytecode *) sp[-depth];
|
||||
}
|
||||
|
||||
/* Be paranoid about loading an invalid pc from sp[-depth]. */
|
||||
if (!pc)
|
||||
goto do_fallback;
|
||||
PR_ASSERT(PR_UPTRDIFF(pc, script->code) < (pruword)script->length);
|
||||
if (PR_UPTRDIFF(pc, script->code) >= (pruword)script->length) {
|
||||
JS_ASSERT(JS_UPTRDIFF(pc, script->code) < (jsuword)script->length);
|
||||
if (JS_UPTRDIFF(pc, script->code) >= (jsuword)script->length) {
|
||||
pc = fp->pc;
|
||||
if (!pc)
|
||||
goto do_fallback;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "jsprvtd.h"
|
||||
#include "jspubtd.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
* JS operation bytecodes.
|
||||
@@ -33,7 +33,7 @@ PR_BEGIN_EXTERN_C
|
||||
typedef enum JSOp {
|
||||
#define OPDEF(op,val,name,token,length,nuses,ndefs,prec,format) \
|
||||
op = val,
|
||||
#include "jsopcode.def"
|
||||
#include "jsopcode.tbl"
|
||||
#undef OPDEF
|
||||
JSOP_LIMIT
|
||||
} JSOp;
|
||||
@@ -183,6 +183,6 @@ js_DecompileFunction(JSPrinter *jp, JSFunction *fun, JSBool newlines);
|
||||
extern JSString *
|
||||
js_DecompileValueGenerator(JSContext *cx, jsval v, JSString *fallback);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsopcode_h___ */
|
||||
|
||||
@@ -194,9 +194,19 @@ OPDEF(JSOP_INSTANCEOF,112,js_instanceof_str,js_instanceof_str,1,2,1,6,JOF_BYTE)
|
||||
/* debugger op */
|
||||
OPDEF(JSOP_DEBUGGER, 113,"debugger", NULL, 1, 0, 0, 0, JOF_BYTE)
|
||||
|
||||
/* jsr/return for finally handling */
|
||||
OPDEF(JSOP_JSR, 114,"jsr", NULL, 3, 0, 1, 0, JOF_JUMP)
|
||||
/* gosub/retsub for finally handling */
|
||||
OPDEF(JSOP_GOSUB, 114,"gosub", NULL, 3, 0, 1, 0, JOF_JUMP)
|
||||
OPDEF(JSOP_RETSUB, 115,"retsub", NULL, 1, 1, 0, 0, JOF_BYTE)
|
||||
|
||||
/* more exception handling ops */
|
||||
OPDEF(JSOP_EXCEPTION, 116,"exception", NULL, 1, 0, 1, 0, JOF_BYTE)
|
||||
OPDEF(JSOP_SETSP, 117,"setsp", NULL, 3, 0, 0, 0, JOF_UINT16)
|
||||
|
||||
/*
|
||||
* ECMA-compliant switch statement ops.
|
||||
* CONDSWITCH is a decompilable NOP; CASE is ===, POP, jump if true, re-push
|
||||
* lval if false; and DEFAULT is POP lval and GOTO.
|
||||
*/
|
||||
OPDEF(JSOP_CONDSWITCH,118,"condswitch", NULL, 1, 0, 0, 0, JOF_BYTE)
|
||||
OPDEF(JSOP_CASE, 119,"case", NULL, 3, 1, 0, 0, JOF_JUMP)
|
||||
OPDEF(JSOP_DEFAULT, 120,"default", NULL, 3, 1, 0, 0, JOF_JUMP)
|
||||
76
mozilla/js/src/jsosdep.h
Normal file
76
mozilla/js/src/jsosdep.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef jsosdep_h___
|
||||
#define jsosdep_h___
|
||||
/*
|
||||
* OS (and machine, and compiler XXX) dependent information.
|
||||
*/
|
||||
|
||||
#ifdef XP_PC
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "os/win32.h"
|
||||
#else
|
||||
#include "os/win16.h"
|
||||
#endif
|
||||
#endif /* XP_PC */
|
||||
|
||||
#ifdef XP_MAC
|
||||
#include "jsmacos.h"
|
||||
#endif
|
||||
|
||||
#ifdef XP_UNIX
|
||||
|
||||
/*
|
||||
* Get OS specific header information.
|
||||
*/
|
||||
#if defined(AIXV3)
|
||||
#include "os/aix.h"
|
||||
|
||||
#elif defined(BSDI)
|
||||
#include "os/bsdi.h"
|
||||
|
||||
#elif defined(HPUX)
|
||||
#include "os/hpux.h"
|
||||
|
||||
#elif defined(IRIX)
|
||||
#include "os/irix.h"
|
||||
|
||||
#elif defined(LINUX)
|
||||
#include "os/linux.h"
|
||||
|
||||
#elif defined(OSF1)
|
||||
#include "os/osf1.h"
|
||||
|
||||
#elif defined(SCO)
|
||||
#include "os/scoos.h"
|
||||
|
||||
#elif defined(SOLARIS)
|
||||
#include "os/solaris.h"
|
||||
|
||||
#elif defined(SUNOS4)
|
||||
#include "os/sunos.h"
|
||||
|
||||
#elif defined(UNIXWARE)
|
||||
#include "os/unixware.h"
|
||||
#endif
|
||||
|
||||
#endif /* XP_UNIX */
|
||||
|
||||
#endif /* jsosdep_h___ */
|
||||
91
mozilla/js/src/jsotypes.h
Normal file
91
mozilla/js/src/jsotypes.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This section typedefs the old 'native' types to the new PR<type>s.
|
||||
* These definitions are scheduled to be eliminated at the earliest
|
||||
* possible time. The NSPR API is implemented and documented using
|
||||
* the new definitions.
|
||||
*/
|
||||
|
||||
#ifndef PROTYPES_H
|
||||
#define PROTYPES_H
|
||||
|
||||
/* SVR4 typedef of uint is commonly found on UNIX machines. */
|
||||
#ifndef XP_UNIX
|
||||
typedef JSUintn uint;
|
||||
#endif
|
||||
|
||||
typedef JSUintn uintn;
|
||||
typedef JSUint64 uint64;
|
||||
#if !defined(XP_MAC) && !defined(_WIN32) && !defined(XP_OS2)
|
||||
typedef JSUint32 uint32;
|
||||
#else
|
||||
typedef unsigned long uint32;
|
||||
#endif
|
||||
typedef JSUint16 uint16;
|
||||
typedef JSUint8 uint8;
|
||||
|
||||
#ifndef _XP_Core_
|
||||
typedef JSIntn intn;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* On AIX 4.3, sys/inttypes.h (which is included by sys/types.h, a very
|
||||
* common header file) defines the types int8, int16, int32, and int64.
|
||||
* So we don't define these four types here to avoid conflicts in case
|
||||
* the code also includes sys/types.h.
|
||||
*/
|
||||
#ifdef AIX4_3
|
||||
#include <sys/inttypes.h>
|
||||
#else
|
||||
typedef JSInt64 int64;
|
||||
|
||||
/* /usr/include/model.h on HP-UX defines int8, int16, and int32 */
|
||||
#ifdef HPUX
|
||||
#include <model.h>
|
||||
#else
|
||||
#if !defined(WIN32) || !defined(_WINSOCK2API_) /* defines its own "int32" */
|
||||
#if !defined(XP_MAC) && !defined(_WIN32) && !defined(XP_OS2)
|
||||
typedef JSInt32 int32;
|
||||
#else
|
||||
typedef long int32;
|
||||
#endif
|
||||
#endif
|
||||
typedef JSInt16 int16;
|
||||
typedef JSInt8 int8;
|
||||
#endif /* HPUX */
|
||||
#endif /* AIX4_3 */
|
||||
|
||||
typedef JSFloat64 float64;
|
||||
|
||||
/* Re: jsbit.h */
|
||||
#define TEST_BIT JS_TEST_BIT
|
||||
#define SET_BIT JS_SET_BIT
|
||||
#define CLEAR_BIT JS_CLEAR_BIT
|
||||
|
||||
#ifdef XP_MAC
|
||||
#ifndef TRUE /* Mac standard is lower case true */
|
||||
#define TRUE 1
|
||||
#endif
|
||||
#ifndef FALSE /* Mac standard is lower case false */
|
||||
#define FALSE 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* !defined(PROTYPES_H) */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -25,7 +25,7 @@
|
||||
#include "jspubtd.h"
|
||||
#include "jsscan.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
* Parsing builds a tree of nodes that directs code generation. This tree is
|
||||
@@ -55,11 +55,11 @@ PR_BEGIN_EXTERN_C
|
||||
* Each sub-tree's root node has a pn_op in the set
|
||||
* JSOP_IMPORT{ALL,PROP,ELEM}
|
||||
* TOK_IF ternary pn_kid1: cond, pn_kid2: then, pn_kid3: else or null
|
||||
* TOK_SWITCH ternary pn_kid1: discriminant
|
||||
* pn_kid2: list of TOK_CASE nodes
|
||||
* pn_kid3: TOK_LC node for default statements or null
|
||||
* TOK_CASE binary pn_left: case expr
|
||||
* pn_right: TOK_LC node for case statements
|
||||
* TOK_SWITCH binary pn_left: discriminant
|
||||
* pn_right: list of TOK_CASE nodes, with at most one
|
||||
* TOK_DEFAULT node
|
||||
* TOK_CASE, binary pn_left: case expr or null if TOK_DEFAULT
|
||||
* TOK_DEFAULT pn_right: TOK_LC node for this case's statements
|
||||
* TOK_WHILE binary pn_left: cond, pn_right: body
|
||||
* TOK_DO binary pn_left: body, pn_right: cond
|
||||
* TOK_FOR binary pn_left: either
|
||||
@@ -125,6 +125,9 @@ PR_BEGIN_EXTERN_C
|
||||
* each has pn_left: property id, pn_right: value
|
||||
* #n={...} produces TOK_DEFSHARP at head of list
|
||||
* TOK_DEFSHARP unary pn_num: jsint value of n in #n=
|
||||
* pn_kid: null for #n=[...] and #n={...}, primary
|
||||
* if #n=primary for function, paren, name, object
|
||||
* literal expressions
|
||||
* TOK_USESHARP nullary pn_num: jsint value of n in #n#
|
||||
* TOK_RP unary pn_kid: parenthesized expression
|
||||
* TOK_NAME, name pn_atom: name, string, or object atom
|
||||
@@ -151,34 +154,34 @@ struct JSParseNode {
|
||||
JSParseNodeArity pn_arity;
|
||||
union {
|
||||
struct { /* TOK_FUNCTION node */
|
||||
JSFunction *fun; /* function object private data */
|
||||
JSParseNode *body; /* TOK_LC list of statements */
|
||||
JSFunction *fun; /* function object private data */
|
||||
JSParseNode *body; /* TOK_LC list of statements */
|
||||
uint32 tryCount; /* try statement count */
|
||||
} func;
|
||||
struct { /* list of next-linked nodes */
|
||||
struct { /* list of next-linked nodes */
|
||||
JSParseNode *head; /* first node in list */
|
||||
JSParseNode **tail; /* ptr to ptr to last node in list */
|
||||
uint32 count; /* number of nodes in list */
|
||||
JSBool extra; /* extra comma flag for [1,2,,] */
|
||||
} list;
|
||||
struct { /* ternary: if, switch, for(;;), ?: */
|
||||
JSParseNode *kid1; /* condition, discriminant, etc. */
|
||||
JSParseNode *kid2; /* then-part, case list, etc. */
|
||||
JSParseNode *kid3; /* else-part, default case, etc. */
|
||||
} list;
|
||||
struct { /* ternary: if, for(;;), ?: */
|
||||
JSParseNode *kid1; /* condition, discriminant, etc. */
|
||||
JSParseNode *kid2; /* then-part, case list, etc. */
|
||||
JSParseNode *kid3; /* else-part, default case, etc. */
|
||||
} ternary;
|
||||
struct { /* two kids if binary */
|
||||
JSParseNode *left;
|
||||
JSParseNode *right;
|
||||
struct { /* two kids if binary */
|
||||
JSParseNode *left;
|
||||
JSParseNode *right;
|
||||
jsval val; /* switch case value */
|
||||
} binary;
|
||||
struct { /* one kid if unary */
|
||||
JSParseNode *kid;
|
||||
jsint num; /* -1 or arg or local/sharp var num */
|
||||
} unary;
|
||||
struct { /* name, labeled statement, etc. */
|
||||
JSAtom *atom; /* name or label atom, null if slot */
|
||||
JSParseNode *expr; /* object or initializer */
|
||||
jsint slot; /* -1 or arg or local var slot */
|
||||
} binary;
|
||||
struct { /* one kid if unary */
|
||||
JSParseNode *kid;
|
||||
jsint num; /* -1 or arg or local/sharp var num */
|
||||
} unary;
|
||||
struct { /* name, labeled statement, etc. */
|
||||
JSAtom *atom; /* name or label atom, null if slot */
|
||||
JSParseNode *expr; /* object or initializer */
|
||||
jsint slot; /* -1 or arg or local var slot */
|
||||
} name;
|
||||
jsdouble dval; /* aligned numeric literal value */
|
||||
} pn_u;
|
||||
@@ -213,25 +216,25 @@ struct JSParseNode {
|
||||
((JSParseNode *)((char *)(list)->pn_tail - offsetof(JSParseNode, pn_next)))
|
||||
|
||||
#define PN_INIT_LIST(list) \
|
||||
PR_BEGIN_MACRO \
|
||||
(list)->pn_head = NULL; \
|
||||
(list)->pn_tail = &(list)->pn_head; \
|
||||
(list)->pn_count = 0; \
|
||||
PR_END_MACRO
|
||||
JS_BEGIN_MACRO \
|
||||
(list)->pn_head = NULL; \
|
||||
(list)->pn_tail = &(list)->pn_head; \
|
||||
(list)->pn_count = 0; \
|
||||
JS_END_MACRO
|
||||
|
||||
#define PN_INIT_LIST_1(list, pn) \
|
||||
PR_BEGIN_MACRO \
|
||||
(list)->pn_head = (pn); \
|
||||
(list)->pn_tail = &(pn)->pn_next; \
|
||||
(list)->pn_count = 1; \
|
||||
PR_END_MACRO
|
||||
JS_BEGIN_MACRO \
|
||||
(list)->pn_head = (pn); \
|
||||
(list)->pn_tail = &(pn)->pn_next; \
|
||||
(list)->pn_count = 1; \
|
||||
JS_END_MACRO
|
||||
|
||||
#define PN_APPEND(list, pn) \
|
||||
PR_BEGIN_MACRO \
|
||||
JS_BEGIN_MACRO \
|
||||
*(list)->pn_tail = (pn); \
|
||||
(list)->pn_tail = &(pn)->pn_next; \
|
||||
(list)->pn_count++; \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
/* New names to connote code generation in addition to parse tree gen. */
|
||||
#define js_CompileTokenStream js_Parse
|
||||
@@ -248,6 +251,6 @@ js_CompileFunctionBody(JSContext *cx, JSTokenStream *ts, JSFunction *fun);
|
||||
extern JSBool
|
||||
js_FoldConstants(JSContext *cx, JSParseNode *pn);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsparse_h___ */
|
||||
|
||||
@@ -25,13 +25,13 @@
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifndef MINI_NSPR
|
||||
#include "primpl.h"
|
||||
#endif
|
||||
#include "prprf.h"
|
||||
#include "prlong.h"
|
||||
#include "prlog.h"
|
||||
#include "prmem.h"
|
||||
#include <stdlib.h>
|
||||
#include "jsprf.h"
|
||||
#include "jslong.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
/* Removed by JSIFY: #include "jsmem.h"
|
||||
*/
|
||||
|
||||
/*
|
||||
** Note: on some platforms va_list is defined as an array,
|
||||
@@ -44,7 +44,7 @@
|
||||
#endif /*MKLINUX*/
|
||||
|
||||
/*
|
||||
** WARNING: This code may *NOT* call PR_LOG (because PR_LOG calls it)
|
||||
** WARNING: This code may *NOT* call JS_LOG (because JS_LOG calls it)
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -54,13 +54,13 @@
|
||||
typedef struct SprintfStateStr SprintfState;
|
||||
|
||||
struct SprintfStateStr {
|
||||
int (*stuff)(SprintfState *ss, const char *sp, PRUint32 len);
|
||||
int (*stuff)(SprintfState *ss, const char *sp, JSUint32 len);
|
||||
|
||||
char *base;
|
||||
char *cur;
|
||||
PRUint32 maxlen;
|
||||
JSUint32 maxlen;
|
||||
|
||||
int (*func)(void *arg, const char *sp, PRUint32 len);
|
||||
int (*func)(void *arg, const char *sp, JSUint32 len);
|
||||
void *arg;
|
||||
};
|
||||
|
||||
@@ -72,8 +72,8 @@ struct NumArgState{
|
||||
va_list ap; /* point to the corresponding position on ap */
|
||||
};
|
||||
|
||||
static PRBool l10n_debug_init = PR_FALSE;
|
||||
static PRBool l10n_debug = PR_FALSE;
|
||||
static JSBool l10n_debug_init = JS_FALSE;
|
||||
static JSBool l10n_debug = JS_FALSE;
|
||||
|
||||
#define NAS_DEFAULT_NUM 20 /* default number of NumberedArgumentState array */
|
||||
|
||||
@@ -270,16 +270,16 @@ static int cvt_l(SprintfState *ss, long num, int width, int prec, int radix,
|
||||
/*
|
||||
** Convert a 64-bit integer into its printable form
|
||||
*/
|
||||
static int cvt_ll(SprintfState *ss, PRInt64 num, int width, int prec, int radix,
|
||||
static int cvt_ll(SprintfState *ss, JSInt64 num, int width, int prec, int radix,
|
||||
int type, int flags, const char *hexp)
|
||||
{
|
||||
char cvtbuf[100];
|
||||
char *cvt;
|
||||
int digits;
|
||||
PRInt64 rad;
|
||||
JSInt64 rad;
|
||||
|
||||
/* according to the man page this needs to happen */
|
||||
if ((prec == 0) && (LL_IS_ZERO(num))) {
|
||||
if ((prec == 0) && (JSLL_IS_ZERO(num))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -288,14 +288,14 @@ static int cvt_ll(SprintfState *ss, PRInt64 num, int width, int prec, int radix,
|
||||
** need to stop when we hit 10 digits. In the signed case, we can
|
||||
** stop when the number is zero.
|
||||
*/
|
||||
LL_I2L(rad, radix);
|
||||
JSLL_I2L(rad, radix);
|
||||
cvt = cvtbuf + sizeof(cvtbuf);
|
||||
digits = 0;
|
||||
while (!LL_IS_ZERO(num)) {
|
||||
PRInt32 digit;
|
||||
PRInt64 quot, rem;
|
||||
LL_UDIVMOD(", &rem, num, rad);
|
||||
LL_L2I(digit, rem);
|
||||
while (!JSLL_IS_ZERO(num)) {
|
||||
JSInt32 digit;
|
||||
JSInt64 quot, rem;
|
||||
JSLL_UDIVMOD(", &rem, num, rad);
|
||||
JSLL_L2I(digit, rem);
|
||||
*--cvt = hexp[digit & 0xf];
|
||||
digits++;
|
||||
num = quot;
|
||||
@@ -324,7 +324,7 @@ static int cvt_f(SprintfState *ss, double d, const char *fmt0, const char *fmt1)
|
||||
char fout[300];
|
||||
int amount = fmt1 - fmt0;
|
||||
|
||||
PR_ASSERT((amount > 0) && (amount < sizeof(fin)));
|
||||
JS_ASSERT((amount > 0) && (amount < sizeof(fin)));
|
||||
if (amount >= sizeof(fin)) {
|
||||
/* Totally bogus % command to sprintf. Just ignore it */
|
||||
return 0;
|
||||
@@ -337,7 +337,7 @@ static int cvt_f(SprintfState *ss, double d, const char *fmt0, const char *fmt1)
|
||||
{
|
||||
const char *p = fin;
|
||||
while (*p) {
|
||||
PR_ASSERT(*p != 'L');
|
||||
JS_ASSERT(*p != 'L');
|
||||
p++;
|
||||
}
|
||||
}
|
||||
@@ -349,7 +349,7 @@ static int cvt_f(SprintfState *ss, double d, const char *fmt0, const char *fmt1)
|
||||
** debugging on. At least this way we can track down the evil piece
|
||||
** of calling code and fix it!
|
||||
*/
|
||||
PR_ASSERT(strlen(fout) < sizeof(fout));
|
||||
JS_ASSERT(strlen(fout) < sizeof(fout));
|
||||
|
||||
return (*ss->stuff)(ss, fout, strlen(fout));
|
||||
}
|
||||
@@ -400,10 +400,10 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv,
|
||||
** 'cause getenv does take time
|
||||
*/
|
||||
if( !l10n_debug_init ){
|
||||
l10n_debug_init = PR_TRUE;
|
||||
l10n_debug_init = JS_TRUE;
|
||||
p = getenv( "NETSCAPE_LOCALIZATION_DEBUG" );
|
||||
if( ( p != NULL ) && ( *p == '1' ) ){
|
||||
l10n_debug = PR_TRUE;
|
||||
l10n_debug = JS_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,11 +456,11 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv,
|
||||
|
||||
|
||||
if( number > NAS_DEFAULT_NUM ){
|
||||
nas = (struct NumArgState*)PR_MALLOC( number * sizeof( struct NumArgState ) );
|
||||
nas = (struct NumArgState*)malloc( number * sizeof( struct NumArgState ) );
|
||||
if( !nas ){
|
||||
*rv = -1;
|
||||
if( l10n_debug )
|
||||
printf( "PR_MALLOC() error for \"%s\"\n", fmt );
|
||||
printf( "malloc() error for \"%s\"\n", fmt );
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
@@ -569,11 +569,11 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv,
|
||||
|
||||
case 'p':
|
||||
/* XXX should use cpp */
|
||||
if (sizeof(void *) == sizeof(PRInt32)) {
|
||||
if (sizeof(void *) == sizeof(JSInt32)) {
|
||||
nas[ cn ].type = TYPE_UINT32;
|
||||
} else if (sizeof(void *) == sizeof(PRInt64)) {
|
||||
} else if (sizeof(void *) == sizeof(JSInt64)) {
|
||||
nas[ cn ].type = TYPE_UINT64;
|
||||
} else if (sizeof(void *) == sizeof(PRIntn)) {
|
||||
} else if (sizeof(void *) == sizeof(JSIntn)) {
|
||||
nas[ cn ].type = TYPE_UINTN;
|
||||
} else {
|
||||
nas[ cn ].type = TYPE_UNKNOWN;
|
||||
@@ -585,7 +585,7 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv,
|
||||
case 'E':
|
||||
case 'G':
|
||||
/* XXX not supported I suppose */
|
||||
PR_ASSERT(0);
|
||||
JS_ASSERT(0);
|
||||
nas[ cn ].type = TYPE_UNKNOWN;
|
||||
break;
|
||||
|
||||
@@ -598,7 +598,7 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv,
|
||||
break;
|
||||
|
||||
default:
|
||||
PR_ASSERT(0);
|
||||
JS_ASSERT(0);
|
||||
nas[ cn ].type = TYPE_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
@@ -620,7 +620,7 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv,
|
||||
|
||||
if( *rv < 0 ){
|
||||
if( nas != nasArray )
|
||||
PR_DELETE( nas );
|
||||
JS_DELETE( nas );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -637,25 +637,25 @@ static struct NumArgState* BuildArgArray( const char *fmt, va_list ap, int* rv,
|
||||
case TYPE_INT16:
|
||||
case TYPE_UINT16:
|
||||
case TYPE_INTN:
|
||||
case TYPE_UINTN: (void)va_arg( ap, PRIntn ); break;
|
||||
case TYPE_UINTN: (void)va_arg( ap, JSIntn ); break;
|
||||
|
||||
case TYPE_INT32: (void)va_arg( ap, PRInt32 ); break;
|
||||
case TYPE_INT32: (void)va_arg( ap, JSInt32 ); break;
|
||||
|
||||
case TYPE_UINT32: (void)va_arg( ap, PRUint32 ); break;
|
||||
case TYPE_UINT32: (void)va_arg( ap, JSUint32 ); break;
|
||||
|
||||
case TYPE_INT64: (void)va_arg( ap, PRInt64 ); break;
|
||||
case TYPE_INT64: (void)va_arg( ap, JSInt64 ); break;
|
||||
|
||||
case TYPE_UINT64: (void)va_arg( ap, PRUint64 ); break;
|
||||
case TYPE_UINT64: (void)va_arg( ap, JSUint64 ); break;
|
||||
|
||||
case TYPE_STRING: (void)va_arg( ap, char* ); break;
|
||||
|
||||
case TYPE_INTSTR: (void)va_arg( ap, PRIntn* ); break;
|
||||
case TYPE_INTSTR: (void)va_arg( ap, JSIntn* ); break;
|
||||
|
||||
case TYPE_DOUBLE: (void)va_arg( ap, double ); break;
|
||||
|
||||
default:
|
||||
if( nas != nasArray )
|
||||
PR_DELETE( nas );
|
||||
JS_DELETE( nas );
|
||||
*rv = -1;
|
||||
return NULL;
|
||||
}
|
||||
@@ -678,7 +678,7 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
|
||||
char ch;
|
||||
int i;
|
||||
long l;
|
||||
PRInt64 ll;
|
||||
JSInt64 ll;
|
||||
double d;
|
||||
const char *s;
|
||||
int *ip;
|
||||
@@ -702,7 +702,7 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
|
||||
nas = BuildArgArray( fmt, ap, &rv, nasArray );
|
||||
if( rv < 0 ){
|
||||
/* the fmt contains error Numbered Argument format, jliu@netscape.com */
|
||||
PR_ASSERT(0);
|
||||
JS_ASSERT(0);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -743,7 +743,7 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
|
||||
if( l10n_debug )
|
||||
printf( "numbered argument type unknown\n" );
|
||||
if( nas && ( nas != nasArray ) )
|
||||
PR_DELETE( nas );
|
||||
JS_DELETE( nas );
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -867,14 +867,14 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
|
||||
goto do_long;
|
||||
|
||||
case TYPE_INT32:
|
||||
u.l = va_arg(ap, PRInt32);
|
||||
u.l = va_arg(ap, JSInt32);
|
||||
if (u.l < 0) {
|
||||
u.l = -u.l;
|
||||
flags |= _NEG;
|
||||
}
|
||||
goto do_long;
|
||||
case TYPE_UINT32:
|
||||
u.l = (long)va_arg(ap, PRUint32);
|
||||
u.l = (long)va_arg(ap, JSUint32);
|
||||
do_long:
|
||||
rv = cvt_l(ss, u.l, width, prec, radix, type, flags, hexp);
|
||||
if (rv < 0) {
|
||||
@@ -883,14 +883,14 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
|
||||
break;
|
||||
|
||||
case TYPE_INT64:
|
||||
u.ll = va_arg(ap, PRInt64);
|
||||
if (!LL_GE_ZERO(u.ll)) {
|
||||
LL_NEG(u.ll, u.ll);
|
||||
u.ll = va_arg(ap, JSInt64);
|
||||
if (!JSLL_GE_ZERO(u.ll)) {
|
||||
JSLL_NEG(u.ll, u.ll);
|
||||
flags |= _NEG;
|
||||
}
|
||||
goto do_longlong;
|
||||
case TYPE_UINT64:
|
||||
u.ll = va_arg(ap, PRUint64);
|
||||
u.ll = va_arg(ap, JSUint64);
|
||||
do_longlong:
|
||||
rv = cvt_ll(ss, u.ll, width, prec, radix, type, flags, hexp);
|
||||
if (rv < 0) {
|
||||
@@ -945,14 +945,14 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
if (sizeof(void *) == sizeof(PRInt32)) {
|
||||
if (sizeof(void *) == sizeof(JSInt32)) {
|
||||
type = TYPE_UINT32;
|
||||
} else if (sizeof(void *) == sizeof(PRInt64)) {
|
||||
} else if (sizeof(void *) == sizeof(JSInt64)) {
|
||||
type = TYPE_UINT64;
|
||||
} else if (sizeof(void *) == sizeof(int)) {
|
||||
type = TYPE_UINTN;
|
||||
} else {
|
||||
PR_ASSERT(0);
|
||||
JS_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
radix = 16;
|
||||
@@ -964,7 +964,7 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
|
||||
case 'E':
|
||||
case 'G':
|
||||
/* XXX not supported I suppose */
|
||||
PR_ASSERT(0);
|
||||
JS_ASSERT(0);
|
||||
break;
|
||||
#endif
|
||||
|
||||
@@ -986,7 +986,7 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
|
||||
default:
|
||||
/* Not a % token after all... skip it */
|
||||
#if 0
|
||||
PR_ASSERT(0);
|
||||
JS_ASSERT(0);
|
||||
#endif
|
||||
rv = (*ss->stuff)(ss, "%", 1);
|
||||
if (rv < 0) {
|
||||
@@ -1003,7 +1003,7 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
|
||||
rv = (*ss->stuff)(ss, "\0", 1);
|
||||
|
||||
if( nas && ( nas != nasArray ) ){
|
||||
PR_DELETE( nas );
|
||||
JS_DELETE( nas );
|
||||
}
|
||||
|
||||
return rv;
|
||||
@@ -1011,7 +1011,7 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
static int FuncStuff(SprintfState *ss, const char *sp, PRUint32 len)
|
||||
static int FuncStuff(SprintfState *ss, const char *sp, JSUint32 len)
|
||||
{
|
||||
int rv;
|
||||
|
||||
@@ -1023,19 +1023,19 @@ static int FuncStuff(SprintfState *ss, const char *sp, PRUint32 len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(PRUint32) PR_sxprintf(PRStuffFunc func, void *arg,
|
||||
IMPLEMENT(JSUint32) JS_sxprintf(JSStuffFunc func, void *arg,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int rv;
|
||||
|
||||
va_start(ap, fmt);
|
||||
rv = PR_vsxprintf(func, arg, fmt, ap);
|
||||
rv = JS_vsxprintf(func, arg, fmt, ap);
|
||||
va_end(ap);
|
||||
return rv;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(PRUint32) PR_vsxprintf(PRStuffFunc func, void *arg,
|
||||
IMPLEMENT(JSUint32) JS_vsxprintf(JSStuffFunc func, void *arg,
|
||||
const char *fmt, va_list ap)
|
||||
{
|
||||
SprintfState ss;
|
||||
@@ -1046,27 +1046,27 @@ PR_IMPLEMENT(PRUint32) PR_vsxprintf(PRStuffFunc func, void *arg,
|
||||
ss.arg = arg;
|
||||
ss.maxlen = 0;
|
||||
rv = dosprintf(&ss, fmt, ap);
|
||||
return (rv < 0) ? (PRUint32)-1 : ss.maxlen;
|
||||
return (rv < 0) ? (JSUint32)-1 : ss.maxlen;
|
||||
}
|
||||
|
||||
/*
|
||||
** Stuff routine that automatically grows the malloc'd output buffer
|
||||
** before it overflows.
|
||||
*/
|
||||
static int GrowStuff(SprintfState *ss, const char *sp, PRUint32 len)
|
||||
static int GrowStuff(SprintfState *ss, const char *sp, JSUint32 len)
|
||||
{
|
||||
ptrdiff_t off;
|
||||
char *newbase;
|
||||
PRUint32 newlen;
|
||||
JSUint32 newlen;
|
||||
|
||||
off = ss->cur - ss->base;
|
||||
if (off + len >= ss->maxlen) {
|
||||
/* Grow the buffer */
|
||||
newlen = ss->maxlen + ((len > 32) ? len : 32);
|
||||
if (ss->base) {
|
||||
newbase = (char*) PR_REALLOC(ss->base, newlen);
|
||||
newbase = (char*) realloc(ss->base, newlen);
|
||||
} else {
|
||||
newbase = (char*) PR_MALLOC(newlen);
|
||||
newbase = (char*) malloc(newlen);
|
||||
}
|
||||
if (!newbase) {
|
||||
/* Ran out of memory */
|
||||
@@ -1082,33 +1082,33 @@ static int GrowStuff(SprintfState *ss, const char *sp, PRUint32 len)
|
||||
--len;
|
||||
*ss->cur++ = *sp++;
|
||||
}
|
||||
PR_ASSERT((PRUint32)(ss->cur - ss->base) <= ss->maxlen);
|
||||
JS_ASSERT((JSUint32)(ss->cur - ss->base) <= ss->maxlen);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** sprintf into a malloc'd buffer
|
||||
*/
|
||||
PR_IMPLEMENT(char *) PR_smprintf(const char *fmt, ...)
|
||||
IMPLEMENT(char *) JS_smprintf(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *rv;
|
||||
|
||||
va_start(ap, fmt);
|
||||
rv = PR_vsmprintf(fmt, ap);
|
||||
rv = JS_vsmprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
** Free memory allocated, for the caller, by PR_smprintf
|
||||
** Free memory allocated, for the caller, by JS_smprintf
|
||||
*/
|
||||
PR_IMPLEMENT(void) PR_smprintf_free(char *mem)
|
||||
IMPLEMENT(void) JS_smprintf_free(char *mem)
|
||||
{
|
||||
PR_DELETE(mem);
|
||||
JS_DELETE(mem);
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(char *) PR_vsmprintf(const char *fmt, va_list ap)
|
||||
IMPLEMENT(char *) JS_vsmprintf(const char *fmt, va_list ap)
|
||||
{
|
||||
SprintfState ss;
|
||||
int rv;
|
||||
@@ -1120,7 +1120,7 @@ PR_IMPLEMENT(char *) PR_vsmprintf(const char *fmt, va_list ap)
|
||||
rv = dosprintf(&ss, fmt, ap);
|
||||
if (rv < 0) {
|
||||
if (ss.base) {
|
||||
PR_DELETE(ss.base);
|
||||
JS_DELETE(ss.base);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1130,9 +1130,9 @@ PR_IMPLEMENT(char *) PR_vsmprintf(const char *fmt, va_list ap)
|
||||
/*
|
||||
** Stuff routine that discards overflow data
|
||||
*/
|
||||
static int LimitStuff(SprintfState *ss, const char *sp, PRUint32 len)
|
||||
static int LimitStuff(SprintfState *ss, const char *sp, JSUint32 len)
|
||||
{
|
||||
PRUint32 limit = ss->maxlen - (ss->cur - ss->base);
|
||||
JSUint32 limit = ss->maxlen - (ss->cur - ss->base);
|
||||
|
||||
if (len > limit) {
|
||||
len = limit;
|
||||
@@ -1148,30 +1148,30 @@ static int LimitStuff(SprintfState *ss, const char *sp, PRUint32 len)
|
||||
** sprintf into a fixed size buffer. Make sure there is a NUL at the end
|
||||
** when finished.
|
||||
*/
|
||||
PR_IMPLEMENT(PRUint32) PR_snprintf(char *out, PRUint32 outlen, const char *fmt, ...)
|
||||
IMPLEMENT(JSUint32) JS_snprintf(char *out, JSUint32 outlen, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int rv;
|
||||
|
||||
PR_ASSERT((PRInt32)outlen > 0);
|
||||
if ((PRInt32)outlen <= 0) {
|
||||
JS_ASSERT((JSInt32)outlen > 0);
|
||||
if ((JSInt32)outlen <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
va_start(ap, fmt);
|
||||
rv = PR_vsnprintf(out, outlen, fmt, ap);
|
||||
rv = JS_vsnprintf(out, outlen, fmt, ap);
|
||||
va_end(ap);
|
||||
return rv;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(PRUint32) PR_vsnprintf(char *out, PRUint32 outlen,const char *fmt,
|
||||
IMPLEMENT(JSUint32) JS_vsnprintf(char *out, JSUint32 outlen,const char *fmt,
|
||||
va_list ap)
|
||||
{
|
||||
SprintfState ss;
|
||||
PRUint32 n;
|
||||
JSUint32 n;
|
||||
|
||||
PR_ASSERT((PRInt32)outlen > 0);
|
||||
if ((PRInt32)outlen <= 0) {
|
||||
JS_ASSERT((JSInt32)outlen > 0);
|
||||
if ((JSInt32)outlen <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1189,18 +1189,18 @@ PR_IMPLEMENT(PRUint32) PR_vsnprintf(char *out, PRUint32 outlen,const char *fmt,
|
||||
return n ? n - 1 : n;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(char *) PR_sprintf_append(char *last, const char *fmt, ...)
|
||||
IMPLEMENT(char *) JS_sprintf_append(char *last, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *rv;
|
||||
|
||||
va_start(ap, fmt);
|
||||
rv = PR_vsprintf_append(last, fmt, ap);
|
||||
rv = JS_vsprintf_append(last, fmt, ap);
|
||||
va_end(ap);
|
||||
return rv;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(char *) PR_vsprintf_append(char *last, const char *fmt, va_list ap)
|
||||
IMPLEMENT(char *) JS_vsprintf_append(char *last, const char *fmt, va_list ap)
|
||||
{
|
||||
SprintfState ss;
|
||||
int rv;
|
||||
@@ -1219,7 +1219,7 @@ PR_IMPLEMENT(char *) PR_vsprintf_append(char *last, const char *fmt, va_list ap)
|
||||
rv = dosprintf(&ss, fmt, ap);
|
||||
if (rv < 0) {
|
||||
if (ss.base) {
|
||||
PR_DELETE(ss.base);
|
||||
JS_DELETE(ss.base);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -16,8 +16,8 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef prprf_h___
|
||||
#define prprf_h___
|
||||
#ifndef jsprf_h___
|
||||
#define jsprf_h___
|
||||
|
||||
/*
|
||||
** API for PR printf like routines. Supports the following formats
|
||||
@@ -35,84 +35,75 @@
|
||||
** %f - float
|
||||
** %g - float
|
||||
*/
|
||||
#include "prtypes.h"
|
||||
#ifndef MINI_NSPR
|
||||
#include "prio.h"
|
||||
#endif
|
||||
#include "jstypes.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
** sprintf into a fixed size buffer. Guarantees that a NUL is at the end
|
||||
** of the buffer. Returns the length of the written output, NOT including
|
||||
** the NUL, or (PRUint32)-1 if an error occurs.
|
||||
** the NUL, or (JSUint32)-1 if an error occurs.
|
||||
*/
|
||||
PR_EXTERN(PRUint32) PR_snprintf(char *out, PRUint32 outlen, const char *fmt, ...);
|
||||
EXTERN(JSUint32) JS_snprintf(char *out, JSUint32 outlen, const char *fmt, ...);
|
||||
|
||||
/*
|
||||
** sprintf into a PR_MALLOC'd buffer. Return a pointer to the malloc'd
|
||||
** buffer on success, NULL on failure. Call "PR_smprintf_free" to release
|
||||
** sprintf into a malloc'd buffer. Return a pointer to the malloc'd
|
||||
** buffer on success, NULL on failure. Call "JS_smprintf_free" to release
|
||||
** the memory returned.
|
||||
*/
|
||||
PR_EXTERN(char*) PR_smprintf(const char *fmt, ...);
|
||||
EXTERN(char*) JS_smprintf(const char *fmt, ...);
|
||||
|
||||
/*
|
||||
** Free the memory allocated, for the caller, by PR_smprintf
|
||||
** Free the memory allocated, for the caller, by JS_smprintf
|
||||
*/
|
||||
PR_EXTERN(void) PR_smprintf_free(char *mem);
|
||||
EXTERN(void) JS_smprintf_free(char *mem);
|
||||
|
||||
/*
|
||||
** "append" sprintf into a PR_MALLOC'd buffer. "last" is the last value of
|
||||
** the PR_MALLOC'd buffer. sprintf will append data to the end of last,
|
||||
** growing it as necessary using realloc. If last is NULL, PR_sprintf_append
|
||||
** "append" sprintf into a malloc'd buffer. "last" is the last value of
|
||||
** the malloc'd buffer. sprintf will append data to the end of last,
|
||||
** growing it as necessary using realloc. If last is NULL, JS_sprintf_append
|
||||
** will allocate the initial string. The return value is the new value of
|
||||
** last for subsequent calls, or NULL if there is a malloc failure.
|
||||
*/
|
||||
PR_EXTERN(char*) PR_sprintf_append(char *last, const char *fmt, ...);
|
||||
EXTERN(char*) JS_sprintf_append(char *last, const char *fmt, ...);
|
||||
|
||||
/*
|
||||
** sprintf into a function. The function "f" is called with a string to
|
||||
** place into the output. "arg" is an opaque pointer used by the stuff
|
||||
** function to hold any state needed to do the storage of the output
|
||||
** data. The return value is a count of the number of characters fed to
|
||||
** the stuff function, or (PRUint32)-1 if an error occurs.
|
||||
** the stuff function, or (JSUint32)-1 if an error occurs.
|
||||
*/
|
||||
typedef PRIntn (*PRStuffFunc)(void *arg, const char *s, PRUint32 slen);
|
||||
typedef JSIntn (*JSStuffFunc)(void *arg, const char *s, JSUint32 slen);
|
||||
|
||||
PR_EXTERN(PRUint32) PR_sxprintf(PRStuffFunc f, void *arg, const char *fmt, ...);
|
||||
|
||||
/*
|
||||
** fprintf to a PRFileDesc
|
||||
*/
|
||||
PR_EXTERN(PRUint32) PR_fprintf(struct PRFileDesc* fd, const char *fmt, ...);
|
||||
EXTERN(JSUint32) JS_sxprintf(JSStuffFunc f, void *arg, const char *fmt, ...);
|
||||
|
||||
/*
|
||||
** va_list forms of the above.
|
||||
*/
|
||||
PR_EXTERN(PRUint32) PR_vsnprintf(char *out, PRUint32 outlen, const char *fmt, va_list ap);
|
||||
PR_EXTERN(char*) PR_vsmprintf(const char *fmt, va_list ap);
|
||||
PR_EXTERN(char*) PR_vsprintf_append(char *last, const char *fmt, va_list ap);
|
||||
PR_EXTERN(PRUint32) PR_vsxprintf(PRStuffFunc f, void *arg, const char *fmt, va_list ap);
|
||||
PR_EXTERN(PRUint32) PR_vfprintf(struct PRFileDesc* fd, const char *fmt, va_list ap);
|
||||
EXTERN(JSUint32) JS_vsnprintf(char *out, JSUint32 outlen, const char *fmt, va_list ap);
|
||||
EXTERN(char*) JS_vsmprintf(const char *fmt, va_list ap);
|
||||
EXTERN(char*) JS_vsprintf_append(char *last, const char *fmt, va_list ap);
|
||||
EXTERN(JSUint32) JS_vsxprintf(JSStuffFunc f, void *arg, const char *fmt, va_list ap);
|
||||
|
||||
/*
|
||||
***************************************************************************
|
||||
** FUNCTION: PR_sscanf
|
||||
** FUNCTION: JS_sscanf
|
||||
** DESCRIPTION:
|
||||
** PR_sscanf() scans the input character string, performs data
|
||||
** JS_sscanf() scans the input character string, performs data
|
||||
** conversions, and stores the converted values in the data objects
|
||||
** pointed to by its arguments according to the format control
|
||||
** string.
|
||||
**
|
||||
** PR_sscanf() behaves the same way as the sscanf() function in the
|
||||
** JS_sscanf() behaves the same way as the sscanf() function in the
|
||||
** Standard C Library (stdio.h), with the following exceptions:
|
||||
** - PR_sscanf() handles the NSPR integer and floating point types,
|
||||
** such as PRInt16, PRInt32, PRInt64, and PRFloat64, whereas
|
||||
** - JS_sscanf() handles the NSPR integer and floating point types,
|
||||
** such as JSInt16, JSInt32, JSInt64, and JSFloat64, whereas
|
||||
** sscanf() handles the standard C types like short, int, long,
|
||||
** and double.
|
||||
** - PR_sscanf() has no multibyte character support, while sscanf()
|
||||
** - JS_sscanf() has no multibyte character support, while sscanf()
|
||||
** does.
|
||||
** INPUTS:
|
||||
** const char *buf
|
||||
@@ -123,15 +114,15 @@ PR_EXTERN(PRUint32) PR_vfprintf(struct PRFileDesc* fd, const char *fmt, va_list
|
||||
** variable number of arguments, each of them is a pointer to
|
||||
** a data object in which the converted value will be stored
|
||||
** OUTPUTS: none
|
||||
** RETURNS: PRInt32
|
||||
** RETURNS: JSInt32
|
||||
** The number of values converted and stored.
|
||||
** RESTRICTIONS:
|
||||
** Multibyte characters in 'buf' or 'fmt' are not allowed.
|
||||
***************************************************************************
|
||||
*/
|
||||
|
||||
PR_EXTERN(PRInt32) PR_sscanf(const char *buf, const char *fmt, ...);
|
||||
EXTERN(JSInt32) JS_sscanf(const char *buf, const char *fmt, ...);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* prprf_h___ */
|
||||
#endif /* jsprf_h___ */
|
||||
131
mozilla/js/src/jsprhash.h
Normal file
131
mozilla/js/src/jsprhash.h
Normal file
@@ -0,0 +1,131 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef JSplhash_h___
|
||||
#define JSplhash_h___
|
||||
/*
|
||||
* API to portable hash table code.
|
||||
*/
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include "jsprtypes.h"
|
||||
|
||||
JSPR_BEGIN_EXTERN_C
|
||||
|
||||
typedef struct JSPRHashEntry JSPRHashEntry;
|
||||
typedef struct JSPRHashTable JSPRHashTable;
|
||||
typedef JSPRUint32 JSPRHashNumber;
|
||||
#define JSPR_HASH_BITS 32
|
||||
typedef JSPRHashNumber (JSCALLBACK *JSPRHashFunction)(const void *key);
|
||||
typedef JSPRIntn (JSCALLBACK *JSPRHashComparator)(const void *v1, const void *v2);
|
||||
typedef JSPRIntn (JSCALLBACK *JSPRHashEnumerator)(JSPRHashEntry *he, JSPRIntn i, void *arg);
|
||||
|
||||
/* Flag bits in JSPRHashEnumerator's return value */
|
||||
#define HT_ENUMERATE_NEXT 0 /* continue enumerating entries */
|
||||
#define HT_ENUMERATE_STOP 1 /* stop enumerating entries */
|
||||
#define HT_ENUMERATE_REMOVE 2 /* remove and free the current entry */
|
||||
#define HT_ENUMERATE_UNHASH 4 /* just unhash the current entry */
|
||||
|
||||
typedef struct JSPRHashAllocOps {
|
||||
void * (JSCALLBACK *allocTable)(void *pool, JSPRSize size);
|
||||
void (JSCALLBACK *freeTable)(void *pool, void *item);
|
||||
JSPRHashEntry * (JSCALLBACK *allocEntry)(void *pool, const void *key);
|
||||
void (JSCALLBACK *freeEntry)(void *pool, JSPRHashEntry *he, JSPRUintn flag);
|
||||
} JSPRHashAllocOps;
|
||||
|
||||
#define HT_FREE_VALUE 0 /* just free the entry's value */
|
||||
#define HT_FREE_ENTRY 1 /* free value and entire entry */
|
||||
|
||||
struct JSPRHashEntry {
|
||||
JSPRHashEntry *next; /* hash chain linkage */
|
||||
JSPRHashNumber keyHash; /* key hash function result */
|
||||
const void *key; /* ptr to opaque key */
|
||||
void *value; /* ptr to opaque value */
|
||||
};
|
||||
|
||||
struct JSPRHashTable {
|
||||
JSPRHashEntry **buckets; /* vector of hash buckets */
|
||||
JSPRUint32 nentries; /* number of entries in table */
|
||||
JSPRUint32 shift; /* multiplicative hash shift */
|
||||
JSPRHashFunction keyHash; /* key hash function */
|
||||
JSPRHashComparator keyCompare; /* key comparison function */
|
||||
JSPRHashComparator valueCompare; /* value comparison function */
|
||||
JSPRHashAllocOps *allocOps; /* allocation operations */
|
||||
void *allocPriv; /* allocation private data */
|
||||
#ifdef HASHMETER
|
||||
JSPRUint32 nlookups; /* total number of lookups */
|
||||
JSPRUint32 nsteps; /* number of hash chains traversed */
|
||||
JSPRUint32 ngrows; /* number of table expansions */
|
||||
JSPRUint32 nshrinks; /* number of table contractions */
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
* Create a new hash table.
|
||||
* If allocOps is null, use default allocator ops built on top of malloc().
|
||||
*/
|
||||
JSEXTERN(JSPRHashTable *)
|
||||
JSPR_NewHashTable(JSPRUint32 n, JSPRHashFunction keyHash,
|
||||
JSPRHashComparator keyCompare, JSPRHashComparator valueCompare,
|
||||
JSPRHashAllocOps *allocOps, void *allocPriv);
|
||||
|
||||
JSEXTERN(void)
|
||||
JSPR_HashTableDestroy(JSPRHashTable *ht);
|
||||
|
||||
/* Low level access methods */
|
||||
JSEXTERN(JSPRHashEntry **)
|
||||
JSPR_HashTableRawLookup(JSPRHashTable *ht, JSPRHashNumber keyHash, const void *key);
|
||||
|
||||
JSEXTERN(JSPRHashEntry *)
|
||||
JSPR_HashTableRawAdd(JSPRHashTable *ht, JSPRHashEntry **hep, JSPRHashNumber keyHash,
|
||||
const void *key, void *value);
|
||||
|
||||
JSEXTERN(void)
|
||||
JSPR_HashTableRawRemove(JSPRHashTable *ht, JSPRHashEntry **hep, JSPRHashEntry *he);
|
||||
|
||||
/* Higher level access methods */
|
||||
JSEXTERN(JSPRHashEntry *)
|
||||
JSPR_HashTableAdd(JSPRHashTable *ht, const void *key, void *value);
|
||||
|
||||
JSEXTERN(JSPRBool)
|
||||
JSPR_HashTableRemove(JSPRHashTable *ht, const void *key);
|
||||
|
||||
JSEXTERN(JSPRIntn)
|
||||
JSPR_HashTableEnumerateEntries(JSPRHashTable *ht, JSPRHashEnumerator f, void *arg);
|
||||
|
||||
JSEXTERN(void *)
|
||||
JSPR_HashTableLookup(JSPRHashTable *ht, const void *key);
|
||||
|
||||
JSEXTERN(JSPRIntn)
|
||||
JSPR_HashTableDump(JSPRHashTable *ht, JSPRHashEnumerator dump, FILE *fp);
|
||||
|
||||
/* General-purpose C string hash function. */
|
||||
JSEXTERN(JSPRHashNumber)
|
||||
JSPR_HashString(const void *key);
|
||||
|
||||
/* Compare strings using strcmp(), return true if equal. */
|
||||
JSEXTERN(int)
|
||||
JSPR_CompareStrings(const void *v1, const void *v2);
|
||||
|
||||
/* Stub function just returns v1 == v2 */
|
||||
JSEXTERN(JSPRIntn)
|
||||
JSPR_CompareValues(const void *v1, const void *v2);
|
||||
|
||||
JSPR_END_EXTERN_C
|
||||
|
||||
#endif /* JSplhash_h___ */
|
||||
@@ -77,23 +77,72 @@ typedef enum JSTrapStatus {
|
||||
JSTRAP_LIMIT
|
||||
} JSTrapStatus;
|
||||
|
||||
#ifndef CRT_CALL
|
||||
#ifdef XP_OS2
|
||||
#define CRT_CALL _Optlink
|
||||
#else
|
||||
#define CRT_CALL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef JSTrapStatus
|
||||
(*JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval,
|
||||
void *closure);
|
||||
(* CRT_CALL JSTrapHandler)(JSContext *cx, JSScript *script, jsbytecode *pc,
|
||||
jsval *rval, void *closure);
|
||||
|
||||
typedef JSBool
|
||||
(* CRT_CALL JSWatchPointHandler)(JSContext *cx, JSObject *obj, jsval id,
|
||||
jsval old, jsval *newp, void *closure);
|
||||
|
||||
/* called just after script creation */
|
||||
typedef void
|
||||
(*JSNewScriptHook)( JSContext *cx,
|
||||
const char *filename, /* URL this script loads from */
|
||||
uintN lineno, /* line where this script starts */
|
||||
JSScript *script,
|
||||
JSFunction *fun,
|
||||
void *callerdata );
|
||||
(* CRT_CALL JSNewScriptHook)(JSContext *cx,
|
||||
const char *filename, /* URL of script */
|
||||
uintN lineno, /* line script starts */
|
||||
JSScript *script,
|
||||
JSFunction *fun,
|
||||
void *callerdata);
|
||||
|
||||
/* called just before script destruction */
|
||||
typedef void
|
||||
(*JSDestroyScriptHook)( JSContext *cx,
|
||||
JSScript *script,
|
||||
void *callerdata );
|
||||
(* CRT_CALL JSDestroyScriptHook)(JSContext *cx,
|
||||
JSScript *script,
|
||||
void *callerdata);
|
||||
|
||||
typedef void
|
||||
(* CRT_CALL JSSourceHandler)(const char *filename, uintN lineno,
|
||||
jschar *str, size_t length,
|
||||
void **listenerTSData, void *closure);
|
||||
|
||||
/*
|
||||
* This hook captures high level script execution and function calls
|
||||
* (JS or native).
|
||||
* It is used by JS_SetExecuteHook to hook top level scripts and by
|
||||
* JS_SetCallHook to hook function calls.
|
||||
* It will get called twice per script or function call:
|
||||
* just before execution begins and just after it finishes. In both cases
|
||||
* the 'current' frame is that of the executing code.
|
||||
*
|
||||
* The 'before' param is JS_TRUE for the hook invocation before the execution
|
||||
* and JS_FALSE for the invocation after the code has run.
|
||||
*
|
||||
* The 'ok' param is significant only on the post execution invocation to
|
||||
* signify whether or not the code completed 'normally'.
|
||||
*
|
||||
* The 'closure' param is as passed to JS_SetExecuteHook or JS_SetCallHook
|
||||
* for the 'before'invocation, but is whatever value is returned from that
|
||||
* invocation for the 'after' invocation. Thus, the hook implementor *could*
|
||||
* allocate a stucture in the 'before' invocation and return a pointer
|
||||
* to that structure. The pointer would then be handed to the hook for
|
||||
* the 'after' invocation. Alternately, the 'before' could just return the
|
||||
* same value as in 'closure' to cause the 'after' invocation to be called
|
||||
* with the same 'closure' value as the 'before'.
|
||||
*
|
||||
* Returning NULL in the 'before' hook will cause the 'after' hook to
|
||||
* NOT be called.
|
||||
*/
|
||||
|
||||
typedef void *
|
||||
(* CRT_CALL JSInterpreterHook)(JSContext *cx, JSStackFrame *fp, JSBool before,
|
||||
JSBool *ok, void *closure);
|
||||
|
||||
#endif /* jsprvtd_h___ */
|
||||
|
||||
@@ -21,47 +21,47 @@
|
||||
/*
|
||||
* JS public API typedefs.
|
||||
*/
|
||||
#include "prtypes.h"
|
||||
#include "jstypes.h"
|
||||
#define NETSCAPE_INTERNAL 1
|
||||
#include "jscompat.h"
|
||||
|
||||
#ifndef PR_INLINE
|
||||
#ifndef JS_INLINE
|
||||
# ifdef _WIN32
|
||||
# define PR_INLINE __inline
|
||||
# define JS_INLINE __inline
|
||||
# elif defined(__GNUC__)
|
||||
# define PR_INLINE inline
|
||||
# define JS_INLINE inline
|
||||
# else
|
||||
# define PR_INLINE
|
||||
# define JS_INLINE
|
||||
# endif
|
||||
#endif /* PR_INLINE */
|
||||
#endif /* JS_INLINE */
|
||||
|
||||
/*
|
||||
* Downrev NSPR versions of prtypes.h do not define these linkage-related
|
||||
* Downrev NSPR versions of jstypes.h do not define these linkage-related
|
||||
* PR_* macros, so we define them if necessary. Eventually, we should be
|
||||
* able to remove these local definitions (move them to js/ref/prtypes.h,
|
||||
* and get them from an uprev NSPR's prtypes.h for js/src).
|
||||
* able to remove these local definitions (move them to js/ref/jstypes.h,
|
||||
* and get them from an uprev NSPR's jstypes.h for js/src).
|
||||
*/
|
||||
#ifndef PR_IMPORT_API
|
||||
#ifndef IMPORT_API
|
||||
# ifdef _WIN32
|
||||
# define PR_IMPORT_API(__x) _declspec(dllimport) __x
|
||||
# define IMPORT_API(__x) _declspec(dllimport) __x
|
||||
# else
|
||||
# define PR_IMPORT_API(__x) PR_IMPLEMENT(__x)
|
||||
# define IMPORT_API(__x) IMPLEMENT(__x)
|
||||
# endif
|
||||
#endif /* PR_IMPORT_API */
|
||||
#ifndef PR_IMPORT_DATA
|
||||
#endif /* IMPORT_API */
|
||||
#ifndef IMPORT_DATA
|
||||
# ifdef _WIN32
|
||||
# define PR_IMPORT_DATA(__x) _declspec(dllimport) __x
|
||||
# define IMPORT_DATA(__x) _declspec(dllimport) __x
|
||||
# else
|
||||
# define PR_IMPORT_DATA(__x) __x
|
||||
# define IMPORT_DATA(__x) __x
|
||||
# endif
|
||||
#endif /* PR_IMPORT_DATA */
|
||||
#ifndef PR_PUBLIC_DATA
|
||||
#endif /* IMPORT_DATA */
|
||||
#ifndef PUBLIC_DATA
|
||||
# ifdef _WIN32
|
||||
# define PR_PUBLIC_DATA(__x) _declspec(dllexport) __x
|
||||
# define PUBLIC_DATA(__x) _declspec(dllexport) __x
|
||||
# else
|
||||
# define PR_PUBLIC_DATA(__x) __x
|
||||
# define PUBLIC_DATA(__x) __x
|
||||
# endif
|
||||
#endif /* PR_PUBLIC_DATA */
|
||||
#endif /* PUBLIC_DATA */
|
||||
|
||||
/*
|
||||
* The linkage of JS API functions differs depending on whether the file is
|
||||
@@ -70,11 +70,11 @@
|
||||
* should not.
|
||||
*/
|
||||
#ifdef EXPORT_JS_API
|
||||
#define JS_PUBLIC_API(t) PR_IMPLEMENT(t)
|
||||
#define JS_PUBLIC_DATA(t) PR_PUBLIC_DATA(t)
|
||||
#define JS_PUBLIC_API(t) IMPLEMENT(t)
|
||||
#define JS_PUBLIC_DATA(t) PUBLIC_DATA(t)
|
||||
#else
|
||||
#define JS_PUBLIC_API(t) PR_IMPORT_API(t)
|
||||
#define JS_PUBLIC_DATA(t) PR_IMPORT_DATA(t)
|
||||
#define JS_PUBLIC_API(t) IMPORT_API(t)
|
||||
#define JS_PUBLIC_DATA(t) IMPORT_DATA(t)
|
||||
#endif
|
||||
|
||||
#define JS_FRIEND_API(t) JS_PUBLIC_API(t)
|
||||
@@ -85,16 +85,9 @@ typedef uint16 jschar;
|
||||
typedef int32 jsint;
|
||||
typedef uint32 jsuint;
|
||||
typedef float64 jsdouble;
|
||||
typedef prword jsval;
|
||||
typedef prword jsid;
|
||||
typedef prword jsrefcount;
|
||||
|
||||
/* Boolean enum and packed int types. */
|
||||
typedef PRBool JSBool;
|
||||
typedef PRPackedBool JSPackedBool;
|
||||
|
||||
#define JS_FALSE PR_FALSE
|
||||
#define JS_TRUE PR_TRUE
|
||||
typedef jsword jsval;
|
||||
typedef jsword jsid;
|
||||
typedef jsword jsrefcount;
|
||||
|
||||
typedef enum JSVersion {
|
||||
JSVERSION_1_0 = 100,
|
||||
@@ -195,8 +188,8 @@ typedef JSBool
|
||||
*/
|
||||
typedef JSBool
|
||||
(* CRT_CALL JSNewEnumerateOp)(JSContext *cx, JSObject *obj,
|
||||
JSIterateOp enum_op,
|
||||
jsval *statep, jsid *idp);
|
||||
JSIterateOp enum_op,
|
||||
jsval *statep, jsid *idp);
|
||||
|
||||
typedef JSBool
|
||||
(* CRT_CALL JSEnumerateOp)(JSContext *cx, JSObject *obj);
|
||||
@@ -291,4 +284,13 @@ typedef void
|
||||
(* CRT_CALL JSErrorReporter)(JSContext *cx, const char *message,
|
||||
JSErrorReport *report);
|
||||
|
||||
typedef struct JSErrorFormatString {
|
||||
const char *format;
|
||||
const uintN argCount;
|
||||
} JSErrorFormatString;
|
||||
|
||||
typedef const JSErrorFormatString *
|
||||
(* CRT_CALL JSErrorCallback)(void *userRef, const char *locale,
|
||||
const uintN errorNumber);
|
||||
|
||||
#endif /* jspubtd_h___ */
|
||||
|
||||
@@ -22,13 +22,16 @@
|
||||
#include "jsstddef.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "jstypes.h"
|
||||
#ifndef NSPR20
|
||||
#include "prarena.h"
|
||||
#include "jsarena.h"
|
||||
#else
|
||||
#include "plarena.h"
|
||||
/* Removed by JSIFY: #include "plarena.h"
|
||||
*/
|
||||
#include "jsarena.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "prlog.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#include "jsapi.h"
|
||||
#include "jsarray.h"
|
||||
#include "jsatom.h"
|
||||
@@ -106,7 +109,7 @@ uint8 reopsize[] = {
|
||||
/* LPAREN */ 3,
|
||||
/* RPAREN */ 3,
|
||||
/* DOT */ 1,
|
||||
/* CCLASS */ 1 + (CCLASS_CHARSET_SIZE / PR_BITS_PER_BYTE),
|
||||
/* CCLASS */ 1 + (CCLASS_CHARSET_SIZE / JS_BITS_PER_BYTE),
|
||||
/* DIGIT */ 1,
|
||||
/* NONDIGIT */ 1,
|
||||
/* ALNUM */ 1,
|
||||
@@ -130,7 +133,7 @@ uint8 reopsize[] = {
|
||||
/* UCFLATi */ 2, /* (2 = op + len) + [len 2-byte chars] */
|
||||
/* UCFLAT1i */ 3, /* op + hibyte + lobyte */
|
||||
/* ANCHOR1 */ 1,
|
||||
/* NCCLASS */ 1 + (CCLASS_CHARSET_SIZE / PR_BITS_PER_BYTE),
|
||||
/* NCCLASS */ 1 + (CCLASS_CHARSET_SIZE / JS_BITS_PER_BYTE),
|
||||
/* END */ 0,
|
||||
};
|
||||
|
||||
@@ -143,17 +146,17 @@ struct RENode {
|
||||
RENode *next; /* next in concatenation order */
|
||||
void *kid; /* first operand */
|
||||
union {
|
||||
void *kid2; /* second operand */
|
||||
jsint num; /* could be a number */
|
||||
jschar chr; /* or a character */
|
||||
struct { /* or a quantifier range */
|
||||
uint16 min;
|
||||
uint16 max;
|
||||
} range;
|
||||
struct { /* or a Unicode character class */
|
||||
uint16 kidlen; /* length of string at kid, in jschars */
|
||||
uint16 bmsize; /* bitmap size, based on max char code */
|
||||
} ucclass;
|
||||
void *kid2; /* second operand */
|
||||
jsint num; /* could be a number */
|
||||
jschar chr; /* or a character */
|
||||
struct { /* or a quantifier range */
|
||||
uint16 min;
|
||||
uint16 max;
|
||||
} range;
|
||||
struct { /* or a Unicode character class */
|
||||
uint16 kidlen; /* length of string at kid, in jschars */
|
||||
uint16 bmsize; /* bitmap size, based on max char code */
|
||||
} ucclass;
|
||||
} u;
|
||||
};
|
||||
|
||||
@@ -183,7 +186,7 @@ NewRENode(CompilerState *state, REOp op, void *kid)
|
||||
RENode *ren;
|
||||
|
||||
cx = state->context;
|
||||
PR_ARENA_ALLOCATE(ren, &cx->tempPool, sizeof *ren);
|
||||
JS_ARENA_ALLOCATE(ren, &cx->tempPool, sizeof *ren);
|
||||
if (!ren) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return NULL;
|
||||
@@ -407,7 +410,7 @@ FixNext(CompilerState *state, RENode *ren1, RENode *ren2, RENode *oldnext)
|
||||
if (REOP(kid) == REOP_JUMP)
|
||||
continue;
|
||||
for (ren = kid; ren->next; ren = ren->next)
|
||||
PR_ASSERT(REOP(ren) != REOP_ALT);
|
||||
JS_ASSERT(REOP(ren) != REOP_ALT);
|
||||
|
||||
/* Append a jump node to all but the last alternative. */
|
||||
ren->next = NewRENode(state, REOP_JUMP, NULL);
|
||||
@@ -653,15 +656,16 @@ loop:
|
||||
case '{':
|
||||
c = *++cp;
|
||||
if (!JS7_ISDEC(c)) {
|
||||
JS_ReportError(state->context, "invalid quantifier %s", state->cp);
|
||||
JS_ReportErrorNumber(state->context, js_GetErrorMessage, NULL,
|
||||
JSMSG_BAD_QUANTIFIER, state->cp);
|
||||
return NULL;
|
||||
}
|
||||
min = (uint32)JS7_UNDEC(c);
|
||||
for (c = *++cp; JS7_ISDEC(c); c = *++cp) {
|
||||
min = 10 * min + (uint32)JS7_UNDEC(c);
|
||||
if (min >> 16) {
|
||||
JS_ReportError(state->context, "overlarge minimum %s",
|
||||
state->cp);
|
||||
JS_ReportErrorNumber(state->context, js_GetErrorMessage, NULL,
|
||||
JSMSG_MIN_TOO_BIG, state->cp);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -672,16 +676,18 @@ loop:
|
||||
for (c = *++cp; JS7_ISDEC(c); c = *++cp) {
|
||||
max = 10 * max + (uint32)JS7_UNDEC(c);
|
||||
if (max >> 16) {
|
||||
JS_ReportError(state->context, "overlarge maximum %s",
|
||||
up);
|
||||
JS_ReportErrorNumber(state->context,
|
||||
js_GetErrorMessage, NULL,
|
||||
JSMSG_MAX_TOO_BIG, up);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (max == 0)
|
||||
goto zero_quant;
|
||||
if (min > max) {
|
||||
JS_ReportError(state->context,
|
||||
"maximum %s less than minimum", up);
|
||||
JS_ReportErrorNumber(state->context,
|
||||
js_GetErrorMessage, NULL,
|
||||
JSMSG_OUT_OF_ORDER, up);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
@@ -692,14 +698,15 @@ loop:
|
||||
/* Exactly n times. */
|
||||
if (min == 0) {
|
||||
zero_quant:
|
||||
JS_ReportError(state->context, "zero quantifier %s", state->cp);
|
||||
JS_ReportErrorNumber(state->context, js_GetErrorMessage, NULL,
|
||||
JSMSG_ZERO_QUANTIFIER, state->cp);
|
||||
return NULL;
|
||||
}
|
||||
max = min;
|
||||
}
|
||||
if (*cp != '}') {
|
||||
JS_ReportError(state->context, "unterminated quantifier %s",
|
||||
state->cp);
|
||||
JS_ReportErrorNumber(state->context, js_GetErrorMessage, NULL,
|
||||
JSMSG_UNTERM_QUANTIFIER, state->cp);
|
||||
return NULL;
|
||||
}
|
||||
cp++;
|
||||
@@ -716,8 +723,8 @@ loop:
|
||||
|
||||
case '*':
|
||||
if (!(ren->flags & RENODE_NONEMPTY)) {
|
||||
JS_ReportError(state->context,
|
||||
"regular expression before * could be empty");
|
||||
JS_ReportErrorNumber(state->context, js_GetErrorMessage, NULL,
|
||||
JSMSG_EMPTY_BEFORE_STAR);
|
||||
return NULL;
|
||||
}
|
||||
cp++;
|
||||
@@ -726,8 +733,8 @@ loop:
|
||||
|
||||
case '+':
|
||||
if (!(ren->flags & RENODE_NONEMPTY)) {
|
||||
JS_ReportError(state->context,
|
||||
"regular expression before + could be empty");
|
||||
JS_ReportErrorNumber(state->context, js_GetErrorMessage, NULL,
|
||||
JSMSG_EMPTY_BEFORE_PLUS);
|
||||
return NULL;
|
||||
}
|
||||
cp++;
|
||||
@@ -809,8 +816,8 @@ ParseAtom(CompilerState *state)
|
||||
return NULL;
|
||||
cp = state->cp;
|
||||
if (*cp != ')') {
|
||||
JS_ReportError(state->context, "unterminated parenthetical %s",
|
||||
ocp);
|
||||
JS_ReportErrorNumber(state->context, js_GetErrorMessage, NULL,
|
||||
JSMSG_MISSING_PAREN, ocp);
|
||||
return NULL;
|
||||
}
|
||||
cp++;
|
||||
@@ -850,8 +857,8 @@ ParseAtom(CompilerState *state)
|
||||
while ((c = *++cp) != ']') {
|
||||
if (c == 0) {
|
||||
bad_cclass:
|
||||
JS_ReportError(state->context,
|
||||
"unterminated character class %s", ocp);
|
||||
JS_ReportErrorNumber(state->context, js_GetErrorMessage, NULL,
|
||||
JSMSG_UNTERM_CLASS, ocp);
|
||||
return NULL;
|
||||
}
|
||||
if (c == '\\' && cp[1] != 0)
|
||||
@@ -867,7 +874,8 @@ ParseAtom(CompilerState *state)
|
||||
c = *++cp;
|
||||
switch (c) {
|
||||
case 0:
|
||||
JS_ReportError(state->context, "trailing \\ in regular expression");
|
||||
JS_ReportErrorNumber(state->context, js_GetErrorMessage, NULL,
|
||||
JSMSG_TRAILING_SLASH);
|
||||
return NULL;
|
||||
|
||||
case 'f':
|
||||
@@ -1045,13 +1053,13 @@ CountFirstChars(RENode *alt)
|
||||
switch (REOP(kid)) {
|
||||
case REOP_QUANT:
|
||||
if (kid->u.range.min == 0)
|
||||
return -1;
|
||||
return -1;
|
||||
/* FALL THROUGH */
|
||||
case REOP_PLUS:
|
||||
case REOP_ALT:
|
||||
sublen = CountFirstChars(kid);
|
||||
if (sublen < 0)
|
||||
return sublen;
|
||||
return sublen;
|
||||
len += sublen;
|
||||
break;
|
||||
case REOP_FLAT:
|
||||
@@ -1062,7 +1070,7 @@ CountFirstChars(RENode *alt)
|
||||
count_char:
|
||||
/* Only '\\' and '-' need escaping within a character class. */
|
||||
if (c == '\\' || c == '-')
|
||||
len += 2;
|
||||
len += 2;
|
||||
else
|
||||
len++;
|
||||
break;
|
||||
@@ -1123,7 +1131,7 @@ StoreFirstChars(RENode *alt, jschar *cp, ptrdiff_t i)
|
||||
;
|
||||
switch (REOP(kid)) {
|
||||
case REOP_QUANT:
|
||||
PR_ASSERT(kid->u.range.min != 0);
|
||||
JS_ASSERT(kid->u.range.min != 0);
|
||||
/* FALL THROUGH */
|
||||
case REOP_PLUS:
|
||||
case REOP_ALT:
|
||||
@@ -1159,7 +1167,7 @@ StoreFirstChars(RENode *alt, jschar *cp, ptrdiff_t i)
|
||||
i = StoreChar(cp, i, 'S', JS_TRUE);
|
||||
break;
|
||||
default:
|
||||
PR_ASSERT(0);
|
||||
JS_ASSERT(0);
|
||||
}
|
||||
/* Test for non-alt so quant and plus execute to here only. */
|
||||
if (REOP(alt) != REOP_ALT)
|
||||
@@ -1184,7 +1192,7 @@ AnchorRegExp(CompilerState *state, RENode *ren)
|
||||
len = CountFirstChars(ren2);
|
||||
if (len <= 0)
|
||||
goto do_anchor;
|
||||
PR_ARENA_ALLOCATE(cp, &state->context->tempPool, len * sizeof(jschar));
|
||||
JS_ARENA_ALLOCATE(cp, &state->context->tempPool, len * sizeof(jschar));
|
||||
if (!cp) {
|
||||
JS_ReportOutOfMemory(state->context);
|
||||
return JS_FALSE;
|
||||
@@ -1257,8 +1265,8 @@ AnchorRegExp(CompilerState *state, RENode *ren)
|
||||
goto do_first_char;
|
||||
|
||||
case REOP_FLAT1:
|
||||
cp = &ren2->u.chr;
|
||||
op = REOP_FLAT1;
|
||||
cp = &ren2->u.chr;
|
||||
op = REOP_FLAT1;
|
||||
goto do_first_char;
|
||||
|
||||
case REOP_DOTSTAR:
|
||||
@@ -1273,8 +1281,8 @@ AnchorRegExp(CompilerState *state, RENode *ren)
|
||||
* Any node other than dotstar that's unanchored and nonempty must be
|
||||
* prefixed by REOP_ANCHOR.
|
||||
*/
|
||||
PR_ASSERT(REOP(ren2) != REOP_ANCHOR);
|
||||
PR_ASSERT(!(ren2->flags & RENODE_ISNEXT));
|
||||
JS_ASSERT(REOP(ren2) != REOP_ANCHOR);
|
||||
JS_ASSERT(!(ren2->flags & RENODE_ISNEXT));
|
||||
if ((ren2->flags & (RENODE_ANCHORED | RENODE_NONEMPTY))
|
||||
== RENODE_NONEMPTY) {
|
||||
ren2 = NewRENode(state, REOP(ren), ren->kid);
|
||||
@@ -1430,10 +1438,10 @@ OptimizeRegExp(CompilerState *state, RENode *ren)
|
||||
/* Try to extend the last alloc, to fuse FLAT,FLAT1,... */
|
||||
size = (len + 1) * sizeof(jschar);
|
||||
incr = len2 * sizeof(jschar);
|
||||
PR_ARENA_GROW(cp, &cx->tempPool, size, incr);
|
||||
JS_ARENA_GROW(cp, &cx->tempPool, size, incr);
|
||||
} else {
|
||||
size = (len + len2 + 1) * sizeof(jschar);
|
||||
PR_ARENA_ALLOCATE(cp, &cx->tempPool, size);
|
||||
JS_ARENA_ALLOCATE(cp, &cx->tempPool, size);
|
||||
}
|
||||
if (!cp) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
@@ -1448,7 +1456,7 @@ OptimizeRegExp(CompilerState *state, RENode *ren)
|
||||
cp[len] = 0;
|
||||
end_coalesce:
|
||||
ren->kid = cp;
|
||||
PR_ASSERT(ren->flags & RENODE_GOODNEXT);
|
||||
JS_ASSERT(ren->flags & RENODE_GOODNEXT);
|
||||
if (!(next->flags & RENODE_GOODNEXT))
|
||||
ren->flags &= ~RENODE_GOODNEXT;
|
||||
ren->u.kid2 = cp + len;
|
||||
@@ -1475,7 +1483,7 @@ OptimizeRegExp(CompilerState *state, RENode *ren)
|
||||
len = 1;
|
||||
}
|
||||
cx = state->context;
|
||||
PR_ARENA_ALLOCATE(cp, &cx->tempPool, len + 2);
|
||||
JS_ARENA_ALLOCATE(cp, &cx->tempPool, len + 2);
|
||||
if (!cp) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return JS_FALSE;
|
||||
@@ -1528,7 +1536,7 @@ OptimizeRegExp(CompilerState *state, RENode *ren)
|
||||
JS7_ISHEX(cp[1]) && JS7_ISHEX(cp[2]) &&
|
||||
JS7_ISHEX(cp[3]) && JS7_ISHEX(cp[4])) {
|
||||
c = (((((JS7_UNHEX(cp[1]) << 4)
|
||||
+ JS7_UNHEX(cp[2])) << 4)
|
||||
+ JS7_UNHEX(cp[2])) << 4)
|
||||
+ JS7_UNHEX(cp[3])) << 4)
|
||||
+ JS7_UNHEX(cp[4]);
|
||||
cp += 5;
|
||||
@@ -1557,7 +1565,7 @@ OptimizeRegExp(CompilerState *state, RENode *ren)
|
||||
}
|
||||
if (maxc >= CCLASS_CHARSET_SIZE) {
|
||||
ren->op = (uint8)REOP_UCCLASS;
|
||||
size = (size_t)(maxc + PR_BITS_PER_BYTE) / PR_BITS_PER_BYTE;
|
||||
size = (size_t)(maxc + JS_BITS_PER_BYTE) / JS_BITS_PER_BYTE;
|
||||
ren->u.ucclass.kidlen = (uint16)len;
|
||||
ren->u.ucclass.bmsize = (uint16)size;
|
||||
state->progLength -= reopsize[REOP_CCLASS];
|
||||
@@ -1689,7 +1697,7 @@ EmitRegExp(CompilerState *state, RENode *ren, JSRegExp *re)
|
||||
pc++;
|
||||
if (op == REOP_CCLASS) {
|
||||
end = ren->u.kid2;
|
||||
for (i = 0; i < CCLASS_CHARSET_SIZE / PR_BITS_PER_BYTE; i++)
|
||||
for (i = 0; i < CCLASS_CHARSET_SIZE / JS_BITS_PER_BYTE; i++)
|
||||
pc[i] = fill;
|
||||
nchars = CCLASS_CHARSET_SIZE;
|
||||
} else {
|
||||
@@ -1700,7 +1708,7 @@ EmitRegExp(CompilerState *state, RENode *ren, JSRegExp *re)
|
||||
state->progLength += n;
|
||||
for (i = 0; i < n; i++)
|
||||
pc[i] = fill;
|
||||
nchars = n * PR_BITS_PER_BYTE;
|
||||
nchars = n * JS_BITS_PER_BYTE;
|
||||
}
|
||||
|
||||
/* Split ops up into statements to keep MSVC1.52 from crashing. */
|
||||
@@ -1838,8 +1846,9 @@ EmitRegExp(CompilerState *state, RENode *ren, JSRegExp *re)
|
||||
|
||||
if (inrange) {
|
||||
if (lastc > c) {
|
||||
JS_ReportError(state->context,
|
||||
"invalid range in character class");
|
||||
JS_ReportErrorNumber(state->context,
|
||||
js_GetErrorMessage, NULL,
|
||||
JSMSG_BAD_CLASS_RANGE);
|
||||
return JS_FALSE;
|
||||
}
|
||||
inrange = JS_FALSE;
|
||||
@@ -1954,7 +1963,7 @@ js_NewRegExp(JSContext *cx, JSString *str, uintN flags)
|
||||
size_t resize;
|
||||
|
||||
re = NULL;
|
||||
mark = PR_ARENA_MARK(&cx->tempPool);
|
||||
mark = JS_ARENA_MARK(&cx->tempPool);
|
||||
|
||||
state.context = cx;
|
||||
state.cpbegin = state.cp = str->chars;
|
||||
@@ -1981,7 +1990,7 @@ js_NewRegExp(JSContext *cx, JSString *str, uintN flags)
|
||||
#endif
|
||||
|
||||
resize = sizeof *re + state.progLength - 1;
|
||||
re = JS_malloc(cx, PR_ROUNDUP(resize, sizeof(prword)));
|
||||
re = JS_malloc(cx, JS_ROUNDUP(resize, sizeof(jsword)));
|
||||
if (!re)
|
||||
goto out;
|
||||
re->source = str;
|
||||
@@ -1999,24 +2008,24 @@ js_NewRegExp(JSContext *cx, JSString *str, uintN flags)
|
||||
|
||||
#ifdef DEBUG_notme
|
||||
{
|
||||
/* print the compiled regexp program bytecode */
|
||||
size_t i;
|
||||
for (i = 0; i < state.progLength; i++) {
|
||||
int b = (int) re->program[i];
|
||||
fprintf(stderr, "%d", b);
|
||||
if ((i > 0 && i % 8 == 0) || i == state.progLength-1)
|
||||
fprintf(stderr, "\n");
|
||||
else
|
||||
fprintf(stderr, ", ");
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
/* print the compiled regexp program bytecode */
|
||||
size_t i;
|
||||
for (i = 0; i < state.progLength; i++) {
|
||||
int b = (int) re->program[i];
|
||||
fprintf(stderr, "%d", b);
|
||||
if ((i > 0 && i % 8 == 0) || i == state.progLength-1)
|
||||
fprintf(stderr, "\n");
|
||||
else
|
||||
fprintf(stderr, ", ");
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Success: lock re->source string. */
|
||||
(void) js_LockGCThing(cx, str);
|
||||
out:
|
||||
PR_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
return re;
|
||||
}
|
||||
|
||||
@@ -2036,10 +2045,13 @@ js_NewRegExpOpt(JSContext *cx, JSString *str, JSString *opt)
|
||||
case 'i':
|
||||
flags |= JSREG_FOLD;
|
||||
break;
|
||||
default:
|
||||
JS_ReportError(cx, "invalid regular expression flag %c",
|
||||
(char) *cp);
|
||||
default: {
|
||||
char charBuf[2] = " ";
|
||||
charBuf[0] = (char)*cp;
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_BAD_FLAG, charBuf);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2280,7 +2292,7 @@ MatchRegExp(MatchState *state, jsbytecode *pc, const jschar *cp)
|
||||
matched = (cp != cpend && *cp != '\n'); \
|
||||
matchlen = 1; \
|
||||
break; \
|
||||
\
|
||||
\
|
||||
NONDOT_SINGLE_CASES \
|
||||
/* END SINGLE_CASES */
|
||||
|
||||
@@ -2298,65 +2310,65 @@ MatchRegExp(MatchState *state, jsbytecode *pc, const jschar *cp)
|
||||
} \
|
||||
matchlen = 1; \
|
||||
break; \
|
||||
\
|
||||
\
|
||||
case REOP_DIGIT: \
|
||||
matched = JS_ISDIGIT(*cp); \
|
||||
matchlen = 1; \
|
||||
break; \
|
||||
\
|
||||
\
|
||||
case REOP_NONDIGIT: \
|
||||
matched = !JS_ISDIGIT(*cp); \
|
||||
matchlen = 1; \
|
||||
break; \
|
||||
\
|
||||
\
|
||||
case REOP_ALNUM: \
|
||||
matched = JS_ISWORD(*cp); \
|
||||
matchlen = 1; \
|
||||
break; \
|
||||
\
|
||||
\
|
||||
case REOP_NONALNUM: \
|
||||
matched = !JS_ISWORD(*cp); \
|
||||
matchlen = 1; \
|
||||
break; \
|
||||
\
|
||||
\
|
||||
case REOP_SPACE: \
|
||||
matched = JS_ISSPACE(*cp); \
|
||||
matchlen = 1; \
|
||||
break; \
|
||||
\
|
||||
\
|
||||
case REOP_NONSPACE: \
|
||||
matched = !JS_ISSPACE(*cp); \
|
||||
matchlen = 1; \
|
||||
break; \
|
||||
\
|
||||
\
|
||||
case REOP_FLAT1: \
|
||||
c = *cp; \
|
||||
c2 = (jschar)pc[1]; \
|
||||
matched = (c == c2); \
|
||||
matchlen = 1; \
|
||||
break; \
|
||||
\
|
||||
\
|
||||
case REOP_FLAT1i: \
|
||||
c = *cp; \
|
||||
c2 = (jschar)pc[1]; \
|
||||
matched = MATCH_CHARS_IGNORING_CASE(c, c2); \
|
||||
matchlen = 1; \
|
||||
break; \
|
||||
\
|
||||
\
|
||||
case REOP_UCFLAT1: \
|
||||
c = *cp; \
|
||||
c2 = ((pc[1] << 8) | pc[2]); \
|
||||
matched = (c == c2); \
|
||||
matchlen = 1; \
|
||||
break; \
|
||||
\
|
||||
\
|
||||
case REOP_UCFLAT1i: \
|
||||
c = *cp; \
|
||||
c2 = ((pc[1] << 8) | pc[2]); \
|
||||
matched = MATCH_CHARS_IGNORING_CASE(c, c2); \
|
||||
matchlen = 1; \
|
||||
break; \
|
||||
\
|
||||
\
|
||||
case REOP_UCCLASS: \
|
||||
case REOP_NUCCLASS: \
|
||||
size = (pc[1] << 8) | pc[2]; \
|
||||
@@ -2386,7 +2398,7 @@ MatchRegExp(MatchState *state, jsbytecode *pc, const jschar *cp)
|
||||
switch (op) {
|
||||
NONDOT_SINGLE_CASES
|
||||
default:
|
||||
PR_ASSERT(0);
|
||||
JS_ASSERT(0);
|
||||
}
|
||||
if (!matched)
|
||||
break;
|
||||
@@ -2408,7 +2420,7 @@ MatchRegExp(MatchState *state, jsbytecode *pc, const jschar *cp)
|
||||
switch (op) {
|
||||
SINGLE_CASES
|
||||
default:
|
||||
PR_ASSERT(0);
|
||||
JS_ASSERT(0);
|
||||
}
|
||||
if (!matched)
|
||||
break;
|
||||
@@ -2427,7 +2439,7 @@ MatchRegExp(MatchState *state, jsbytecode *pc, const jschar *cp)
|
||||
switch (op) {
|
||||
SINGLE_CASES
|
||||
default:
|
||||
PR_ASSERT(0);
|
||||
JS_ASSERT(0);
|
||||
}
|
||||
pc += oplen;
|
||||
if (matched) {
|
||||
@@ -2530,12 +2542,12 @@ MatchRegExp(MatchState *state, jsbytecode *pc, const jschar *cp)
|
||||
op = (REOp) *++pc;
|
||||
oplen = reopsize[op];
|
||||
pc2 = pc + oplen;
|
||||
PR_ASSERT(pc2 < pcend);
|
||||
JS_ASSERT(pc2 < pcend);
|
||||
for (cp2 = cp; cp < cpend; cp++) {
|
||||
switch (op) {
|
||||
NONDOT_SINGLE_CASES
|
||||
default:
|
||||
PR_ASSERT(0);
|
||||
JS_ASSERT(0);
|
||||
}
|
||||
if (matched) {
|
||||
cp3 = MatchRegExp(state, pc2, cp);
|
||||
@@ -2552,7 +2564,7 @@ MatchRegExp(MatchState *state, jsbytecode *pc, const jschar *cp)
|
||||
#undef NONDOT_SINGLE_CASES
|
||||
|
||||
default:
|
||||
PR_ASSERT(0);
|
||||
JS_ASSERT(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -2609,12 +2621,12 @@ js_ExecuteRegExp(JSContext *cx, JSRegExp *re, JSString *str, size_t *indexp,
|
||||
|
||||
/*
|
||||
* Use the temporary arena pool to grab space for parenthetical matches.
|
||||
* After the PR_ARENA_ALLOCATE early return on error, goto out to be sure
|
||||
* After the JS_ARENA_ALLOCATE early return on error, goto out to be sure
|
||||
* to free this memory.
|
||||
*/
|
||||
length = 2 * sizeof(JSSubString) * re->parenCount;
|
||||
mark = PR_ARENA_MARK(&cx->tempPool);
|
||||
PR_ARENA_ALLOCATE(parsub, &cx->tempPool, length);
|
||||
mark = JS_ARENA_MARK(&cx->tempPool);
|
||||
JS_ARENA_ALLOCATE(parsub, &cx->tempPool, length);
|
||||
if (!parsub) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return JS_FALSE;
|
||||
@@ -2681,7 +2693,7 @@ js_ExecuteRegExp(JSContext *cx, JSRegExp *re, JSString *str, size_t *indexp,
|
||||
}
|
||||
|
||||
res = &cx->regExpStatics;
|
||||
PR_ASSERT(state.parenCount <= re->parenCount);
|
||||
JS_ASSERT(state.parenCount <= re->parenCount);
|
||||
if (state.parenCount == 0) {
|
||||
res->parenCount = 0;
|
||||
res->lastParen = js_EmptySubString;
|
||||
@@ -2773,7 +2785,7 @@ js_ExecuteRegExp(JSContext *cx, JSRegExp *re, JSString *str, size_t *indexp,
|
||||
res->rightContext.length = state.cpend - ep;
|
||||
|
||||
out:
|
||||
PR_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -3069,7 +3081,7 @@ JSClass js_RegExpClass = {
|
||||
|
||||
static JSBool
|
||||
regexp_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *rval)
|
||||
jsval *rval)
|
||||
{
|
||||
JSBool ok;
|
||||
JSRegExp *re;
|
||||
@@ -3084,7 +3096,7 @@ regexp_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
JS_LOCK_OBJ(cx, obj);
|
||||
re = JS_GetPrivate(cx, obj);
|
||||
if (!re) {
|
||||
*rval = STRING_TO_JSVAL(cx->runtime->emptyString);
|
||||
*rval = STRING_TO_JSVAL(cx->runtime->emptyString);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -3183,15 +3195,16 @@ regexp_exec_sub(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
return JS_FALSE;
|
||||
re = JS_GetPrivate(cx, obj);
|
||||
if (!re)
|
||||
return JS_TRUE;
|
||||
return JS_TRUE;
|
||||
ok = locked = JS_FALSE;
|
||||
if (argc == 0) {
|
||||
str = cx->regExpStatics.input;
|
||||
if (!str) {
|
||||
JS_ReportError(cx, "no input for /%s/%s%s",
|
||||
JS_GetStringBytes(re->source),
|
||||
(re->flags & JSREG_GLOB) ? "g" : "",
|
||||
(re->flags & JSREG_FOLD) ? "i" : "");
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_NO_INPUT,
|
||||
JS_GetStringBytes(re->source),
|
||||
(re->flags & JSREG_GLOB) ? "g" : "",
|
||||
(re->flags & JSREG_FOLD) ? "i" : "");
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
@@ -3248,8 +3261,8 @@ RegExp(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
/* If not constructing, replace obj with a new RegExp object. */
|
||||
if (!cx->fp->constructing) {
|
||||
obj = js_NewObject(cx, &js_RegExpClass, NULL, NULL);
|
||||
if (!obj)
|
||||
obj = js_NewObject(cx, &js_RegExpClass, NULL, NULL);
|
||||
if (!obj)
|
||||
return JS_FALSE;
|
||||
}
|
||||
return regexp_compile(cx, obj, argc, argv, rval);
|
||||
|
||||
@@ -29,19 +29,23 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "jstypes.h"
|
||||
#ifndef NSPR20
|
||||
#include "prarena.h"
|
||||
#include "jsarena.h"
|
||||
#else
|
||||
#include "plarena.h"
|
||||
/* Removed by JSIFY: #include "plarena.h"
|
||||
*/
|
||||
#include "jsarena.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "prlog.h"
|
||||
#include "prdtoa.h"
|
||||
#include "prprf.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#include "jsdtoa.h"
|
||||
#include "jsprf.h"
|
||||
#include "jsapi.h"
|
||||
#include "jsatom.h"
|
||||
#include "jscntxt.h"
|
||||
#include "jsconfig.h"
|
||||
#include "jsexn.h"
|
||||
#include "jsnum.h"
|
||||
#include "jsopcode.h"
|
||||
#include "jsregexp.h"
|
||||
@@ -153,7 +157,7 @@ js_InitScanner(JSContext *cx)
|
||||
if (!atom)
|
||||
return JS_FALSE;
|
||||
atom->kwindex = (JSVERSION_IS_ECMA(cx->version)
|
||||
|| kw->version <= cx->version) ? kw - keywords : -1;
|
||||
|| kw->version <= cx->version) ? kw - keywords : -1;
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
@@ -180,7 +184,7 @@ js_NewTokenStream(JSContext *cx, const jschar *base, size_t length,
|
||||
ts->filename = filename;
|
||||
ts->lineno = lineno;
|
||||
if (principals)
|
||||
JSPRINCIPALS_HOLD(cx, principals);
|
||||
JSPRINCIPALS_HOLD(cx, principals);
|
||||
ts->principals = principals;
|
||||
return ts;
|
||||
}
|
||||
@@ -192,7 +196,7 @@ js_NewBufferTokenStream(JSContext *cx, const jschar *base, size_t length)
|
||||
JSTokenStream *ts;
|
||||
|
||||
nb = sizeof(JSTokenStream) + JS_LINE_LIMIT * sizeof(jschar);
|
||||
PR_ARENA_ALLOCATE(ts, &cx->tempPool, nb);
|
||||
JS_ARENA_ALLOCATE(ts, &cx->tempPool, nb);
|
||||
if (!ts) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return NULL;
|
||||
@@ -204,9 +208,8 @@ js_NewBufferTokenStream(JSContext *cx, const jschar *base, size_t length)
|
||||
ts->userbuf.base = (jschar *)base;
|
||||
ts->userbuf.limit = (jschar *)base + length;
|
||||
ts->userbuf.ptr = (jschar *)base;
|
||||
#ifdef JSD_LOWLEVEL_SOURCE
|
||||
ts->jsdc = JSD_JSDContextForJSContext(cx);
|
||||
#endif
|
||||
ts->listener = cx->runtime->sourceHandler;
|
||||
ts->listenerData = cx->runtime->sourceHandlerData;
|
||||
return ts;
|
||||
}
|
||||
|
||||
@@ -218,9 +221,9 @@ js_NewFileTokenStream(JSContext *cx, const char *filename, FILE *defaultfp)
|
||||
JSTokenStream *ts;
|
||||
FILE *file;
|
||||
|
||||
PR_ARENA_ALLOCATE(base, &cx->tempPool, JS_LINE_LIMIT * sizeof(jschar));
|
||||
JS_ARENA_ALLOCATE(base, &cx->tempPool, JS_LINE_LIMIT * sizeof(jschar));
|
||||
if (!base)
|
||||
return NULL;
|
||||
return NULL;
|
||||
ts = js_NewBufferTokenStream(cx, base, JS_LINE_LIMIT);
|
||||
if (!ts)
|
||||
return NULL;
|
||||
@@ -229,7 +232,8 @@ js_NewFileTokenStream(JSContext *cx, const char *filename, FILE *defaultfp)
|
||||
} else {
|
||||
file = fopen(filename, "r");
|
||||
if (!file) {
|
||||
JS_ReportError(cx, "can't open %s: %s", filename, strerror(errno));
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_OPEN,
|
||||
filename, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -244,7 +248,7 @@ JS_FRIEND_API(JSBool)
|
||||
js_CloseTokenStream(JSContext *cx, JSTokenStream *ts)
|
||||
{
|
||||
if (ts->principals)
|
||||
JSPRINCIPALS_DROP(cx, ts->principals);
|
||||
JSPRINCIPALS_DROP(cx, ts->principals);
|
||||
#ifdef JSFILE
|
||||
return !ts->file || fclose(ts->file) == 0;
|
||||
#else
|
||||
@@ -252,48 +256,6 @@ js_CloseTokenStream(JSContext *cx, JSTokenStream *ts)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef JSD_LOWLEVEL_SOURCE
|
||||
static void
|
||||
SendSourceToJSDebugger(JSTokenStream *ts, jschar *str, size_t length)
|
||||
{
|
||||
if (!ts->jsdsrc) {
|
||||
const char* filename = ts->filename ? ts->filename : "typein";
|
||||
|
||||
if (1 == ts->lineno) {
|
||||
ts->jsdsrc = JSD_NewSourceText(ts->jsdc, filename);
|
||||
} else {
|
||||
ts->jsdsrc = JSD_FindSourceForURL(ts->jsdc, filename);
|
||||
if (ts->jsdsrc && JSD_SOURCE_PARTIAL !=
|
||||
JSD_GetSourceStatus(ts->jsdc, ts->jsdsrc)) {
|
||||
ts->jsdsrc = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ts->jsdsrc) {
|
||||
/* here we convert our Unicode into a C string to pass to JSD */
|
||||
#define JSD_BUF_SIZE 1024
|
||||
static char* buf = NULL;
|
||||
int remaining = length;
|
||||
|
||||
if (!buf)
|
||||
buf = malloc(JSD_BUF_SIZE);
|
||||
if (buf)
|
||||
{
|
||||
while (remaining && ts->jsdsrc) {
|
||||
int bytes = PR_MIN(remaining, JSD_BUF_SIZE);
|
||||
int i;
|
||||
for (i = 0; i < bytes; i++)
|
||||
buf[i] = (const char) *(str++);
|
||||
ts->jsdsrc = JSD_AppendSourceText(ts->jsdc,ts->jsdsrc,
|
||||
buf, bytes,
|
||||
JSD_SOURCE_PARTIAL);
|
||||
remaining -= bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static int32
|
||||
GetChar(JSTokenStream *ts)
|
||||
{
|
||||
@@ -321,7 +283,7 @@ GetChar(JSTokenStream *ts)
|
||||
return EOF;
|
||||
}
|
||||
len = olen = strlen(cbuf);
|
||||
PR_ASSERT(len > 0);
|
||||
JS_ASSERT(len > 0);
|
||||
ubuf = ts->userbuf.base;
|
||||
i = 0;
|
||||
if (crflag) {
|
||||
@@ -343,12 +305,9 @@ GetChar(JSTokenStream *ts)
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef JSD_LOWLEVEL_SOURCE
|
||||
if (ts->jsdc)
|
||||
SendSourceToJSDebugger(ts, ts->userbuf.ptr, len);
|
||||
#endif
|
||||
|
||||
if (ts->listener)
|
||||
(*ts->listener)(ts->filename, ts->lineno, ts->userbuf.ptr, len,
|
||||
&ts->listenerTSData, ts->listenerData);
|
||||
/*
|
||||
* Any one of \n, \r, or \r\n ends a line (longest match wins).
|
||||
*/
|
||||
@@ -399,7 +358,7 @@ GetChar(JSTokenStream *ts)
|
||||
nl[-1] == '\r' &&
|
||||
ts->linebuf.base[len-2] == '\r') {
|
||||
len--;
|
||||
PR_ASSERT(ts->linebuf.base[len] == '\n');
|
||||
JS_ASSERT(ts->linebuf.base[len] == '\n');
|
||||
ts->linebuf.base[len-1] = '\n';
|
||||
}
|
||||
}
|
||||
@@ -434,7 +393,7 @@ UngetChar(JSTokenStream *ts, int32 c)
|
||||
{
|
||||
if (c == EOF)
|
||||
return;
|
||||
PR_ASSERT(ts->ungetpos < sizeof ts->ungetbuf / sizeof ts->ungetbuf[0]);
|
||||
JS_ASSERT(ts->ungetpos < sizeof ts->ungetbuf / sizeof ts->ungetbuf[0]);
|
||||
if (c == '\n')
|
||||
ts->lineno--;
|
||||
ts->ungetbuf[ts->ungetpos++] = (jschar)c;
|
||||
@@ -474,21 +433,21 @@ SkipChars(JSTokenStream *ts, intN n)
|
||||
GetChar(ts);
|
||||
}
|
||||
|
||||
static int32
|
||||
MatchChar(JSTokenStream *ts, int32 nextChar)
|
||||
static JSBool
|
||||
MatchChar(JSTokenStream *ts, int32 expect)
|
||||
{
|
||||
int32 c;
|
||||
|
||||
c = GetChar(ts);
|
||||
if (c == nextChar)
|
||||
return 1;
|
||||
if (c == expect)
|
||||
return JS_TRUE;
|
||||
UngetChar(ts, c);
|
||||
return 0;
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
js_ReportCompileError(JSContext *cx, JSTokenStream *ts, const char *format,
|
||||
...)
|
||||
js_ReportCompileError(JSContext *cx, JSTokenStream *ts, uintN flags,
|
||||
const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *message;
|
||||
@@ -498,14 +457,14 @@ js_ReportCompileError(JSContext *cx, JSTokenStream *ts, const char *format,
|
||||
JSString *linestr;
|
||||
|
||||
va_start(ap, format);
|
||||
message = PR_vsmprintf(format, ap);
|
||||
message = JS_vsmprintf(format, ap);
|
||||
va_end(ap);
|
||||
if (!message) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return;
|
||||
}
|
||||
|
||||
PR_ASSERT(ts->linebuf.limit < ts->linebuf.base + JS_LINE_LIMIT);
|
||||
JS_ASSERT(ts->linebuf.limit < ts->linebuf.base + JS_LINE_LIMIT);
|
||||
limit = ts->linebuf.limit;
|
||||
lastc = limit[-1];
|
||||
if (lastc == '\n')
|
||||
@@ -523,18 +482,20 @@ js_ReportCompileError(JSContext *cx, JSTokenStream *ts, const char *format,
|
||||
: NULL;
|
||||
report.uclinebuf = ts->linebuf.base;
|
||||
report.uctokenptr = ts->token.ptr;
|
||||
report.flags = flags;
|
||||
(*onError)(cx, message, &report);
|
||||
#if !defined XP_PC || !defined _MSC_VER || _MSC_VER > 800
|
||||
} else {
|
||||
if (!(ts->flags & TSF_INTERACTIVE))
|
||||
fprintf(stderr, "JavaScript error: ");
|
||||
fprintf(stderr, "JavaScript %s: ",
|
||||
JSREPORT_IS_WARNING(flags) ? "warning" : "error");
|
||||
if (ts->filename)
|
||||
fprintf(stderr, "%s, ", ts->filename);
|
||||
if (ts->lineno)
|
||||
fprintf(stderr, "line %u: ", ts->lineno);
|
||||
fprintf(stderr, "%s:\n%s\n",message,
|
||||
js_DeflateString(cx, ts->linebuf.base,
|
||||
ts->linebuf.limit - ts->linebuf.base));
|
||||
js_DeflateString(cx, ts->linebuf.base,
|
||||
ts->linebuf.limit - ts->linebuf.base));
|
||||
#endif
|
||||
}
|
||||
if (lastc == '\n')
|
||||
@@ -542,6 +503,88 @@ js_ReportCompileError(JSContext *cx, JSTokenStream *ts, const char *format,
|
||||
free(message);
|
||||
}
|
||||
|
||||
void
|
||||
js_ReportCompileErrorNumber(JSContext *cx, JSTokenStream *ts, uintN flags,
|
||||
const uintN errorNumber, ...)
|
||||
{
|
||||
va_list ap;
|
||||
jschar *limit, lastc;
|
||||
JSErrorReporter onError;
|
||||
JSErrorReport report;
|
||||
JSString *linestr;
|
||||
char *message;
|
||||
|
||||
report.errorNumber = errorNumber;
|
||||
report.messageArgs = NULL;
|
||||
report.ucmessage = NULL;
|
||||
message = NULL;
|
||||
|
||||
va_start(ap, errorNumber);
|
||||
if (!js_ExpandErrorArguments(cx, js_GetErrorMessage, NULL,
|
||||
errorNumber, &message, &report, ap))
|
||||
return;
|
||||
va_end(ap);
|
||||
|
||||
JS_ASSERT(ts->linebuf.limit < ts->linebuf.base + JS_LINE_LIMIT);
|
||||
limit = ts->linebuf.limit;
|
||||
lastc = limit[-1];
|
||||
if (lastc == '\n')
|
||||
limit[-1] = 0;
|
||||
onError = cx->errorReporter;
|
||||
if (onError) {
|
||||
report.filename = ts->filename;
|
||||
report.lineno = ts->lineno;
|
||||
linestr = js_NewStringCopyZ(cx, ts->linebuf.base, 0);
|
||||
report.linebuf = linestr
|
||||
? JS_GetStringBytes(linestr)
|
||||
: NULL;
|
||||
report.tokenptr = linestr
|
||||
? report.linebuf + (ts->token.ptr - ts->linebuf.base)
|
||||
: NULL;
|
||||
report.uclinebuf = ts->linebuf.base;
|
||||
report.uctokenptr = ts->token.ptr;
|
||||
report.flags = flags;
|
||||
|
||||
#if JS_HAS_ERROR_EXCEPTIONS
|
||||
/*
|
||||
* If there's a runtime exception type associated with this error
|
||||
* number, set that as the pending exception. For errors occuring at
|
||||
* compile time, this is very likely to be a JSEXN_SYNTAXERR. If an
|
||||
* exception is thrown, then the JSREPORT_EXCEPTION flag will be set in
|
||||
* report.flags. Proper behavior for error reporters is probably to
|
||||
* ignore this for all but toplevel compilation errors.
|
||||
|
||||
* XXXmccabe it's still at issue if there's a public API to distinguish
|
||||
* between toplevel compilation and other types.
|
||||
|
||||
* XXX it'd probably be best if there was only one call to this
|
||||
* function, but there seem to be two error reporter call points.
|
||||
*/
|
||||
(void)js_ErrorToException(cx, &report, message);
|
||||
#endif
|
||||
|
||||
(*onError)(cx, message, &report);
|
||||
|
||||
#if !defined XP_PC || !defined _MSC_VER || _MSC_VER > 800
|
||||
} else {
|
||||
if (!(ts->flags & TSF_INTERACTIVE))
|
||||
fprintf(stderr, "JavaScript %s: ",
|
||||
JSREPORT_IS_WARNING(flags) ? "warning" : "error");
|
||||
if (ts->filename)
|
||||
fprintf(stderr, "%s, ", ts->filename);
|
||||
if (ts->lineno)
|
||||
fprintf(stderr, "line %u: ", ts->lineno);
|
||||
fprintf(stderr, "%s:\n%s\n",message,
|
||||
js_DeflateString(cx, ts->linebuf.base,
|
||||
ts->linebuf.limit - ts->linebuf.base));
|
||||
#endif
|
||||
}
|
||||
if (lastc == '\n')
|
||||
limit[-1] = lastc;
|
||||
if (message) free(message);
|
||||
if (report.messageArgs) free(report.messageArgs);
|
||||
}
|
||||
|
||||
JSTokenType
|
||||
js_PeekToken(JSContext *cx, JSTokenStream *ts)
|
||||
{
|
||||
@@ -578,7 +621,7 @@ GrowTokenBuf(JSContext *cx, JSTokenBuf *tb)
|
||||
jschar *base;
|
||||
ptrdiff_t offset, length;
|
||||
size_t tbincr, tbsize;
|
||||
PRArenaPool *pool;
|
||||
JSArenaPool *pool;
|
||||
|
||||
base = tb->base;
|
||||
offset = PTRDIFF(tb->ptr, base, jschar);
|
||||
@@ -586,10 +629,10 @@ GrowTokenBuf(JSContext *cx, JSTokenBuf *tb)
|
||||
tbincr = TBINCR * sizeof(jschar);
|
||||
pool = &cx->tempPool;
|
||||
if (!base) {
|
||||
PR_ARENA_ALLOCATE(base, pool, tbincr);
|
||||
JS_ARENA_ALLOCATE(base, pool, tbincr);
|
||||
} else {
|
||||
tbsize = (size_t)(length * sizeof(jschar));
|
||||
PR_ARENA_GROW(base, pool, tbsize, tbincr);
|
||||
JS_ARENA_GROW(base, pool, tbsize, tbincr);
|
||||
}
|
||||
if (!base) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
@@ -695,16 +738,19 @@ retry:
|
||||
RETURN(TOK_ERROR);
|
||||
c = GetChar(ts);
|
||||
radix = 16;
|
||||
} else if (JS7_ISDEC(c) && c < '8') {
|
||||
/*
|
||||
* XXX Warning needed. Checking against c < '8' above is
|
||||
* non-ECMA, but is required to support legacy code; it's
|
||||
* likely that "08" and "09" are in use in code having to do
|
||||
* with dates. So we need to support it, which makes our
|
||||
* behavior a superset of ECMA in this area. We should be
|
||||
* raising a warning if '8' or '9' is encountered.
|
||||
*/
|
||||
radix = 8;
|
||||
} else if (JS7_ISDEC(c)) {
|
||||
/*
|
||||
* We permit 08 and 09 as decimal numbers, which makes our
|
||||
* behaviour superset of the ECMA numeric grammar. We might
|
||||
* not always be so permissive, so we warn about it.
|
||||
*/
|
||||
if (c > '7' && JSVERSION_IS_ECMA(cx->version)) {
|
||||
js_ReportCompileError(cx, ts, JSREPORT_WARNING,
|
||||
"0%c is not a legal ECMA-262 numeric constant", c);
|
||||
radix = 10;
|
||||
} else {
|
||||
radix = 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -734,7 +780,8 @@ retry:
|
||||
c = GetChar(ts);
|
||||
}
|
||||
if (!JS7_ISDEC(c)) {
|
||||
js_ReportCompileError(cx, ts, "missing exponent");
|
||||
js_ReportCompileError(cx, ts, JSREPORT_ERROR,
|
||||
"missing exponent");
|
||||
RETURN(TOK_ERROR);
|
||||
}
|
||||
do {
|
||||
@@ -750,12 +797,14 @@ retry:
|
||||
|
||||
if (radix == 10) {
|
||||
if (!js_strtod(cx, ts->tokenbuf.base, &endptr, &dval)) {
|
||||
js_ReportCompileError(cx, ts, "out of memory");
|
||||
js_ReportCompileError(cx, ts, JSREPORT_ERROR,
|
||||
"out of memory");
|
||||
RETURN(TOK_ERROR);
|
||||
}
|
||||
} else {
|
||||
if (!js_strtointeger(cx, ts->tokenbuf.base, &endptr, radix, &dval)) {
|
||||
js_ReportCompileError(cx, ts, "out of memory");
|
||||
js_ReportCompileError(cx, ts, JSREPORT_ERROR,
|
||||
"out of memory");
|
||||
RETURN(TOK_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -770,7 +819,8 @@ retry:
|
||||
while ((c = GetChar(ts)) != qc) {
|
||||
if (c == '\n' || c == EOF) {
|
||||
UngetChar(ts, c);
|
||||
js_ReportCompileError(cx, ts, "unterminated string literal");
|
||||
js_ReportCompileError(cx, ts, JSREPORT_ERROR,
|
||||
"unterminated string literal");
|
||||
RETURN(TOK_ERROR);
|
||||
}
|
||||
if (c == '\\') {
|
||||
@@ -959,11 +1009,13 @@ skipline:
|
||||
if (c == '/' && MatchChar(ts, '*')) {
|
||||
if (MatchChar(ts, '/'))
|
||||
goto retry;
|
||||
js_ReportCompileError(cx, ts, "nested comment");
|
||||
js_ReportCompileError(cx, ts, JSREPORT_ERROR,
|
||||
"nested comment");
|
||||
}
|
||||
}
|
||||
if (c == EOF) {
|
||||
js_ReportCompileError(cx, ts, "unterminated comment");
|
||||
js_ReportCompileError(cx, ts, JSREPORT_ERROR,
|
||||
"unterminated comment");
|
||||
RETURN(TOK_ERROR);
|
||||
}
|
||||
goto retry;
|
||||
@@ -978,7 +1030,7 @@ skipline:
|
||||
while ((c = GetChar(ts)) != '/') {
|
||||
if (c == '\n' || c == EOF) {
|
||||
UngetChar(ts, c);
|
||||
js_ReportCompileError(cx, ts,
|
||||
js_ReportCompileError(cx, ts,JSREPORT_ERROR,
|
||||
"unterminated regular expression literal");
|
||||
RETURN(TOK_ERROR);
|
||||
}
|
||||
@@ -1002,7 +1054,7 @@ skipline:
|
||||
c = PeekChar(ts);
|
||||
if (JS7_ISLET(c)) {
|
||||
ts->token.ptr = ts->linebuf.ptr - 1;
|
||||
js_ReportCompileError(cx, ts,
|
||||
js_ReportCompileError(cx, ts,JSREPORT_ERROR,
|
||||
"invalid flag after regular expression");
|
||||
(void) GetChar(ts);
|
||||
RETURN(TOK_ERROR);
|
||||
@@ -1069,7 +1121,7 @@ skipline:
|
||||
break;
|
||||
n = 10 * n + JS7_UNDEC(c);
|
||||
if (n >= ATOM_INDEX_LIMIT) {
|
||||
js_ReportCompileError(cx, ts,
|
||||
js_ReportCompileError(cx, ts,JSREPORT_ERROR,
|
||||
"overlarge sharp variable number");
|
||||
RETURN(TOK_ERROR);
|
||||
}
|
||||
@@ -1086,11 +1138,12 @@ skipline:
|
||||
#endif /* JS_HAS_SHARP_VARS */
|
||||
|
||||
default:
|
||||
js_ReportCompileError(cx, ts, "illegal character");
|
||||
js_ReportCompileError(cx, ts, JSREPORT_ERROR,
|
||||
"illegal character");
|
||||
RETURN(TOK_ERROR);
|
||||
}
|
||||
|
||||
PR_ASSERT(c < TOK_LIMIT);
|
||||
JS_ASSERT(c < TOK_LIMIT);
|
||||
RETURN(c);
|
||||
|
||||
#undef INIT_TOKENBUF
|
||||
@@ -1102,7 +1155,7 @@ skipline:
|
||||
void
|
||||
js_UngetToken(JSTokenStream *ts)
|
||||
{
|
||||
PR_ASSERT(ts->pushback.type == TOK_EOF);
|
||||
JS_ASSERT(ts->pushback.type == TOK_EOF);
|
||||
if (ts->flags & TSF_ERROR)
|
||||
return;
|
||||
ts->pushback = ts->token;
|
||||
|
||||
@@ -29,11 +29,7 @@
|
||||
#include "jsprvtd.h"
|
||||
#include "jspubtd.h"
|
||||
|
||||
#ifdef JSD_LOWLEVEL_SOURCE
|
||||
#include "jsdebug.h"
|
||||
#endif
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
typedef enum JSTokenType {
|
||||
TOK_ERROR = -1, /* well-known as the only code < EOF */
|
||||
@@ -114,11 +110,11 @@ struct JSToken {
|
||||
JSTokenPos pos; /* token position in file */
|
||||
jschar *ptr; /* beginning of token in line buffer */
|
||||
union {
|
||||
struct {
|
||||
struct {
|
||||
JSOp op; /* operator, for minimal parser */
|
||||
JSAtom *atom; /* atom table entry */
|
||||
} s;
|
||||
jsdouble dval; /* floating point number */
|
||||
} s;
|
||||
jsdouble dval; /* floating point number */
|
||||
} u;
|
||||
};
|
||||
|
||||
@@ -133,7 +129,7 @@ typedef struct JSTokenBuf {
|
||||
} JSTokenBuf;
|
||||
|
||||
#define JS_LINE_LIMIT 256 /* logical line buffer size limit --
|
||||
physical line length is unlimited */
|
||||
physical line length is unlimited */
|
||||
|
||||
struct JSTokenStream {
|
||||
JSToken token; /* last token scanned */
|
||||
@@ -152,10 +148,9 @@ struct JSTokenStream {
|
||||
FILE *file; /* stdio stream if reading from file */
|
||||
#endif
|
||||
JSPrincipals *principals; /* principals associated with given input */
|
||||
#ifdef JSD_LOWLEVEL_SOURCE
|
||||
JSDContext *jsdc; /* used to cram source into debugger */
|
||||
JSDSourceText *jsdsrc; /* used to cram source into debugger */
|
||||
#endif
|
||||
JSSourceHandler listener; /* callback for source; eg debugger */
|
||||
void *listenerData; /* listener 'this' data */
|
||||
void *listenerTSData;/* listener data for this TokenStream */
|
||||
};
|
||||
|
||||
/* JSTokenStream flags */
|
||||
@@ -176,11 +171,11 @@ struct JSTokenStream {
|
||||
#define CLEAR_PUSHBACK(ts) ((ts)->pushback.type = TOK_EOF)
|
||||
#define SCAN_NEWLINES(ts) ((ts)->flags |= TSF_NEWLINES)
|
||||
#define HIDE_NEWLINES(ts) \
|
||||
PR_BEGIN_MACRO \
|
||||
JS_BEGIN_MACRO \
|
||||
(ts)->flags &= ~TSF_NEWLINES; \
|
||||
if ((ts)->pushback.type == TOK_EOL) \
|
||||
(ts)->pushback.type = TOK_EOF; \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
/* Clear ts member that might point above a released cx->tempPool mark. */
|
||||
#define RESET_TOKENBUF(ts) ((ts)->tokenbuf.base = (ts)->tokenbuf.limit = NULL)
|
||||
@@ -191,7 +186,7 @@ struct JSTokenStream {
|
||||
*
|
||||
* NB: All of js_New{,Buffer,File}TokenStream() return a pointer to transient
|
||||
* memory in the current context's temp pool. This memory is deallocated via
|
||||
* PR_ARENA_RELEASE() after parsing is finished.
|
||||
* JS_ARENA_RELEASE() after parsing is finished.
|
||||
*/
|
||||
extern JSTokenStream *
|
||||
js_NewTokenStream(JSContext *cx, const jschar *base, size_t length,
|
||||
@@ -226,8 +221,12 @@ js_MapKeywords(void (*mapfun)(const char *));
|
||||
* associated with cx.
|
||||
*/
|
||||
extern void
|
||||
js_ReportCompileError(JSContext *cx, JSTokenStream *ts, const char *format,
|
||||
...);
|
||||
js_ReportCompileError(JSContext *cx, JSTokenStream *ts, uintN flags,
|
||||
const char *format, ...);
|
||||
|
||||
void
|
||||
js_ReportCompileErrorNumber(JSContext *cx, JSTokenStream *ts, uintN flags,
|
||||
const uintN errorNumber, ...);
|
||||
|
||||
/*
|
||||
* Look ahead one token and return its type.
|
||||
@@ -256,6 +255,6 @@ js_UngetToken(JSTokenStream *ts);
|
||||
extern JSBool
|
||||
js_MatchToken(JSContext *cx, JSTokenStream *ts, JSTokenType tt);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsscan_h___ */
|
||||
|
||||
@@ -21,8 +21,9 @@
|
||||
*/
|
||||
#include "jsstddef.h"
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "prlog.h"
|
||||
#include "jstypes.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#include "jsapi.h"
|
||||
#include "jsatom.h"
|
||||
#include "jscntxt.h"
|
||||
@@ -32,7 +33,7 @@
|
||||
#include "jsscope.h"
|
||||
#include "jsstr.h"
|
||||
|
||||
PR_STATIC_CALLBACK(PRHashNumber)
|
||||
STATIC_DLL_CALLBACK(JSHashNumber)
|
||||
js_hash_id(const void *key)
|
||||
{
|
||||
jsval v;
|
||||
@@ -50,19 +51,19 @@ typedef struct JSScopePrivate {
|
||||
JSScope *scope;
|
||||
} JSScopePrivate;
|
||||
|
||||
PR_STATIC_CALLBACK(void *)
|
||||
STATIC_DLL_CALLBACK(void *)
|
||||
js_alloc_scope_space(void *priv, size_t size)
|
||||
{
|
||||
return JS_malloc(((JSScopePrivate *)priv)->context, size);
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
STATIC_DLL_CALLBACK(void)
|
||||
js_free_scope_space(void *priv, void *item)
|
||||
{
|
||||
JS_free(((JSScopePrivate *)priv)->context, item);
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(PRHashEntry *)
|
||||
STATIC_DLL_CALLBACK(JSHashEntry *)
|
||||
js_alloc_symbol(void *priv, const void *key)
|
||||
{
|
||||
JSScopePrivate *spriv;
|
||||
@@ -70,7 +71,7 @@ js_alloc_symbol(void *priv, const void *key)
|
||||
JSSymbol *sym;
|
||||
|
||||
spriv = priv;
|
||||
PR_ASSERT(JS_IS_SCOPE_LOCKED(spriv->scope));
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(spriv->scope));
|
||||
cx = spriv->context;
|
||||
sym = JS_malloc(cx, sizeof(JSSymbol));
|
||||
if (!sym)
|
||||
@@ -79,8 +80,8 @@ js_alloc_symbol(void *priv, const void *key)
|
||||
return &sym->entry;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
js_free_symbol(void *priv, PRHashEntry *he, uintN flag)
|
||||
STATIC_DLL_CALLBACK(void)
|
||||
js_free_symbol(void *priv, JSHashEntry *he, uintN flag)
|
||||
{
|
||||
JSScopePrivate *spriv;
|
||||
JSContext *cx;
|
||||
@@ -88,7 +89,7 @@ js_free_symbol(void *priv, PRHashEntry *he, uintN flag)
|
||||
JSScopeProperty *sprop;
|
||||
|
||||
spriv = priv;
|
||||
PR_ASSERT(JS_IS_SCOPE_LOCKED(spriv->scope));
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(spriv->scope));
|
||||
cx = spriv->context;
|
||||
sym = (JSSymbol *)he;
|
||||
sprop = sym->entry.value;
|
||||
@@ -111,27 +112,27 @@ js_free_symbol(void *priv, PRHashEntry *he, uintN flag)
|
||||
JS_free(cx, he);
|
||||
}
|
||||
|
||||
static PRHashAllocOps hash_scope_alloc_ops = {
|
||||
static JSHashAllocOps hash_scope_alloc_ops = {
|
||||
js_alloc_scope_space, js_free_scope_space,
|
||||
js_alloc_symbol, js_free_symbol
|
||||
};
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
PR_STATIC_CALLBACK(JSSymbol *)
|
||||
js_hash_scope_lookup(JSContext *cx, JSScope *scope, jsid id, PRHashNumber hash)
|
||||
STATIC_DLL_CALLBACK(JSSymbol *)
|
||||
js_hash_scope_lookup(JSContext *cx, JSScope *scope, jsid id, JSHashNumber hash)
|
||||
{
|
||||
PRHashTable *table = scope->data;
|
||||
PRHashEntry **hep;
|
||||
JSHashTable *table = scope->data;
|
||||
JSHashEntry **hep;
|
||||
JSSymbol *sym;
|
||||
|
||||
hep = PR_HashTableRawLookup(table, hash, (const void *)id);
|
||||
hep = JS_HashTableRawLookup(table, hash, (const void *)id);
|
||||
sym = (JSSymbol *) *hep;
|
||||
return sym;
|
||||
}
|
||||
|
||||
#define SCOPE_ADD(PRIV, CLASS_SPECIFIC_CODE) \
|
||||
PR_BEGIN_MACRO \
|
||||
JS_BEGIN_MACRO \
|
||||
if (sym) { \
|
||||
if (sym->entry.value == sprop) \
|
||||
return sym; \
|
||||
@@ -150,58 +151,58 @@ js_hash_scope_lookup(JSContext *cx, JSScope *scope, jsid id, PRHashNumber hash)
|
||||
} else { \
|
||||
sym->entry.value = NULL; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
PR_STATIC_CALLBACK(JSSymbol *)
|
||||
STATIC_DLL_CALLBACK(JSSymbol *)
|
||||
js_hash_scope_add(JSContext *cx, JSScope *scope, jsid id, JSScopeProperty *sprop)
|
||||
{
|
||||
PRHashTable *table = scope->data;
|
||||
JSHashTable *table = scope->data;
|
||||
const void *key;
|
||||
PRHashNumber keyHash;
|
||||
PRHashEntry **hep;
|
||||
JSHashNumber keyHash;
|
||||
JSHashEntry **hep;
|
||||
JSSymbol *sym, **sp;
|
||||
JSScopePrivate *priv;
|
||||
|
||||
PR_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
priv = table->allocPriv;
|
||||
priv->context = cx;
|
||||
key = (const void *)id;
|
||||
keyHash = js_hash_id(key);
|
||||
hep = PR_HashTableRawLookup(table, keyHash, key);
|
||||
hep = JS_HashTableRawLookup(table, keyHash, key);
|
||||
sym = (JSSymbol *) *hep;
|
||||
SCOPE_ADD(priv,
|
||||
sym = (JSSymbol *) PR_HashTableRawAdd(table, hep, keyHash, key, NULL);
|
||||
sym = (JSSymbol *) JS_HashTableRawAdd(table, hep, keyHash, key, NULL);
|
||||
if (!sym)
|
||||
return NULL;
|
||||
);
|
||||
return sym;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
STATIC_DLL_CALLBACK(JSBool)
|
||||
js_hash_scope_remove(JSContext *cx, JSScope *scope, jsid id)
|
||||
{
|
||||
PRHashTable *table = scope->data;
|
||||
JSHashTable *table = scope->data;
|
||||
JSScopePrivate *priv;
|
||||
|
||||
PR_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
priv = table->allocPriv;
|
||||
priv->context = cx;
|
||||
return PR_HashTableRemove(table, (const void *)id);
|
||||
return JS_HashTableRemove(table, (const void *)id);
|
||||
}
|
||||
|
||||
/* Forward declaration for use by js_hash_scope_clear(). */
|
||||
extern JS_FRIEND_DATA(JSScopeOps) js_list_scope_ops;
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
STATIC_DLL_CALLBACK(void)
|
||||
js_hash_scope_clear(JSContext *cx, JSScope *scope)
|
||||
{
|
||||
PRHashTable *table = scope->data;
|
||||
JSHashTable *table = scope->data;
|
||||
JSScopePrivate *priv;
|
||||
|
||||
PR_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
priv = table->allocPriv;
|
||||
priv->context = cx;
|
||||
PR_HashTableDestroy(table);
|
||||
JS_HashTableDestroy(table);
|
||||
JS_free(cx, priv);
|
||||
scope->ops = &js_list_scope_ops;
|
||||
scope->data = NULL;
|
||||
@@ -216,12 +217,12 @@ JSScopeOps js_hash_scope_ops = {
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
PR_STATIC_CALLBACK(JSSymbol *)
|
||||
js_list_scope_lookup(JSContext *cx, JSScope *scope, jsid id, PRHashNumber hash)
|
||||
STATIC_DLL_CALLBACK(JSSymbol *)
|
||||
js_list_scope_lookup(JSContext *cx, JSScope *scope, jsid id, JSHashNumber hash)
|
||||
{
|
||||
JSSymbol *sym, **sp;
|
||||
|
||||
PR_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
for (sp = (JSSymbol **)&scope->data; (sym = *sp) != 0;
|
||||
sp = (JSSymbol **)&sym->entry.next) {
|
||||
if (sym_id(sym) == id) {
|
||||
@@ -237,17 +238,17 @@ js_list_scope_lookup(JSContext *cx, JSScope *scope, jsid id, PRHashNumber hash)
|
||||
|
||||
#define HASH_THRESHOLD 5
|
||||
|
||||
PR_STATIC_CALLBACK(JSSymbol *)
|
||||
STATIC_DLL_CALLBACK(JSSymbol *)
|
||||
js_list_scope_add(JSContext *cx, JSScope *scope, jsid id, JSScopeProperty *sprop)
|
||||
{
|
||||
JSSymbol *list = scope->data;
|
||||
uint32 nsyms;
|
||||
JSSymbol *sym, *next, **sp;
|
||||
PRHashTable *table;
|
||||
PRHashEntry **hep;
|
||||
JSHashTable *table;
|
||||
JSHashEntry **hep;
|
||||
JSScopePrivate priv;
|
||||
|
||||
PR_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
nsyms = 0;
|
||||
for (sym = list; sym; sym = (JSSymbol *)sym->entry.next) {
|
||||
if (sym_id(sym) == id)
|
||||
@@ -260,9 +261,9 @@ js_list_scope_add(JSContext *cx, JSScope *scope, jsid id, JSScopeProperty *sprop
|
||||
if (!priv) return NULL;
|
||||
priv->context = cx;
|
||||
priv->scope = scope;
|
||||
table = PR_NewHashTable(nsyms, js_hash_id,
|
||||
PR_CompareValues, PR_CompareValues,
|
||||
&hash_scope_alloc_ops, priv);
|
||||
table = JS_NewHashTable(nsyms, js_hash_id,
|
||||
JS_CompareValues, JS_CompareValues,
|
||||
&hash_scope_alloc_ops, priv);
|
||||
if (table) {
|
||||
for (sym = list; sym; sym = next) {
|
||||
/* Save next for loop update, before it changes in lookup. */
|
||||
@@ -271,7 +272,7 @@ js_list_scope_add(JSContext *cx, JSScope *scope, jsid id, JSScopeProperty *sprop
|
||||
/* Now compute missing keyHash fields. */
|
||||
sym->entry.keyHash = js_hash_id(sym->entry.key);
|
||||
sym->entry.next = NULL;
|
||||
hep = PR_HashTableRawLookup(table,
|
||||
hep = JS_HashTableRawLookup(table,
|
||||
sym->entry.keyHash,
|
||||
sym->entry.key);
|
||||
*hep = &sym->entry;
|
||||
@@ -296,13 +297,13 @@ js_list_scope_add(JSContext *cx, JSScope *scope, jsid id, JSScopeProperty *sprop
|
||||
return sym;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
STATIC_DLL_CALLBACK(JSBool)
|
||||
js_list_scope_remove(JSContext *cx, JSScope *scope, jsid id)
|
||||
{
|
||||
JSSymbol *sym, **sp;
|
||||
JSScopePrivate priv;
|
||||
|
||||
PR_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
for (sp = (JSSymbol **)&scope->data; (sym = *sp) != 0;
|
||||
sp = (JSSymbol **)&sym->entry.next) {
|
||||
if (sym_id(sym) == id) {
|
||||
@@ -316,13 +317,13 @@ js_list_scope_remove(JSContext *cx, JSScope *scope, jsid id)
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
STATIC_DLL_CALLBACK(void)
|
||||
js_list_scope_clear(JSContext *cx, JSScope *scope)
|
||||
{
|
||||
JSSymbol *sym;
|
||||
JSScopePrivate priv;
|
||||
|
||||
PR_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
while ((sym = scope->data) != NULL) {
|
||||
scope->data = sym->entry.next;
|
||||
priv.context = cx;
|
||||
@@ -346,7 +347,7 @@ js_GetMutableScope(JSContext *cx, JSObject *obj)
|
||||
JSScope *scope, *newscope;
|
||||
|
||||
scope = (JSScope *) obj->map;
|
||||
PR_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
if (scope->object == obj)
|
||||
return scope;
|
||||
newscope = js_NewScope(cx, 0, scope->map.ops, LOCKED_OBJ_GET_CLASS(obj),
|
||||
@@ -405,13 +406,13 @@ js_DestroyScope(JSContext *cx, JSScope *scope)
|
||||
scope->ops->clear(cx, scope);
|
||||
JS_UNLOCK_SCOPE(cx, scope);
|
||||
#ifdef JS_THREADSAFE
|
||||
PR_ASSERT(scope->count == 0);
|
||||
JS_ASSERT(scope->count == 0);
|
||||
js_DestroyLock(&scope->lock);
|
||||
#endif
|
||||
JS_free(cx, scope);
|
||||
}
|
||||
|
||||
PRHashNumber
|
||||
JSHashNumber
|
||||
js_HashValue(jsval v)
|
||||
{
|
||||
return js_hash_id((const void *)v);
|
||||
@@ -435,7 +436,7 @@ js_NewScopeProperty(JSContext *cx, JSScope *scope, jsid id,
|
||||
uint32 slot;
|
||||
JSScopeProperty *sprop;
|
||||
|
||||
PR_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
if (!js_AllocSlot(cx, scope->object, &slot))
|
||||
return NULL;
|
||||
sprop = JS_malloc(cx, sizeof(JSScopeProperty));
|
||||
@@ -476,7 +477,7 @@ js_DestroyScopeProperty(JSContext *cx, JSScope *scope, JSScopeProperty *sprop)
|
||||
* sure to free prop's slot and unlink it from obj's property list.
|
||||
*/
|
||||
if (scope) {
|
||||
PR_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
if (scope->object) {
|
||||
js_FreeSlot(cx, scope->object, sprop->slot);
|
||||
*sprop->prevp = sprop->next;
|
||||
@@ -495,9 +496,9 @@ js_DestroyScopeProperty(JSContext *cx, JSScope *scope, JSScopeProperty *sprop)
|
||||
JSScopeProperty *
|
||||
js_HoldScopeProperty(JSContext *cx, JSScope *scope, JSScopeProperty *sprop)
|
||||
{
|
||||
PR_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
if (sprop) {
|
||||
PR_ASSERT(sprop->nrefs >= 0);
|
||||
JS_ASSERT(sprop->nrefs >= 0);
|
||||
sprop->nrefs++;
|
||||
}
|
||||
return sprop;
|
||||
@@ -506,9 +507,9 @@ js_HoldScopeProperty(JSContext *cx, JSScope *scope, JSScopeProperty *sprop)
|
||||
JSScopeProperty *
|
||||
js_DropScopeProperty(JSContext *cx, JSScope *scope, JSScopeProperty *sprop)
|
||||
{
|
||||
PR_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(scope));
|
||||
if (sprop) {
|
||||
PR_ASSERT(sprop->nrefs > 0);
|
||||
JS_ASSERT(sprop->nrefs > 0);
|
||||
if (--sprop->nrefs == 0) {
|
||||
js_DestroyScopeProperty(cx, scope, sprop);
|
||||
sprop = NULL;
|
||||
|
||||
@@ -21,11 +21,13 @@
|
||||
/*
|
||||
* JS symbol tables.
|
||||
*/
|
||||
#include "prtypes.h"
|
||||
#include "jstypes.h"
|
||||
#ifndef NSPR20
|
||||
#include "prhash.h"
|
||||
#include "jshash.h"
|
||||
#else
|
||||
#include "plhash.h"
|
||||
/* Removed by JSIFY: #include "JShash.h"
|
||||
*/
|
||||
#include "jshash.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "jsobj.h"
|
||||
#include "jsprvtd.h"
|
||||
@@ -33,7 +35,7 @@
|
||||
|
||||
struct JSScopeOps {
|
||||
JSSymbol * (*lookup)(JSContext *cx, JSScope *scope, jsid id,
|
||||
PRHashNumber hash);
|
||||
JSHashNumber hash);
|
||||
JSSymbol * (*add)(JSContext *cx, JSScope *scope, jsid id,
|
||||
JSScopeProperty *sprop);
|
||||
JSBool (*remove)(JSContext *cx, JSScope *scope, jsid id);
|
||||
@@ -58,7 +60,7 @@ struct JSScope {
|
||||
};
|
||||
|
||||
struct JSSymbol {
|
||||
PRHashEntry entry; /* base class state */
|
||||
JSHashEntry entry; /* base class state */
|
||||
JSScope *scope; /* pointer to owning scope */
|
||||
JSSymbol *next; /* next in type-specific list */
|
||||
};
|
||||
@@ -104,7 +106,7 @@ js_NewScope(JSContext *cx, jsrefcount nrefs, JSObjectOps *ops, JSClass *clasp,
|
||||
extern void
|
||||
js_DestroyScope(JSContext *cx, JSScope *scope);
|
||||
|
||||
extern PRHashNumber
|
||||
extern JSHashNumber
|
||||
js_HashValue(jsval v);
|
||||
|
||||
extern jsval
|
||||
|
||||
@@ -21,9 +21,10 @@
|
||||
*/
|
||||
#include "jsstddef.h"
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "prlog.h"
|
||||
#include "prprf.h"
|
||||
#include "jstypes.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#include "jsprf.h"
|
||||
#include "jsapi.h"
|
||||
#include "jsatom.h"
|
||||
#include "jscntxt.h"
|
||||
@@ -58,7 +59,7 @@ script_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
script = JS_GetPrivate(cx, obj);
|
||||
|
||||
/* Let n count the source string length, j the "front porch" length. */
|
||||
j = PR_snprintf(buf, sizeof buf, "(new %s(", js_ScriptClass.name);
|
||||
j = JS_snprintf(buf, sizeof buf, "(new %s(", js_ScriptClass.name);
|
||||
n = j + 2;
|
||||
if (!script) {
|
||||
/* Let k count the constructor argument string length. */
|
||||
@@ -71,12 +72,12 @@ script_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
(uintN)indent);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
str = js_QuoteString(cx, str, '\'');
|
||||
str = js_QuoteString(cx, str, '\'');
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
s = str->chars;
|
||||
s = str->chars;
|
||||
k = str->length;
|
||||
n += k;
|
||||
n += k;
|
||||
}
|
||||
|
||||
/* Allocate the source string and copy into it. */
|
||||
@@ -111,11 +112,11 @@ script_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
JSString *str;
|
||||
|
||||
if (!JS_InstanceOf(cx, obj, &js_ScriptClass, argv))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
script = JS_GetPrivate(cx, obj);
|
||||
if (!script) {
|
||||
*rval = STRING_TO_JSVAL(cx->runtime->emptyString);
|
||||
return JS_TRUE;
|
||||
*rval = STRING_TO_JSVAL(cx->runtime->emptyString);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
indent = 0;
|
||||
@@ -124,7 +125,7 @@ script_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
str = JS_DecompileScript(cx, script, "Script.prototype.toString",
|
||||
(uintN)indent);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
return JS_TRUE;
|
||||
}
|
||||
@@ -143,26 +144,26 @@ script_compile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
|
||||
/* If no args, leave private undefined and return early. */
|
||||
if (argc == 0)
|
||||
goto out;
|
||||
goto out;
|
||||
|
||||
/* Otherwise, the first arg is the script source to compile. */
|
||||
str = js_ValueToString(cx, argv[0]);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
|
||||
/* Compile using the caller's scope chain, which js_Invoke passes to fp. */
|
||||
fp = cx->fp;
|
||||
caller = fp->down;
|
||||
PR_ASSERT(fp->scopeChain == caller->scopeChain);
|
||||
JS_ASSERT(fp->scopeChain == caller->scopeChain);
|
||||
|
||||
scopeobj = NULL;
|
||||
if (argc >= 2) {
|
||||
if (!js_ValueToObject(cx, argv[1], &scopeobj))
|
||||
if (!js_ValueToObject(cx, argv[1], &scopeobj))
|
||||
return JS_FALSE;
|
||||
argv[1] = OBJECT_TO_JSVAL(scopeobj);
|
||||
argv[1] = OBJECT_TO_JSVAL(scopeobj);
|
||||
}
|
||||
if (!scopeobj)
|
||||
scopeobj = caller->scopeChain;
|
||||
scopeobj = caller->scopeChain;
|
||||
|
||||
if (caller->script) {
|
||||
file = caller->script->filename;
|
||||
@@ -179,13 +180,13 @@ script_compile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
str->chars, str->length,
|
||||
file, line);
|
||||
if (!script)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
|
||||
/* Swap script for obj's old script, if any. */
|
||||
oldscript = JS_GetPrivate(cx, obj);
|
||||
if (!JS_SetPrivate(cx, obj, script)) {
|
||||
js_DestroyScript(cx, script);
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
}
|
||||
if (oldscript)
|
||||
js_DestroyScript(cx, oldscript);
|
||||
@@ -205,25 +206,25 @@ script_exec(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
JSObject *scopeobj;
|
||||
|
||||
if (!JS_InstanceOf(cx, obj, &js_ScriptClass, argv))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
script = JS_GetPrivate(cx, obj);
|
||||
if (!script)
|
||||
return JS_TRUE;
|
||||
return JS_TRUE;
|
||||
|
||||
scopeobj = NULL;
|
||||
if (argc) {
|
||||
if (!js_ValueToObject(cx, argv[0], &scopeobj))
|
||||
if (!js_ValueToObject(cx, argv[0], &scopeobj))
|
||||
return JS_FALSE;
|
||||
argv[0] = OBJECT_TO_JSVAL(scopeobj);
|
||||
argv[0] = OBJECT_TO_JSVAL(scopeobj);
|
||||
}
|
||||
|
||||
/* Emulate eval() by using caller's this, scope chain, and sharp array. */
|
||||
fp = cx->fp;
|
||||
caller = fp->down;
|
||||
if (!scopeobj)
|
||||
scopeobj = caller->scopeChain;
|
||||
scopeobj = caller->scopeChain;
|
||||
fp->thisp = caller->thisp;
|
||||
PR_ASSERT(fp->scopeChain == caller->scopeChain);
|
||||
JS_ASSERT(fp->scopeChain == caller->scopeChain);
|
||||
fp->sharpArray = caller->sharpArray;
|
||||
return js_Execute(cx, scopeobj, script, NULL, fp, JS_FALSE, rval);
|
||||
}
|
||||
@@ -271,15 +272,15 @@ XDRAtomMap(JSXDRState *xdr, JSAtomMap *map)
|
||||
JSAtomListElement *ale;
|
||||
|
||||
cx = xdr->cx;
|
||||
mark = PR_ARENA_MARK(&cx->tempPool);
|
||||
mark = JS_ARENA_MARK(&cx->tempPool);
|
||||
ATOM_LIST_INIT(&al);
|
||||
for (i = 0; i < length; i++) {
|
||||
PR_ARENA_ALLOCATE(ale, &cx->tempPool, sizeof(*ale));
|
||||
JS_ARENA_ALLOCATE(ale, &cx->tempPool, sizeof(*ale));
|
||||
if (!ale ||
|
||||
!XDRAtom1(xdr, ale)) {
|
||||
if (!ale)
|
||||
JS_ReportOutOfMemory(cx);
|
||||
PR_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
return JS_FALSE;
|
||||
}
|
||||
ale->next = al.list;
|
||||
@@ -287,10 +288,10 @@ XDRAtomMap(JSXDRState *xdr, JSAtomMap *map)
|
||||
al.list = ale;
|
||||
}
|
||||
if (!js_InitAtomMap(cx, map, &al)) {
|
||||
PR_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
return JS_FALSE;
|
||||
}
|
||||
PR_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
} else if (xdr->mode == JSXDR_ENCODE) {
|
||||
JSAtomListElement ale;
|
||||
|
||||
@@ -389,7 +390,7 @@ script_freeze(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
goto out;
|
||||
}
|
||||
|
||||
PR_ASSERT((prword)buf % sizeof(jschar) == 0);
|
||||
JS_ASSERT((jsword)buf % sizeof(jschar) == 0);
|
||||
len /= sizeof(jschar);
|
||||
str = JS_NewUCStringCopyN(cx, (jschar *)buf, len);
|
||||
if (!str) {
|
||||
@@ -405,7 +406,7 @@ script_freeze(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
/* Swap bytes in Unichars to keep frozen strings machine-independent. */
|
||||
chars = JS_GetStringChars(str);
|
||||
for (i = 0; i < len; i++)
|
||||
chars[i] = JSXDR_SWAB16(chars[i]);
|
||||
chars[i] = JSXDR_SWAB16(chars[i]);
|
||||
}
|
||||
#endif
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
@@ -430,10 +431,10 @@ script_thaw(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
return JS_FALSE;
|
||||
|
||||
if (argc == 0)
|
||||
return JS_TRUE;
|
||||
return JS_TRUE;
|
||||
str = js_ValueToString(cx, argv[0]);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
|
||||
/* create new XDR */
|
||||
xdr = JS_XDRNewMem(cx, JSXDR_DECODE);
|
||||
@@ -451,9 +452,9 @@ script_thaw(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
from = (jschar *)buf;
|
||||
to = JS_malloc(cx, len * sizeof(jschar));
|
||||
if (!to)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
for (i = 0; i < len; i++)
|
||||
to[i] = JSXDR_SWAB16(from[i]);
|
||||
to[i] = JSXDR_SWAB16(from[i]);
|
||||
buf = (char *)to;
|
||||
}
|
||||
#endif
|
||||
@@ -522,7 +523,7 @@ script_finalize(JSContext *cx, JSObject *obj)
|
||||
|
||||
script = JS_GetPrivate(cx, obj);
|
||||
if (script)
|
||||
js_DestroyScript(cx, script);
|
||||
js_DestroyScript(cx, script);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
@@ -546,8 +547,8 @@ Script(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
/* If not constructing, replace obj with a new Script object. */
|
||||
if (!cx->fp->constructing) {
|
||||
obj = js_NewObject(cx, &js_ScriptClass, NULL, NULL);
|
||||
if (!obj)
|
||||
obj = js_NewObject(cx, &js_ScriptClass, NULL, NULL);
|
||||
if (!obj)
|
||||
return JS_FALSE;
|
||||
}
|
||||
return script_compile(cx, obj, argc, argv, rval);
|
||||
@@ -563,7 +564,7 @@ script_static_thaw(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
if (!obj)
|
||||
return JS_FALSE;
|
||||
if (!script_thaw(cx, obj, argc, argv, rval))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
*rval = OBJECT_TO_JSVAL(obj);
|
||||
return JS_TRUE;
|
||||
}
|
||||
@@ -612,11 +613,11 @@ js_NewScriptFromParams(JSContext *cx, jsbytecode *code, uint32 length,
|
||||
|
||||
script = js_NewScript(cx, length);
|
||||
if (!script)
|
||||
return NULL;
|
||||
return NULL;
|
||||
memcpy(script->code, code, length * sizeof(jsbytecode));
|
||||
if (filename) {
|
||||
script->filename = JS_strdup(cx, filename);
|
||||
if (!script->filename) {
|
||||
script->filename = JS_strdup(cx, filename);
|
||||
if (!script->filename) {
|
||||
js_DestroyScript(cx, script);
|
||||
return NULL;
|
||||
}
|
||||
@@ -626,7 +627,7 @@ js_NewScriptFromParams(JSContext *cx, jsbytecode *code, uint32 length,
|
||||
script->notes = notes;
|
||||
script->trynotes = trynotes;
|
||||
if (principals)
|
||||
JSPRINCIPALS_HOLD(cx, principals);
|
||||
JSPRINCIPALS_HOLD(cx, principals);
|
||||
script->principals = principals;
|
||||
return script;
|
||||
}
|
||||
@@ -648,7 +649,7 @@ js_NewScriptFromCG(JSContext *cx, JSCodeGenerator *cg, JSFunction *fun)
|
||||
cg->maxStackDepth, notes, trynotes,
|
||||
cg->principals);
|
||||
if (!script)
|
||||
return NULL;
|
||||
return NULL;
|
||||
if (!notes || !js_InitAtomMap(cx, &script->atomMap, &cg->atomList)) {
|
||||
js_DestroyScript(cx, script);
|
||||
return NULL;
|
||||
@@ -658,8 +659,8 @@ js_NewScriptFromCG(JSContext *cx, JSCodeGenerator *cg, JSFunction *fun)
|
||||
rt = cx->runtime;
|
||||
hook = rt->newScriptHook;
|
||||
if (hook) {
|
||||
(*hook)(cx, cg->filename, cg->firstLine, script, fun,
|
||||
rt->newScriptHookData);
|
||||
(*hook)(cx, cg->filename, cg->firstLine, script, fun,
|
||||
rt->newScriptHookData);
|
||||
}
|
||||
return script;
|
||||
}
|
||||
@@ -673,17 +674,15 @@ js_DestroyScript(JSContext *cx, JSScript *script)
|
||||
rt = cx->runtime;
|
||||
hook = rt->destroyScriptHook;
|
||||
if (hook)
|
||||
(*hook)(cx, script, rt->destroyScriptHookData);
|
||||
(*hook)(cx, script, rt->destroyScriptHookData);
|
||||
|
||||
JS_ClearScriptTraps(cx, script);
|
||||
js_FreeAtomMap(cx, &script->atomMap);
|
||||
if (js_InterpreterHooks && js_InterpreterHooks->destroyScript)
|
||||
js_InterpreterHooks->destroyScript(cx, script);
|
||||
JS_free(cx, (void *)script->filename);
|
||||
JS_free(cx, script->notes);
|
||||
JS_free(cx, script->trynotes);
|
||||
if (script->principals)
|
||||
JSPRINCIPALS_DROP(cx, script->principals);
|
||||
JSPRINCIPALS_DROP(cx, script->principals);
|
||||
JS_free(cx, script);
|
||||
}
|
||||
|
||||
@@ -695,14 +694,14 @@ js_GetSrcNote(JSScript *script, jsbytecode *pc)
|
||||
|
||||
sn = script->notes;
|
||||
if (!sn)
|
||||
return NULL;
|
||||
return NULL;
|
||||
target = PTRDIFF(pc, script->code, jsbytecode);
|
||||
if ((uintN)target >= script->length)
|
||||
return NULL;
|
||||
return NULL;
|
||||
for (offset = 0; !SN_IS_TERMINATOR(sn); sn = SN_NEXT(sn)) {
|
||||
offset += SN_DELTA(sn);
|
||||
if (offset == target && SN_IS_GETTABLE(sn))
|
||||
return sn;
|
||||
offset += SN_DELTA(sn);
|
||||
if (offset == target && SN_IS_GETTABLE(sn))
|
||||
return sn;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -717,21 +716,21 @@ js_PCToLineNumber(JSScript *script, jsbytecode *pc)
|
||||
|
||||
sn = script->notes;
|
||||
if (!sn)
|
||||
return 0;
|
||||
return 0;
|
||||
target = PTRDIFF(pc, script->code, jsbytecode);
|
||||
lineno = script->lineno;
|
||||
for (offset = 0; !SN_IS_TERMINATOR(sn); sn = SN_NEXT(sn)) {
|
||||
offset += SN_DELTA(sn);
|
||||
type = SN_TYPE(sn);
|
||||
if (type == SRC_SETLINE) {
|
||||
if (offset <= target)
|
||||
lineno = (uintN) js_GetSrcNoteOffset(sn, 0);
|
||||
} else if (type == SRC_NEWLINE) {
|
||||
if (offset <= target)
|
||||
lineno++;
|
||||
}
|
||||
if (offset > target)
|
||||
break;
|
||||
offset += SN_DELTA(sn);
|
||||
type = SN_TYPE(sn);
|
||||
if (type == SRC_SETLINE) {
|
||||
if (offset <= target)
|
||||
lineno = (uintN) js_GetSrcNoteOffset(sn, 0);
|
||||
} else if (type == SRC_NEWLINE) {
|
||||
if (offset <= target)
|
||||
lineno++;
|
||||
}
|
||||
if (offset > target)
|
||||
break;
|
||||
}
|
||||
return lineno;
|
||||
}
|
||||
@@ -746,18 +745,18 @@ js_LineNumberToPC(JSScript *script, uintN target)
|
||||
|
||||
sn = script->notes;
|
||||
if (!sn)
|
||||
return NULL;
|
||||
return NULL;
|
||||
lineno = script->lineno;
|
||||
for (offset = 0; !SN_IS_TERMINATOR(sn); sn = SN_NEXT(sn)) {
|
||||
if (lineno >= target)
|
||||
break;
|
||||
offset += SN_DELTA(sn);
|
||||
type = SN_TYPE(sn);
|
||||
if (type == SRC_SETLINE) {
|
||||
lineno = (uintN) js_GetSrcNoteOffset(sn, 0);
|
||||
} else if (type == SRC_NEWLINE) {
|
||||
lineno++;
|
||||
}
|
||||
if (lineno >= target)
|
||||
break;
|
||||
offset += SN_DELTA(sn);
|
||||
type = SN_TYPE(sn);
|
||||
if (type == SRC_SETLINE) {
|
||||
lineno = (uintN) js_GetSrcNoteOffset(sn, 0);
|
||||
} else if (type == SRC_NEWLINE) {
|
||||
lineno++;
|
||||
}
|
||||
}
|
||||
return script->code + offset;
|
||||
}
|
||||
@@ -771,15 +770,15 @@ js_GetScriptLineExtent(JSScript *script)
|
||||
|
||||
sn = script->notes;
|
||||
if (!sn)
|
||||
return 0;
|
||||
return 0;
|
||||
lineno = script->lineno;
|
||||
for (; !SN_IS_TERMINATOR(sn); sn = SN_NEXT(sn)) {
|
||||
type = SN_TYPE(sn);
|
||||
if (type == SRC_SETLINE) {
|
||||
lineno = (uintN) js_GetSrcNoteOffset(sn, 0);
|
||||
} else if (type == SRC_NEWLINE) {
|
||||
lineno++;
|
||||
}
|
||||
type = SN_TYPE(sn);
|
||||
if (type == SRC_SETLINE) {
|
||||
lineno = (uintN) js_GetSrcNoteOffset(sn, 0);
|
||||
} else if (type == SRC_NEWLINE) {
|
||||
lineno++;
|
||||
}
|
||||
}
|
||||
return 1 + lineno - script->lineno;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "jsatom.h"
|
||||
#include "jsprvtd.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
* Exception handling runtime information.
|
||||
@@ -50,7 +50,6 @@ struct JSScript {
|
||||
jssrcnote *notes; /* line number and other decompiling data */
|
||||
JSTryNote *trynotes; /* exception table for this script */
|
||||
JSPrincipals *principals; /* principals for this script */
|
||||
void *javaData; /* XXX extra data used by jsjava.c */
|
||||
JSObject *object; /* optional Script-class object wrapper */
|
||||
};
|
||||
|
||||
@@ -89,6 +88,6 @@ js_GetScriptLineExtent(JSScript *script);
|
||||
extern JSBool
|
||||
js_XDRScript(JSXDRState *xdr, JSScript **scriptp, JSBool *magic);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsscript_h___ */
|
||||
|
||||
16
mozilla/js/src/jsshell.msg
Normal file
16
mozilla/js/src/jsshell.msg
Normal file
@@ -0,0 +1,16 @@
|
||||
/* -*- Mode: C; tab-width: 8 -*-
|
||||
* Copyright (C) 1998 Netscape Communications Corporation, All Rights Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
Error messages for JSShell. See JSJMSG.def for format.
|
||||
|
||||
*/
|
||||
|
||||
MSG_DEF(JSSMSG_NOT_AN_ERROR, 0, 0, JSEXN_NONE, "<Error #0 is reserved>")
|
||||
MSG_DEF(JSSMSG_CANT_OPEN, 1, 2, JSEXN_NONE, "can't open {0}: {1}")
|
||||
MSG_DEF(JSSMSG_TRAP_USAGE, 2, 0, JSEXN_NONE, "usage: trap [fun] [pc] expr")
|
||||
MSG_DEF(JSSMSG_LINE2PC_USAGE, 3, 0, JSEXN_NONE, "usage: line2pc [fun] line")
|
||||
MSG_DEF(JSSMSG_FILE_SCRIPTS_ONLY, 4, 0, JSEXN_NONE, "only works on JS scripts read from files")
|
||||
MSG_DEF(JSSMSG_UNEXPECTED_EOF, 5, 1, JSEXN_NONE, "unexpected EOF in {0}")
|
||||
MSG_DEF(JSSMSG_DOEXP_USAGE, 6, 0, JSEXN_NONE, "usage: doexp obj id")
|
||||
@@ -29,14 +29,17 @@
|
||||
#include "jsstddef.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "prlog.h"
|
||||
#include "jstypes.h"
|
||||
/* Removed by JSIFY: #include "prlog.h" */
|
||||
#include "jsutil.h" /* Added by JSIFY */
|
||||
#ifndef NSPR20
|
||||
#include "prhash.h"
|
||||
#include "jshash.h"
|
||||
#else
|
||||
#include "plhash.h"
|
||||
/* Removed by JSIFY: #include "JShash.h"
|
||||
*/
|
||||
#include "jshash.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "prprf.h"
|
||||
#include "jsprf.h"
|
||||
#include "jsapi.h"
|
||||
#include "jsarray.h"
|
||||
#include "jsatom.h"
|
||||
@@ -57,7 +60,7 @@
|
||||
|
||||
/* Contributions from the String class to the set of methods defined for the
|
||||
* global object. escape and unescape used to be defined in the Mocha library,
|
||||
* but as ECMA decided to spec them. So they've been moved to the core engine
|
||||
* but as ECMA decided to spec them, they've been moved to the core engine
|
||||
* and made ECMA-compliant. (Incomplete escapes are interpreted as literal
|
||||
* characters by unescape.)
|
||||
*/
|
||||
@@ -79,13 +82,13 @@ static const unsigned char netCharType[256] =
|
||||
*/
|
||||
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 1x */
|
||||
0,0,0,0,0,0,0,0,0,0,7,4,0,7,7,4, /* 2x !"#$%&'()*+,-./ */
|
||||
7,7,7,7,7,7,7,7,7,7,0,0,0,0,0,0, /* 3x 0123456789:;<=>? */
|
||||
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, /* 4x @ABCDEFGHIJKLMNO */
|
||||
7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,7, /* 5X PQRSTUVWXYZ[\]^_ */
|
||||
0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, /* 6x `abcdefghijklmno */
|
||||
7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,0, /* 7X pqrstuvwxyz{\}~ DEL */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 1x */
|
||||
0,0,0,0,0,0,0,0,0,0,7,4,0,7,7,4, /* 2x !"#$%&'()*+,-./ */
|
||||
7,7,7,7,7,7,7,7,7,7,0,0,0,0,0,0, /* 3x 0123456789:;<=>? */
|
||||
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, /* 4x @ABCDEFGHIJKLMNO */
|
||||
7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,7, /* 5X PQRSTUVWXYZ[\]^_ */
|
||||
0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, /* 6x `abcdefghijklmno */
|
||||
7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,0, /* 7X pqrstuvwxyz{\}~ DEL */
|
||||
0, };
|
||||
|
||||
/* This matches the ECMA escape set when mask is 7 (default.) */
|
||||
@@ -104,71 +107,74 @@ str_escape(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
jsint mask;
|
||||
jsdouble d;
|
||||
const char digits[] = {'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
|
||||
if (argc > 1) {
|
||||
if (!js_ValueToNumber(cx, argv[1], &d))
|
||||
return JS_FALSE;
|
||||
if (!JSDOUBLE_IS_FINITE(d) ||
|
||||
(mask = (jsint)d) != d ||
|
||||
mask & ~(URL_XALPHAS | URL_XPALPHAS | URL_PATH))
|
||||
{
|
||||
JS_ReportError(cx, "invalid string escape mask %x", mask);
|
||||
return JS_FALSE;
|
||||
}
|
||||
if (!js_ValueToNumber(cx, argv[1], &d))
|
||||
return JS_FALSE;
|
||||
if (!JSDOUBLE_IS_FINITE(d) ||
|
||||
(mask = (jsint)d) != d ||
|
||||
mask & ~(URL_XALPHAS | URL_XPALPHAS | URL_PATH))
|
||||
{
|
||||
char numBuf[12];
|
||||
JS_snprintf(numBuf, sizeof numBuf, "%lx", (unsigned long) mask);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_BAD_STRING_MASK, numBuf);
|
||||
return JS_FALSE;
|
||||
}
|
||||
} else {
|
||||
mask = URL_XALPHAS | URL_XPALPHAS | URL_PATH;
|
||||
mask = URL_XALPHAS | URL_XPALPHAS | URL_PATH;
|
||||
}
|
||||
|
||||
str = js_ValueToString(cx, argv[0]);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
argv[0] = STRING_TO_JSVAL(str);
|
||||
|
||||
chars = str->chars;
|
||||
newlength = str->length;
|
||||
/* Take a first pass and see how big the result string will need to be. */
|
||||
for (i = 0; i < str->length; i++) {
|
||||
if ((ch = chars[i]) < 128 && IS_OK(ch, mask)) {
|
||||
continue;
|
||||
} else if (ch < 256) {
|
||||
if (mask == URL_XPALPHAS && ch == ' ')
|
||||
continue; /* The character will be encoded as '+' */
|
||||
else
|
||||
newlength += 2; /* The character will be encoded as %XX */
|
||||
} else {
|
||||
newlength += 5; /* The character will be encoded as %uXXXX */
|
||||
}
|
||||
if ((ch = chars[i]) < 128 && IS_OK(ch, mask)) {
|
||||
continue;
|
||||
} else if (ch < 256) {
|
||||
if (mask == URL_XPALPHAS && ch == ' ')
|
||||
continue; /* The character will be encoded as '+' */
|
||||
else
|
||||
newlength += 2; /* The character will be encoded as %XX */
|
||||
} else {
|
||||
newlength += 5; /* The character will be encoded as %uXXXX */
|
||||
}
|
||||
}
|
||||
|
||||
newchars = (jschar *) JS_malloc(cx, (newlength + 1) * sizeof(jschar));
|
||||
for (i = 0, ni = 0; i < str->length; i++) {
|
||||
if ((ch = chars[i]) < 128 && IS_OK(ch, mask)) {
|
||||
newchars[ni++] = ch;
|
||||
} else if (ch < 256) {
|
||||
if (mask == URL_XPALPHAS && ch == ' ') {
|
||||
newchars[ni++] = '+'; /* convert spaces to pluses */
|
||||
} else {
|
||||
newchars[ni++] = '%';
|
||||
newchars[ni++] = digits[ch >> 4];
|
||||
newchars[ni++] = digits[ch & 0xF];
|
||||
}
|
||||
} else {
|
||||
newchars[ni++] = '%';
|
||||
newchars[ni++] = 'u';
|
||||
newchars[ni++] = digits[ch >> 12];
|
||||
newchars[ni++] = digits[(ch & 0xF00) >> 8];
|
||||
newchars[ni++] = digits[(ch & 0xF0) >> 4];
|
||||
newchars[ni++] = digits[ch & 0xF];
|
||||
}
|
||||
if ((ch = chars[i]) < 128 && IS_OK(ch, mask)) {
|
||||
newchars[ni++] = ch;
|
||||
} else if (ch < 256) {
|
||||
if (mask == URL_XPALPHAS && ch == ' ') {
|
||||
newchars[ni++] = '+'; /* convert spaces to pluses */
|
||||
} else {
|
||||
newchars[ni++] = '%';
|
||||
newchars[ni++] = digits[ch >> 4];
|
||||
newchars[ni++] = digits[ch & 0xF];
|
||||
}
|
||||
} else {
|
||||
newchars[ni++] = '%';
|
||||
newchars[ni++] = 'u';
|
||||
newchars[ni++] = digits[ch >> 12];
|
||||
newchars[ni++] = digits[(ch & 0xF00) >> 8];
|
||||
newchars[ni++] = digits[(ch & 0xF0) >> 4];
|
||||
newchars[ni++] = digits[ch & 0xF];
|
||||
}
|
||||
}
|
||||
PR_ASSERT(ni == newlength);
|
||||
JS_ASSERT(ni == newlength);
|
||||
newchars[newlength] = 0;
|
||||
|
||||
str = js_NewString(cx, newchars, newlength, 0);
|
||||
if (!str) {
|
||||
JS_free(cx, newchars);
|
||||
return JS_FALSE;
|
||||
JS_free(cx, newchars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
return JS_TRUE;
|
||||
@@ -187,7 +193,7 @@ str_unescape(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
|
||||
str = js_ValueToString(cx, argv[0]);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
argv[0] = STRING_TO_JSVAL(str);
|
||||
|
||||
chars = str->chars;
|
||||
@@ -195,32 +201,32 @@ str_unescape(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
newchars = (jschar *) JS_malloc(cx, (str->length + 1) * sizeof(jschar));
|
||||
ni = i = 0;
|
||||
while (i < str->length) {
|
||||
ch = chars[i++];
|
||||
if (ch == '%') {
|
||||
if (i + 1 < str->length &&
|
||||
JS7_ISHEX(chars[i]) && JS7_ISHEX(chars[i + 1]))
|
||||
{
|
||||
ch = JS7_UNHEX(chars[i]) * 16 + JS7_UNHEX(chars[i + 1]);
|
||||
i += 2;
|
||||
} else if (i + 4 < str->length && chars[i] == 'u' &&
|
||||
JS7_ISHEX(chars[i + 1]) && JS7_ISHEX(chars[i + 2]) &&
|
||||
JS7_ISHEX(chars[i + 3]) && JS7_ISHEX(chars[i + 4]))
|
||||
{
|
||||
ch = (((((JS7_UNHEX(chars[i + 1]) << 4)
|
||||
+ JS7_UNHEX(chars[i + 2])) << 4)
|
||||
+ JS7_UNHEX(chars[i + 3])) << 4)
|
||||
+ JS7_UNHEX(chars[i + 4]);
|
||||
i += 5;
|
||||
}
|
||||
}
|
||||
newchars[ni++] = ch;
|
||||
ch = chars[i++];
|
||||
if (ch == '%') {
|
||||
if (i + 1 < str->length &&
|
||||
JS7_ISHEX(chars[i]) && JS7_ISHEX(chars[i + 1]))
|
||||
{
|
||||
ch = JS7_UNHEX(chars[i]) * 16 + JS7_UNHEX(chars[i + 1]);
|
||||
i += 2;
|
||||
} else if (i + 4 < str->length && chars[i] == 'u' &&
|
||||
JS7_ISHEX(chars[i + 1]) && JS7_ISHEX(chars[i + 2]) &&
|
||||
JS7_ISHEX(chars[i + 3]) && JS7_ISHEX(chars[i + 4]))
|
||||
{
|
||||
ch = (((((JS7_UNHEX(chars[i + 1]) << 4)
|
||||
+ JS7_UNHEX(chars[i + 2])) << 4)
|
||||
+ JS7_UNHEX(chars[i + 3])) << 4)
|
||||
+ JS7_UNHEX(chars[i + 4]);
|
||||
i += 5;
|
||||
}
|
||||
}
|
||||
newchars[ni++] = ch;
|
||||
}
|
||||
newchars[ni] = 0;
|
||||
|
||||
str = js_NewString(cx, newchars, ni, 0);
|
||||
if (!str) {
|
||||
JS_free(cx, newchars);
|
||||
return JS_FALSE;
|
||||
JS_free(cx, newchars);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
return JS_TRUE;
|
||||
@@ -345,7 +351,7 @@ str_quote(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
return JS_FALSE;
|
||||
str = js_QuoteString(cx, str, '"');
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
return JS_TRUE;
|
||||
}
|
||||
@@ -366,25 +372,25 @@ str_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
return js_obj_toSource(cx, obj, argc, argv, rval);
|
||||
str = js_QuoteString(cx, JSVAL_TO_STRING(v), '"');
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
j = PR_snprintf(buf, sizeof buf, "(new %s(", string_class.name);
|
||||
return JS_FALSE;
|
||||
j = JS_snprintf(buf, sizeof buf, "(new %s(", string_class.name);
|
||||
s = str->chars;
|
||||
k = str->length;
|
||||
n = j + k + 2;
|
||||
t = JS_malloc(cx, (n + 1) * sizeof(jschar));
|
||||
if (!t)
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
for (i = 0; i < j; i++)
|
||||
t[i] = buf[i];
|
||||
t[i] = buf[i];
|
||||
for (j = 0; j < k; i++, j++)
|
||||
t[i] = s[j];
|
||||
t[i] = s[j];
|
||||
t[i++] = ')';
|
||||
t[i++] = ')';
|
||||
t[i] = 0;
|
||||
str = js_NewString(cx, t, n, 0);
|
||||
if (!str) {
|
||||
JS_free(cx, t);
|
||||
return JS_FALSE;
|
||||
JS_free(cx, t);
|
||||
return JS_FALSE;
|
||||
}
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
return JS_TRUE;
|
||||
@@ -464,7 +470,7 @@ str_substring(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
}
|
||||
|
||||
str = js_NewStringCopyN(cx, str->chars + (size_t)begin,
|
||||
(size_t)(end - begin), 0);
|
||||
(size_t)(end - begin), 0);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
}
|
||||
@@ -547,7 +553,7 @@ str_charAt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
if (d < 0 || str->length <= d) {
|
||||
*rval = JS_GetEmptyStringValue(cx);
|
||||
} else {
|
||||
index = (size_t)d;
|
||||
index = (size_t)d;
|
||||
buf[0] = str->chars[index];
|
||||
buf[1] = 0;
|
||||
str = js_NewStringCopyN(cx, buf, 1, 0);
|
||||
@@ -575,10 +581,10 @@ str_charCodeAt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
return JS_FALSE;
|
||||
d = js_DoubleToInteger(d);
|
||||
if (d < 0 || str->length <= d) {
|
||||
*rval = JS_GetNaNValue(cx);
|
||||
*rval = JS_GetNaNValue(cx);
|
||||
} else {
|
||||
index = (size_t)d;
|
||||
*rval = INT_TO_JSVAL((jsint)str->chars[index]);
|
||||
index = (size_t)d;
|
||||
*rval = INT_TO_JSVAL((jsint)str->chars[index]);
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
@@ -592,7 +598,7 @@ js_BoyerMooreHorspool(const jschar *text, jsint textlen,
|
||||
uint8 skip[BMH_CHARSET_SIZE];
|
||||
jschar c;
|
||||
|
||||
PR_ASSERT(0 < patlen && patlen <= BMH_PATLEN_MAX);
|
||||
JS_ASSERT(0 < patlen && patlen <= BMH_PATLEN_MAX);
|
||||
for (i = 0; i < BMH_CHARSET_SIZE; i++)
|
||||
skip[i] = (uint8)patlen;
|
||||
m = patlen - 1;
|
||||
@@ -640,13 +646,13 @@ str_indexOf(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
if (argc > 1) {
|
||||
if (!js_ValueToNumber(cx, argv[1], &d))
|
||||
return JS_FALSE;
|
||||
d = js_DoubleToInteger(d);
|
||||
d = js_DoubleToInteger(d);
|
||||
if (d < 0)
|
||||
i = 0;
|
||||
else if (d > textlen)
|
||||
i = textlen;
|
||||
else
|
||||
i = (jsint)d;
|
||||
else
|
||||
i = (jsint)d;
|
||||
} else {
|
||||
i = 0;
|
||||
}
|
||||
@@ -707,19 +713,19 @@ str_lastIndexOf(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
if (argc > 1) {
|
||||
if (!js_ValueToNumber(cx, argv[1], &d))
|
||||
return JS_FALSE;
|
||||
if (JSDOUBLE_IS_NaN(d)) {
|
||||
i = textlen;
|
||||
} else {
|
||||
d = js_DoubleToInteger(d);
|
||||
if (d < 0)
|
||||
i = 0;
|
||||
else if (d > textlen - patlen)
|
||||
i = textlen - patlen;
|
||||
else
|
||||
i = (jsint)d;
|
||||
}
|
||||
if (JSDOUBLE_IS_NaN(d)) {
|
||||
i = textlen;
|
||||
} else {
|
||||
d = js_DoubleToInteger(d);
|
||||
if (d < 0)
|
||||
i = 0;
|
||||
else if (d > textlen - patlen)
|
||||
i = textlen - patlen;
|
||||
else
|
||||
i = (jsint)d;
|
||||
}
|
||||
} else {
|
||||
i = textlen;
|
||||
i = textlen;
|
||||
}
|
||||
|
||||
if (patlen == 0) {
|
||||
@@ -748,8 +754,8 @@ str_lastIndexOf(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
static JSBool
|
||||
str_nyi(JSContext *cx, const char *what)
|
||||
{
|
||||
JS_ReportError(cx, "sorry, String.prototype.%s is not yet implemented",
|
||||
what);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_NO_STRING_PROTO, what);
|
||||
return JS_FALSE;
|
||||
}
|
||||
#endif
|
||||
@@ -791,7 +797,7 @@ match_or_replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
reobj = JSVAL_TO_OBJECT(argv[0]);
|
||||
re = JS_GetPrivate(cx, reobj);
|
||||
} else {
|
||||
src = js_ValueToString(cx, argv[0]);
|
||||
src = js_ValueToString(cx, argv[0]);
|
||||
if (!src)
|
||||
return JS_FALSE;
|
||||
if (data->optarg < argc) {
|
||||
@@ -832,7 +838,7 @@ match_or_replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
if (!ok)
|
||||
break;
|
||||
if (cx->regExpStatics.lastMatch.length == 0) {
|
||||
if (index == str->length)
|
||||
if (index == str->length)
|
||||
break;
|
||||
index++;
|
||||
}
|
||||
@@ -867,7 +873,7 @@ match_glob(JSContext *cx, jsint count, GlobData *data)
|
||||
mdata = (MatchData *)data;
|
||||
arrayobj = mdata->arrayobj;
|
||||
if (!arrayobj) {
|
||||
arrayobj = js_ConstructObject(cx, &js_ArrayClass, NULL, NULL);
|
||||
arrayobj = js_ConstructObject(cx, &js_ArrayClass, NULL, NULL);
|
||||
if (!arrayobj)
|
||||
return JS_FALSE;
|
||||
mdata->arrayobj = arrayobj;
|
||||
@@ -938,7 +944,7 @@ interpret_dollar(JSContext *cx, jschar *dp, ReplaceData *rdata, size_t *skip)
|
||||
JSString *str;
|
||||
|
||||
/* Allow a real backslash (literal "\\") to escape "$1" etc. */
|
||||
PR_ASSERT(*dp == '$');
|
||||
JS_ASSERT(*dp == '$');
|
||||
if (dp > rdata->repstr->chars && dp[-1] == '\\')
|
||||
return NULL;
|
||||
|
||||
@@ -1003,11 +1009,11 @@ find_replen(JSContext *cx, ReplaceData *rdata, size_t *sizep)
|
||||
|
||||
lambda = rdata->lambda;
|
||||
if (lambda) {
|
||||
uintN argc, i, j, m, n, p;
|
||||
jsval *sp, *oldsp, rval;
|
||||
void *mark;
|
||||
uintN argc, i, j, m, n, p;
|
||||
jsval *sp, *oldsp, rval;
|
||||
void *mark;
|
||||
JSStackFrame *fp;
|
||||
JSBool ok;
|
||||
JSBool ok;
|
||||
|
||||
/*
|
||||
* In the lambda case, not only do we find the replacement string's
|
||||
@@ -1017,8 +1023,8 @@ find_replen(JSContext *cx, ReplaceData *rdata, size_t *sizep)
|
||||
* For $&, etc., we must create string jsvals from cx->regExpStatics.
|
||||
* We grab up stack space to keep the newborn strings GC-rooted.
|
||||
*/
|
||||
p = rdata->base.regexp->parenCount;
|
||||
argc = 1 + p + 2;
|
||||
p = rdata->base.regexp->parenCount;
|
||||
argc = 1 + p + 2;
|
||||
sp = js_AllocStack(cx, 2 + argc, &mark);
|
||||
if (!sp)
|
||||
return JS_FALSE;
|
||||
@@ -1028,7 +1034,7 @@ find_replen(JSContext *cx, ReplaceData *rdata, size_t *sizep)
|
||||
*sp++ = OBJECT_TO_JSVAL(OBJ_GET_PARENT(cx, lambda));
|
||||
|
||||
#define PUSH_REGEXP_STATIC(sub) \
|
||||
PR_BEGIN_MACRO \
|
||||
JS_BEGIN_MACRO \
|
||||
JSString *str = js_NewStringCopyN(cx, \
|
||||
cx->regExpStatics.sub.chars, \
|
||||
cx->regExpStatics.sub.length, \
|
||||
@@ -1038,16 +1044,16 @@ find_replen(JSContext *cx, ReplaceData *rdata, size_t *sizep)
|
||||
goto lambda_out; \
|
||||
} \
|
||||
*sp++ = STRING_TO_JSVAL(str); \
|
||||
PR_END_MACRO
|
||||
JS_END_MACRO
|
||||
|
||||
/* Push $&, $1, $2, ... */
|
||||
/* Push $&, $1, $2, ... */
|
||||
PUSH_REGEXP_STATIC(lastMatch);
|
||||
i = 0;
|
||||
m = cx->regExpStatics.parenCount;
|
||||
n = PR_MIN(m, 9);
|
||||
for (j = 0; i < n; i++, j++)
|
||||
m = cx->regExpStatics.parenCount;
|
||||
n = JS_MIN(m, 9);
|
||||
for (j = 0; i < n; i++, j++)
|
||||
PUSH_REGEXP_STATIC(parens[j]);
|
||||
for (j = 0; i < m; i++, j++)
|
||||
for (j = 0; i < m; i++, j++)
|
||||
PUSH_REGEXP_STATIC(moreParens[j]);
|
||||
|
||||
#undef PUSH_REGEXP_STATIC
|
||||
@@ -1064,7 +1070,7 @@ find_replen(JSContext *cx, ReplaceData *rdata, size_t *sizep)
|
||||
fp = cx->fp;
|
||||
oldsp = fp->sp;
|
||||
fp->sp = sp;
|
||||
ok = js_Invoke(cx, argc, JS_FALSE);
|
||||
ok = js_Invoke(cx, argc, JS_FALSE);
|
||||
rval = fp->sp[-1];
|
||||
fp->sp = oldsp;
|
||||
|
||||
@@ -1076,7 +1082,7 @@ find_replen(JSContext *cx, ReplaceData *rdata, size_t *sizep)
|
||||
*/
|
||||
repstr = js_ValueToString(cx, rval);
|
||||
if (!repstr) {
|
||||
ok = JS_FALSE;
|
||||
ok = JS_FALSE;
|
||||
} else {
|
||||
rdata->repstr = repstr;
|
||||
*sizep = repstr->length;
|
||||
@@ -1085,7 +1091,7 @@ find_replen(JSContext *cx, ReplaceData *rdata, size_t *sizep)
|
||||
|
||||
lambda_out:
|
||||
js_FreeStack(cx, mark);
|
||||
return ok;
|
||||
return ok;
|
||||
}
|
||||
#endif /* JS_HAS_REPLACE_LAMBDA */
|
||||
|
||||
@@ -1145,7 +1151,7 @@ replace_glob(JSContext *cx, jsint count, GlobData *data)
|
||||
rdata->leftIndex = cx->regExpStatics.lastMatch.chars - str->chars;
|
||||
rdata->leftIndex += cx->regExpStatics.lastMatch.length;
|
||||
if (!find_replen(cx, rdata, &replen))
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
growth = leftlen + replen;
|
||||
chars = rdata->chars
|
||||
? JS_realloc(cx, rdata->chars, (rdata->length + growth + 1)
|
||||
@@ -1179,8 +1185,8 @@ str_replace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
|
||||
#if JS_HAS_REPLACE_LAMBDA
|
||||
if (JS_TypeOfValue(cx, argv[1]) == JSTYPE_FUNCTION) {
|
||||
lambda = JSVAL_TO_OBJECT(argv[1]);
|
||||
repstr = NULL;
|
||||
lambda = JSVAL_TO_OBJECT(argv[1]);
|
||||
repstr = NULL;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
@@ -1340,20 +1346,20 @@ find_split(JSContext *cx, JSString *str, JSRegExp *re, jsint *ip,
|
||||
* in match_or_replace.
|
||||
*/
|
||||
if (i == *ip) {
|
||||
/*
|
||||
* "Bump-along" to avoid sticking at an empty match, but don't
|
||||
* bump past end of string -- our caller must do that by adding
|
||||
* sep->length to our return value.
|
||||
*/
|
||||
if ((size_t)i == str->length) {
|
||||
/*
|
||||
* "Bump-along" to avoid sticking at an empty match, but don't
|
||||
* bump past end of string -- our caller must do that by adding
|
||||
* sep->length to our return value.
|
||||
*/
|
||||
if ((size_t)i == str->length) {
|
||||
sep->length = 1;
|
||||
return i;
|
||||
}
|
||||
i++;
|
||||
goto again;
|
||||
i++;
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
PR_ASSERT((size_t)i >= sep->length);
|
||||
JS_ASSERT((size_t)i >= sep->length);
|
||||
return i - sep->length;
|
||||
}
|
||||
#endif
|
||||
@@ -1438,19 +1444,19 @@ str_split(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
re = NULL;
|
||||
}
|
||||
|
||||
/* Use the second argument as the split limit, if given. */
|
||||
/* XXX our v2 ecma spec checks against given, undefined. */
|
||||
/* Use the second argument as the split limit, if given. */
|
||||
/* XXX our v2 ecma spec checks against given, undefined. */
|
||||
limited = (argc > 1);
|
||||
if (limited) {
|
||||
if (!js_ValueToNumber(cx, argv[1], &d))
|
||||
return JS_FALSE;
|
||||
|
||||
/* Clamp limit between 0 and 1 + string length. */
|
||||
d = js_DoubleToInteger(d);
|
||||
if (d < 0)
|
||||
d = 0;
|
||||
else if (d > str->length)
|
||||
d = 1 + str->length;
|
||||
/* Clamp limit between 0 and 1 + string length. */
|
||||
d = js_DoubleToInteger(d);
|
||||
if (d < 0)
|
||||
d = 0;
|
||||
else if (d > str->length)
|
||||
d = 1 + str->length;
|
||||
limit = (jsint)d;
|
||||
}
|
||||
|
||||
@@ -1561,7 +1567,7 @@ str_substr(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
}
|
||||
|
||||
str = js_NewStringCopyN(cx, str->chars + (size_t)begin,
|
||||
(size_t)(end - begin), 0);
|
||||
(size_t)(end - begin), 0);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
}
|
||||
@@ -1714,7 +1720,7 @@ str_slice(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
}
|
||||
|
||||
str = js_NewStringCopyN(cx, str->chars + (size_t)begin,
|
||||
(size_t)(end - begin), 0);
|
||||
(size_t)(end - begin), 0);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
}
|
||||
@@ -1776,7 +1782,7 @@ tagify(JSContext *cx, JSObject *obj, jsval *argv,
|
||||
for (i = 0; i < endlen; i++)
|
||||
tagbuf[j++] = (jschar)end[i];
|
||||
tagbuf[j++] = '>';
|
||||
PR_ASSERT(j == taglen);
|
||||
JS_ASSERT(j == taglen);
|
||||
|
||||
str = js_NewString(cx, tagbuf, taglen, 0);
|
||||
if (!str) {
|
||||
@@ -1984,7 +1990,7 @@ static JSFunctionSpec string_static_methods[] = {
|
||||
{0}
|
||||
};
|
||||
|
||||
static PRHashTable *deflated_string_cache;
|
||||
static JSHashTable *deflated_string_cache;
|
||||
static uint32 deflated_string_cache_bytes;
|
||||
#ifdef JS_THREADSAFE
|
||||
static JSLock *deflated_string_cache_lock;
|
||||
@@ -2008,7 +2014,7 @@ void
|
||||
js_FreeStringGlobals()
|
||||
{
|
||||
if (deflated_string_cache) {
|
||||
PR_HashTableDestroy(deflated_string_cache);
|
||||
JS_HashTableDestroy(deflated_string_cache);
|
||||
deflated_string_cache = NULL;
|
||||
}
|
||||
#ifdef JS_THREADSAFE
|
||||
@@ -2098,17 +2104,17 @@ js_NewStringCopyZ(JSContext *cx, const jschar *s, uintN gcflag)
|
||||
return str;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(PRHashNumber)
|
||||
STATIC_DLL_CALLBACK(JSHashNumber)
|
||||
js_hash_string_pointer(const void *key)
|
||||
{
|
||||
return (PRHashNumber)key >> JSVAL_TAGBITS;
|
||||
return (JSHashNumber)key >> JSVAL_TAGBITS;
|
||||
}
|
||||
|
||||
void
|
||||
js_FinalizeString(JSContext *cx, JSString *str)
|
||||
{
|
||||
PRHashNumber hash;
|
||||
PRHashEntry *he, **hep;
|
||||
JSHashNumber hash;
|
||||
JSHashEntry *he, **hep;
|
||||
|
||||
if (str->chars) {
|
||||
JS_free(cx, str->chars);
|
||||
@@ -2116,11 +2122,11 @@ js_FinalizeString(JSContext *cx, JSString *str)
|
||||
if (deflated_string_cache) {
|
||||
hash = js_hash_string_pointer(str);
|
||||
JS_ACQUIRE_LOCK(deflated_string_cache_lock);
|
||||
hep = PR_HashTableRawLookup(deflated_string_cache, hash, str);
|
||||
hep = JS_HashTableRawLookup(deflated_string_cache, hash, str);
|
||||
he = *hep;
|
||||
if (he) {
|
||||
JS_free(cx, he->value);
|
||||
PR_HashTableRawRemove(deflated_string_cache, hep, he);
|
||||
JS_HashTableRawRemove(deflated_string_cache, hep, he);
|
||||
deflated_string_cache_bytes -= str->length;
|
||||
}
|
||||
JS_RELEASE_LOCK(deflated_string_cache_lock);
|
||||
@@ -2181,10 +2187,10 @@ js_ValueToSource(JSContext *cx, jsval v)
|
||||
return js_ValueToString(cx, v);
|
||||
}
|
||||
|
||||
PRHashNumber
|
||||
JSHashNumber
|
||||
js_HashString(const JSString *str)
|
||||
{
|
||||
PRHashNumber h;
|
||||
JSHashNumber h;
|
||||
size_t n, m;
|
||||
const jschar *s;
|
||||
|
||||
@@ -2212,7 +2218,7 @@ js_CompareStrings(const JSString *str1, const JSString *str2)
|
||||
|
||||
l1 = str1->length, l2 = str2->length;
|
||||
s1 = str1->chars, s2 = str2->chars;
|
||||
n = PR_MIN(l1, l2);
|
||||
n = JS_MIN(l1, l2);
|
||||
for (i = 0; i < n; i++) {
|
||||
cmp = s1[i] - s2[i];
|
||||
if (cmp != 0)
|
||||
@@ -2247,7 +2253,7 @@ js_SkipWhiteSpace(const jschar *s)
|
||||
{
|
||||
/* JS_ISSPACE is false on a null. */
|
||||
while (JS_ISSPACE(*s))
|
||||
s++;
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -2295,15 +2301,15 @@ js_DeflateString(JSContext *cx, const jschar *chars, size_t length)
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static PRHashTable *
|
||||
static JSHashTable *
|
||||
GetDeflatedStringCache(void)
|
||||
{
|
||||
PRHashTable *cache;
|
||||
JSHashTable *cache;
|
||||
|
||||
cache = deflated_string_cache;
|
||||
if (!cache) {
|
||||
cache = PR_NewHashTable(8, js_hash_string_pointer,
|
||||
PR_CompareValues, PR_CompareValues,
|
||||
cache = JS_NewHashTable(8, js_hash_string_pointer,
|
||||
JS_CompareValues, JS_CompareValues,
|
||||
NULL, NULL);
|
||||
deflated_string_cache = cache;
|
||||
}
|
||||
@@ -2313,10 +2319,10 @@ GetDeflatedStringCache(void)
|
||||
JSBool
|
||||
js_SetStringBytes(JSString *str, char *bytes, size_t length)
|
||||
{
|
||||
PRHashTable *cache;
|
||||
JSHashTable *cache;
|
||||
JSBool ok;
|
||||
PRHashNumber hash;
|
||||
PRHashEntry **hep;
|
||||
JSHashNumber hash;
|
||||
JSHashEntry **hep;
|
||||
|
||||
JS_ACQUIRE_LOCK(deflated_string_cache_lock);
|
||||
|
||||
@@ -2325,9 +2331,9 @@ js_SetStringBytes(JSString *str, char *bytes, size_t length)
|
||||
ok = JS_FALSE;
|
||||
} else {
|
||||
hash = js_hash_string_pointer(str);
|
||||
hep = PR_HashTableRawLookup(cache, hash, str);
|
||||
PR_ASSERT(*hep == NULL);
|
||||
ok = PR_HashTableRawAdd(cache, hep, hash, str, bytes) != NULL;
|
||||
hep = JS_HashTableRawLookup(cache, hash, str);
|
||||
JS_ASSERT(*hep == NULL);
|
||||
ok = JS_HashTableRawAdd(cache, hep, hash, str, bytes) != NULL;
|
||||
if (ok)
|
||||
deflated_string_cache_bytes += length;
|
||||
}
|
||||
@@ -2339,10 +2345,10 @@ js_SetStringBytes(JSString *str, char *bytes, size_t length)
|
||||
char *
|
||||
js_GetStringBytes(JSString *str)
|
||||
{
|
||||
PRHashTable *cache;
|
||||
JSHashTable *cache;
|
||||
char *bytes;
|
||||
PRHashNumber hash;
|
||||
PRHashEntry *he, **hep;
|
||||
JSHashNumber hash;
|
||||
JSHashEntry *he, **hep;
|
||||
|
||||
JS_ACQUIRE_LOCK(deflated_string_cache_lock);
|
||||
|
||||
@@ -2351,14 +2357,14 @@ js_GetStringBytes(JSString *str)
|
||||
bytes = NULL;
|
||||
} else {
|
||||
hash = js_hash_string_pointer(str);
|
||||
hep = PR_HashTableRawLookup(cache, hash, str);
|
||||
hep = JS_HashTableRawLookup(cache, hash, str);
|
||||
he = *hep;
|
||||
if (he) {
|
||||
bytes = he->value;
|
||||
} else {
|
||||
bytes = js_DeflateString(NULL, str->chars, str->length);
|
||||
if (bytes) {
|
||||
if (PR_HashTableRawAdd(cache, hep, hash, str, bytes)) {
|
||||
if (JS_HashTableRawAdd(cache, hep, hash, str, bytes)) {
|
||||
deflated_string_cache_bytes += str->length;
|
||||
} else {
|
||||
free(bytes);
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#include "jspubtd.h"
|
||||
#include "jsprvtd.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
struct JSString {
|
||||
size_t length;
|
||||
@@ -191,11 +191,11 @@ js_ValueToString(JSContext *cx, jsval v);
|
||||
extern JSString *
|
||||
js_ValueToSource(JSContext *cx, jsval v);
|
||||
|
||||
#ifdef HT_ENUMERATE_NEXT /* XXX don't require prhash.h */
|
||||
#ifdef HT_ENUMERATE_NEXT /* XXX don't require jshash.h */
|
||||
/*
|
||||
* Compute a hash function from str.
|
||||
*/
|
||||
extern PRHashNumber
|
||||
extern JSHashNumber
|
||||
js_HashString(const JSString *str);
|
||||
#endif
|
||||
|
||||
@@ -263,6 +263,6 @@ js_SetStringBytes(JSString *str, char *bytes, size_t length);
|
||||
extern char *
|
||||
js_GetStringBytes(JSString *str);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsstr_h___ */
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
** File: prtypes.h
|
||||
** File: jstypes.h
|
||||
** Description: Definitions of NSPR's basic types
|
||||
**
|
||||
** Prototypes and macros used to make up for deficiencies in ANSI environments
|
||||
@@ -30,301 +30,301 @@
|
||||
** for all C files.
|
||||
**/
|
||||
|
||||
#ifndef prtypes_h___
|
||||
#define prtypes_h___
|
||||
|
||||
#include "prcpucfg.h"
|
||||
#ifndef jstypes_h___
|
||||
#define jstypes_h___
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/***********************************************************************
|
||||
** MACROS: PR_EXTERN
|
||||
** PR_IMPLEMENT
|
||||
** MACROS: EXTERN
|
||||
** IMPLEMENT
|
||||
** DESCRIPTION:
|
||||
** These are only for externally visible routines and globals. For
|
||||
** internal routines, just use "extern" for type checking and that
|
||||
** will not export internal cross-file or forward-declared symbols.
|
||||
** Define a macro for declaring procedures return types. We use this to
|
||||
** deal with windoze specific type hackery for DLL definitions. Use
|
||||
** PR_EXTERN when the prototype for the method is declared. Use
|
||||
** PR_IMPLEMENT for the implementation of the method.
|
||||
** EXTERN when the prototype for the method is declared. Use
|
||||
** IMPLEMENT for the implementation of the method.
|
||||
**
|
||||
** Example:
|
||||
** in dowhim.h
|
||||
** PR_EXTERN( void ) DoWhatIMean( void );
|
||||
** EXTERN( void ) DoWhatIMean( void );
|
||||
** in dowhim.c
|
||||
** PR_IMPLEMENT( void ) DoWhatIMean( void ) { return; }
|
||||
** IMPLEMENT( void ) DoWhatIMean( void ) { return; }
|
||||
**
|
||||
**
|
||||
***********************************************************************/
|
||||
#if defined(WIN32)
|
||||
#define PR_EXTERN(__type) extern _declspec(dllexport) __type
|
||||
#define PR_IMPLEMENT(__type) _declspec(dllexport) __type
|
||||
#define PR_EXTERN_DATA(__type) extern _declspec(dllexport) __type
|
||||
#define PR_IMPLEMENT_DATA(__type) _declspec(dllexport) __type
|
||||
#ifdef WIN32
|
||||
#define EXTERN(__type) extern _declspec(dllexport) __type
|
||||
#define IMPLEMENT(__type) _declspec(dllexport) __type
|
||||
#define EXTERN_DATA(__type) extern _declspec(dllexport) __type
|
||||
#define IMPLEMENT_DATA(__type) _declspec(dllexport) __type
|
||||
|
||||
#define PR_CALLBACK
|
||||
#define PR_CALLBACK_DECL
|
||||
#define PR_STATIC_CALLBACK(__x) static __x
|
||||
#define DLL_CALLBACK
|
||||
#define CALLBACK_DECL
|
||||
#define STATIC_DLL_CALLBACK(__x) static __x
|
||||
|
||||
#elif defined(WIN16)
|
||||
|
||||
#define PR_CALLBACK_DECL __cdecl
|
||||
#define CALLBACK_DECL __cdecl
|
||||
|
||||
#if defined(_WINDLL)
|
||||
#define PR_EXTERN(__type) extern __type _cdecl _export _loadds
|
||||
#define PR_IMPLEMENT(__type) __type _cdecl _export _loadds
|
||||
#define PR_EXTERN_DATA(__type) extern __type _export
|
||||
#define PR_IMPLEMENT_DATA(__type) __type _export
|
||||
#ifdef _WINDLL
|
||||
#define EXTERN(__type) extern __type _cdecl _export _loadds
|
||||
#define IMPLEMENT(__type) __type _cdecl _export _loadds
|
||||
#define EXTERN_DATA(__type) extern __type _export
|
||||
#define IMPLEMENT_DATA(__type) __type _export
|
||||
|
||||
#define PR_CALLBACK __cdecl __loadds
|
||||
#define PR_STATIC_CALLBACK(__x) static __x PR_CALLBACK
|
||||
#define DLL_CALLBACK __cdecl __loadds
|
||||
#define STATIC_DLL_CALLBACK(__x) static __x CALLBACK
|
||||
|
||||
#else /* this must be .EXE */
|
||||
#define PR_EXTERN(__type) extern __type _cdecl _export
|
||||
#define PR_IMPLEMENT(__type) __type _cdecl _export
|
||||
#define PR_EXTERN_DATA(__type) extern __type _export
|
||||
#define PR_IMPLEMENT_DATA(__type) __type _export
|
||||
#define EXTERN(__type) extern __type _cdecl _export
|
||||
#define IMPLEMENT(__type) __type _cdecl _export
|
||||
#define EXTERN_DATA(__type) extern __type _export
|
||||
#define IMPLEMENT_DATA(__type) __type _export
|
||||
|
||||
#define PR_CALLBACK __cdecl __loadds
|
||||
#define PR_STATIC_CALLBACK(__x) __x PR_CALLBACK
|
||||
#define DLL_CALLBACK __cdecl __loadds
|
||||
#define STATIC_DLL_CALLBACK(__x) __x DLL_CALLBACK
|
||||
#endif /* _WINDLL */
|
||||
|
||||
#elif defined(XP_MAC)
|
||||
#define PR_EXTERN(__type) extern __declspec(export) __type
|
||||
#define PR_IMPLEMENT(__type) __declspec(export) __type
|
||||
#define PR_EXTERN_DATA(__type) extern __declspec(export) __type
|
||||
#define PR_IMPLEMENT_DATA(__type) __declspec(export) __type
|
||||
#define EXTERN(__type) extern __declspec(export) __type
|
||||
#define IMPLEMENT(__type) __declspec(export) __type
|
||||
#define EXTERN_DATA(__type) extern __declspec(export) __type
|
||||
#define IMPLEMENT_DATA(__type) __declspec(export) __type
|
||||
|
||||
#define PR_CALLBACK
|
||||
#define PR_CALLBACK_DECL
|
||||
#define PR_STATIC_CALLBACK(__x) static __x
|
||||
#define DLL_CALLBACK
|
||||
#define CALLBACK_DECL
|
||||
#define STATIC_DLL_CALLBACK(__x) static __x
|
||||
|
||||
#elif defined(XP_OS2)
|
||||
#define PR_EXTERN(__type) extern __type
|
||||
#define PR_IMPLEMENT(__type) __type
|
||||
#define PR_EXTERN_DATA(__type) extern __type
|
||||
#define PR_IMPLEMENT_DATA(__type) __type
|
||||
#define PR_CALLBACK
|
||||
#define PR_CALLBACK_DECL
|
||||
#define PR_STATIC_CALLBACK(__x) __x _Optlink
|
||||
#define EXTERN(__type) extern __type
|
||||
#define IMPLEMENT(__type) __type
|
||||
#define EXTERN_DATA(__type) extern __type
|
||||
#define IMPLEMENT_DATA(__type) __type
|
||||
#define DLL_CALLBACK
|
||||
#define CALLBACK_DECL
|
||||
#define STATIC_DLL_CALLBACK(__x) __x _Optlink
|
||||
|
||||
#else /* Unix */
|
||||
#define PR_EXTERN(__type) extern __type
|
||||
#define PR_IMPLEMENT(__type) __type
|
||||
#define PR_EXTERN_DATA(__type) extern __type
|
||||
#define PR_IMPLEMENT_DATA(__type) __type
|
||||
#define PR_CALLBACK
|
||||
#define PR_CALLBACK_DECL
|
||||
#define PR_STATIC_CALLBACK(__x) static __x
|
||||
#define EXTERN(__type) extern __type
|
||||
#define IMPLEMENT(__type) __type
|
||||
#define EXTERN_DATA(__type) extern __type
|
||||
#define IMPLEMENT_DATA(__type) __type
|
||||
#define DLL_CALLBACK
|
||||
#define CALLBACK_DECL
|
||||
#define STATIC_DLL_CALLBACK(__x) static __x
|
||||
|
||||
#endif
|
||||
|
||||
#if !defined(NO_NSPR_10_SUPPORT)
|
||||
#define PR_PUBLIC_API PR_IMPLEMENT
|
||||
#ifndef NO_NSPR_10_SUPPORT
|
||||
#define PUBLIC_API IMPLEMENT
|
||||
#endif
|
||||
|
||||
/***********************************************************************
|
||||
** MACROS: PR_BEGIN_MACRO
|
||||
** PR_END_MACRO
|
||||
** MACROS: JS_BEGIN_MACRO
|
||||
** JS_END_MACRO
|
||||
** DESCRIPTION:
|
||||
** Macro body brackets so that macros with compound statement definitions
|
||||
** behave syntactically more like functions when called.
|
||||
***********************************************************************/
|
||||
#define PR_BEGIN_MACRO do {
|
||||
#define PR_END_MACRO } while (0)
|
||||
#define JS_BEGIN_MACRO do {
|
||||
#define JS_END_MACRO } while (0)
|
||||
|
||||
/***********************************************************************
|
||||
** MACROS: PR_BEGIN_EXTERN_C
|
||||
** PR_END_EXTERN_C
|
||||
** MACROS: JS_BEGIN_EXTERN_C
|
||||
** JS_END_EXTERN_C
|
||||
** DESCRIPTION:
|
||||
** Macro shorthands for conditional C++ extern block delimiters.
|
||||
***********************************************************************/
|
||||
#ifdef __cplusplus
|
||||
#define PR_BEGIN_EXTERN_C extern "C" {
|
||||
#define PR_END_EXTERN_C }
|
||||
#define JS_BEGIN_EXTERN_C extern "C" {
|
||||
#define JS_END_EXTERN_C }
|
||||
#else
|
||||
#define PR_BEGIN_EXTERN_C
|
||||
#define PR_END_EXTERN_C
|
||||
#define JS_BEGIN_EXTERN_C
|
||||
#define JS_END_EXTERN_C
|
||||
#endif
|
||||
|
||||
/***********************************************************************
|
||||
** MACROS: PR_BIT
|
||||
** PR_BITMASK
|
||||
** MACROS: JS_BIT
|
||||
** JS_BITMASK
|
||||
** DESCRIPTION:
|
||||
** Bit masking macros. XXX n must be <= 31 to be portable
|
||||
***********************************************************************/
|
||||
#define PR_BIT(n) ((PRUint32)1 << (n))
|
||||
#define PR_BITMASK(n) (PR_BIT(n) - 1)
|
||||
#define JS_BIT(n) ((JSUint32)1 << (n))
|
||||
#define JS_BITMASK(n) (JS_BIT(n) - 1)
|
||||
|
||||
/***********************************************************************
|
||||
** MACROS: PR_ROUNDUP
|
||||
** PR_MIN
|
||||
** PR_MAX
|
||||
** MACROS: JS_ROUNDUP
|
||||
** JS_MIN
|
||||
** JS_MAX
|
||||
** DESCRIPTION:
|
||||
** Commonly used macros for operations on compatible types.
|
||||
***********************************************************************/
|
||||
#define PR_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y))
|
||||
#define PR_MIN(x,y) ((x)<(y)?(x):(y))
|
||||
#define PR_MAX(x,y) ((x)>(y)?(x):(y))
|
||||
#define JS_ROUNDUP(x,y) ((((x)+((y)-1))/(y))*(y))
|
||||
#define JS_MIN(x,y) ((x)<(y)?(x):(y))
|
||||
#define JS_MAX(x,y) ((x)>(y)?(x):(y))
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
#include "jscpucfg.h"
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/************************************************************************
|
||||
** TYPES: PRUint8
|
||||
** PRInt8
|
||||
** TYPES: JSUint8
|
||||
** JSInt8
|
||||
** DESCRIPTION:
|
||||
** The int8 types are known to be 8 bits each. There is no type that
|
||||
** is equivalent to a plain "char".
|
||||
************************************************************************/
|
||||
#if PR_BYTES_PER_BYTE == 1
|
||||
typedef unsigned char PRUint8;
|
||||
typedef signed char PRInt8;
|
||||
#if JS_BYTES_PER_BYTE == 1
|
||||
typedef unsigned char JSUint8;
|
||||
typedef signed char JSInt8;
|
||||
#else
|
||||
#error No suitable type for PRInt8/PRUint8
|
||||
#error No suitable type for JSInt8/JSUint8
|
||||
#endif
|
||||
|
||||
/************************************************************************
|
||||
** TYPES: PRUint16
|
||||
** PRInt16
|
||||
** TYPES: JSUint16
|
||||
** JSInt16
|
||||
** DESCRIPTION:
|
||||
** The int16 types are known to be 16 bits each.
|
||||
************************************************************************/
|
||||
#if PR_BYTES_PER_SHORT == 2
|
||||
typedef unsigned short PRUint16;
|
||||
typedef short PRInt16;
|
||||
#if JS_BYTES_PER_SHORT == 2
|
||||
typedef unsigned short JSUint16;
|
||||
typedef short JSInt16;
|
||||
#else
|
||||
#error No suitable type for PRInt16/PRUint16
|
||||
#error No suitable type for JSInt16/JSUint16
|
||||
#endif
|
||||
|
||||
/************************************************************************
|
||||
** TYPES: PRUint32
|
||||
** PRInt32
|
||||
** TYPES: JSUint32
|
||||
** JSInt32
|
||||
** DESCRIPTION:
|
||||
** The int32 types are known to be 32 bits each.
|
||||
************************************************************************/
|
||||
#if PR_BYTES_PER_INT == 4
|
||||
typedef unsigned int PRUint32;
|
||||
typedef int PRInt32;
|
||||
#define PR_INT32(x) x
|
||||
#define PR_UINT32(x) x ## U
|
||||
#elif PR_BYTES_PER_LONG == 4
|
||||
typedef unsigned long PRUint32;
|
||||
typedef long PRInt32;
|
||||
#define PR_INT32(x) x ## L
|
||||
#define PR_UINT32(x) x ## UL
|
||||
#if JS_BYTES_PER_INT == 4
|
||||
typedef unsigned int JSUint32;
|
||||
typedef int JSInt32;
|
||||
#define JS_INT32(x) x
|
||||
#define JS_UINT32(x) x ## U
|
||||
#elif JS_BYTES_PER_LONG == 4
|
||||
typedef unsigned long JSUint32;
|
||||
typedef long JSInt32;
|
||||
#define JS_INT32(x) x ## L
|
||||
#define JS_UINT32(x) x ## UL
|
||||
#else
|
||||
#error No suitable type for PRInt32/PRUint32
|
||||
#error No suitable type for JSInt32/JSUint32
|
||||
#endif
|
||||
|
||||
/************************************************************************
|
||||
** TYPES: PRUint64
|
||||
** PRInt64
|
||||
** TYPES: JSUint64
|
||||
** JSInt64
|
||||
** DESCRIPTION:
|
||||
** The int64 types are known to be 64 bits each. Care must be used when
|
||||
** declaring variables of type PRUint64 or PRInt64. Different hardware
|
||||
** declaring variables of type JSUint64 or JSInt64. Different hardware
|
||||
** architectures and even different compilers have varying support for
|
||||
** 64 bit values. The only guaranteed portability requires the use of
|
||||
** the LL_ macros (see prlong.h).
|
||||
** the JSLL_ macros (see jslong.h).
|
||||
************************************************************************/
|
||||
#ifdef HAVE_LONG_LONG
|
||||
#if PR_BYTES_PER_LONG == 8
|
||||
typedef long PRInt64;
|
||||
typedef unsigned long PRUint64;
|
||||
#if JS_BYTES_PER_LONG == 8
|
||||
typedef long JSInt64;
|
||||
typedef unsigned long JSUint64;
|
||||
#elif defined(WIN16)
|
||||
typedef __int64 PRInt64;
|
||||
typedef unsigned __int64 PRUint64;
|
||||
typedef __int64 JSInt64;
|
||||
typedef unsigned __int64 JSUint64;
|
||||
#elif defined(WIN32)
|
||||
typedef __int64 PRInt64;
|
||||
typedef unsigned __int64 PRUint64;
|
||||
typedef __int64 JSInt64;
|
||||
typedef unsigned __int64 JSUint64;
|
||||
#else
|
||||
typedef long long PRInt64;
|
||||
typedef unsigned long long PRUint64;
|
||||
#endif /* PR_BYTES_PER_LONG == 8 */
|
||||
typedef long long JSInt64;
|
||||
typedef unsigned long long JSUint64;
|
||||
#endif /* JS_BYTES_PER_LONG == 8 */
|
||||
#else /* !HAVE_LONG_LONG */
|
||||
typedef struct {
|
||||
#ifdef IS_LITTLE_ENDIAN
|
||||
PRUint32 lo, hi;
|
||||
JSUint32 lo, hi;
|
||||
#else
|
||||
PRUint32 hi, lo;
|
||||
JSUint32 hi, lo;
|
||||
#endif
|
||||
} PRInt64;
|
||||
typedef PRInt64 PRUint64;
|
||||
} JSInt64;
|
||||
typedef JSInt64 JSUint64;
|
||||
#endif /* !HAVE_LONG_LONG */
|
||||
|
||||
/************************************************************************
|
||||
** TYPES: PRUintn
|
||||
** PRIntn
|
||||
** TYPES: JSUintn
|
||||
** JSIntn
|
||||
** DESCRIPTION:
|
||||
** The PRIntn types are most appropriate for automatic variables. They are
|
||||
** The JSIntn types are most appropriate for automatic variables. They are
|
||||
** guaranteed to be at least 16 bits, though various architectures may
|
||||
** define them to be wider (e.g., 32 or even 64 bits). These types are
|
||||
** never valid for fields of a structure.
|
||||
************************************************************************/
|
||||
#if PR_BYTES_PER_INT >= 2
|
||||
typedef int PRIntn;
|
||||
typedef unsigned int PRUintn;
|
||||
#if JS_BYTES_PER_INT >= 2
|
||||
typedef int JSIntn;
|
||||
typedef unsigned int JSUintn;
|
||||
#else
|
||||
#error 'sizeof(int)' not sufficient for platform use
|
||||
#endif
|
||||
|
||||
/************************************************************************
|
||||
** TYPES: PRFloat64
|
||||
** TYPES: JSFloat64
|
||||
** DESCRIPTION:
|
||||
** NSPR's floating point type is always 64 bits.
|
||||
************************************************************************/
|
||||
typedef double PRFloat64;
|
||||
typedef double JSFloat64;
|
||||
|
||||
/************************************************************************
|
||||
** TYPES: PRSize
|
||||
** TYPES: JSSize
|
||||
** DESCRIPTION:
|
||||
** A type for representing the size of objects.
|
||||
************************************************************************/
|
||||
typedef size_t PRSize;
|
||||
typedef size_t JSSize;
|
||||
|
||||
/************************************************************************
|
||||
** TYPES: PRPtrDiff
|
||||
** TYPES: JSPtrDiff
|
||||
** DESCRIPTION:
|
||||
** A type for pointer difference. Variables of this type are suitable
|
||||
** for storing a pointer or pointer sutraction.
|
||||
************************************************************************/
|
||||
typedef ptrdiff_t PRPtrdiff;
|
||||
typedef ptrdiff_t JSPtrdiff;
|
||||
|
||||
/************************************************************************
|
||||
** TYPES: PRUptrdiff
|
||||
** TYPES: JSUptrdiff
|
||||
** DESCRIPTION:
|
||||
** A type for pointer difference. Variables of this type are suitable
|
||||
** for storing a pointer or pointer sutraction.
|
||||
************************************************************************/
|
||||
typedef unsigned long PRUptrdiff;
|
||||
typedef unsigned long JSUptrdiff;
|
||||
|
||||
/************************************************************************
|
||||
** TYPES: PRBool
|
||||
** TYPES: JSBool
|
||||
** DESCRIPTION:
|
||||
** Use PRBool for variables and parameter types. Use PR_FALSE and PR_TRUE
|
||||
** Use JSBool for variables and parameter types. Use JS_FALSE and JS_TRUE
|
||||
** for clarity of target type in assignments and actual arguments. Use
|
||||
** 'if (bool)', 'while (!bool)', '(bool) ? x : y' etc., to test booleans
|
||||
** juast as you would C int-valued conditions.
|
||||
************************************************************************/
|
||||
typedef PRIntn PRBool;
|
||||
#define PR_TRUE (PRIntn)1
|
||||
#define PR_FALSE (PRIntn)0
|
||||
typedef JSIntn JSBool;
|
||||
#define JS_TRUE (JSIntn)1
|
||||
#define JS_FALSE (JSIntn)0
|
||||
|
||||
/************************************************************************
|
||||
** TYPES: PRPackedBool
|
||||
** TYPES: JSPackedBool
|
||||
** DESCRIPTION:
|
||||
** Use PRPackedBOol within structs where bitfields are not desireable
|
||||
** but minimum and consistant overhead matters.
|
||||
************************************************************************/
|
||||
typedef PRUint8 PRPackedBool;
|
||||
typedef JSUint8 JSPackedBool;
|
||||
|
||||
/*
|
||||
** Status code used by some routines that have a single point of failure or
|
||||
** special status return.
|
||||
*/
|
||||
typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
|
||||
typedef enum { JS_FAILURE = -1, JS_SUCCESS = 0 } JSStatus;
|
||||
|
||||
#if defined(NO_NSPR_10_SUPPORT)
|
||||
#ifdef NO_NSPR_10_SUPPORT
|
||||
#else
|
||||
/********* ???????????????? FIX ME ??????????????????????????? *****/
|
||||
/********************** Some old definitions until pr=>ds transition is done ***/
|
||||
@@ -359,24 +359,20 @@ typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
|
||||
#endif
|
||||
|
||||
/*
|
||||
** A PRWord is an integer that is the same size as a void*
|
||||
** A JSWord is an integer that is the same size as a void*
|
||||
*/
|
||||
typedef long PRWord;
|
||||
typedef unsigned long PRUword;
|
||||
typedef long JSWord;
|
||||
typedef unsigned long JSUword;
|
||||
|
||||
/********* ????????????? End Fix me ?????????????????????????????? *****/
|
||||
#endif /* NO_NSPR_10_SUPPORT */
|
||||
|
||||
#if defined(XP_MAC) || defined(MINI_NSPR)
|
||||
#include "protypes.h"
|
||||
#include "jsotypes.h"
|
||||
#ifndef NSPR20
|
||||
#define NSPR20 1
|
||||
#endif
|
||||
#else
|
||||
#include "obsolete/protypes.h"
|
||||
#endif
|
||||
|
||||
PR_END_EXTERN_C
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* prtypes_h___ */
|
||||
#endif /* jstypes_h___ */
|
||||
|
||||
45
mozilla/js/src/jsutil.c
Normal file
45
mozilla/js/src/jsutil.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
* PR assertion checker.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "jstypes.h"
|
||||
#include "jsutil.h"
|
||||
|
||||
#ifdef WIN32
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
IMPLEMENT(void) JS_Assert(const char *s, const char *file, JSIntn ln)
|
||||
{
|
||||
#if defined(XP_UNIX) || defined(XP_OS2)
|
||||
fprintf(stderr, "Assertion failure: %s, at %s:%d\n", s, file, ln);
|
||||
#endif
|
||||
#ifdef XP_MAC
|
||||
dprintf("Assertion failure: %s, at %s:%d\n", s, file, ln);
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
DebugBreak();
|
||||
#endif
|
||||
#ifndef XP_MAC
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
84
mozilla/js/src/jsutil.h
Normal file
84
mozilla/js/src/jsutil.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
* PR assertion checker.
|
||||
*/
|
||||
|
||||
#ifndef jsutil_h___
|
||||
#define jsutil_h___
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/***********************************************************************
|
||||
** FUNCTION: JS_MALLOC()
|
||||
** DESCRIPTION:
|
||||
** JS_NEW() allocates an untyped item of size _size from the heap.
|
||||
** INPUTS: _size: size in bytes of item to be allocated
|
||||
** OUTPUTS: untyped pointer to the node allocated
|
||||
** RETURN: pointer to node or error returned from malloc().
|
||||
***********************************************************************/
|
||||
#define JS_MALLOC(_bytes) (malloc((_bytes)))
|
||||
|
||||
/***********************************************************************
|
||||
** FUNCTION: JS_DELETE()
|
||||
** DESCRIPTION:
|
||||
** JS_DELETE() unallocates an object previosly allocated via JS_NEW()
|
||||
** or JS_NEWZAP() to the heap.
|
||||
** INPUTS: pointer to previously allocated object
|
||||
** OUTPUTS: the referenced object is returned to the heap
|
||||
** RETURN: void
|
||||
***********************************************************************/
|
||||
#define JS_DELETE(_ptr) { free(_ptr); (_ptr) = NULL; }
|
||||
|
||||
/***********************************************************************
|
||||
** FUNCTION: JS_NEW()
|
||||
** DESCRIPTION:
|
||||
** JS_NEW() allocates an item of type _struct from the heap.
|
||||
** INPUTS: _struct: a data type
|
||||
** OUTPUTS: pointer to _struct
|
||||
** RETURN: pointer to _struct or error returns from malloc().
|
||||
***********************************************************************/
|
||||
#define JS_NEW(_struct) ((_struct *) JS_MALLOC(sizeof(_struct)))
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
EXTERN(void) JS_Assert(const char *s, const char *file, JSIntn ln);
|
||||
#define JS_ASSERT(_expr) \
|
||||
((_expr)?((void)0):JS_Assert(# _expr,__FILE__,__LINE__))
|
||||
|
||||
#define JS_NOT_REACHED(_reasonStr) \
|
||||
JS_Assert(_reasonStr,__FILE__,__LINE__)
|
||||
|
||||
#else
|
||||
|
||||
#define JS_ASSERT(expr) ((void) 0)
|
||||
#define JS_NOT_REACHED(reasonStr)
|
||||
|
||||
#endif /* defined(DEBUG) */
|
||||
|
||||
/*
|
||||
** Abort the process in a non-graceful manner. This will cause a core file,
|
||||
** call to the debugger or other moral equivalent as well as causing the
|
||||
** entire process to stop.
|
||||
*/
|
||||
EXTERN(void) JS_Abort(void);
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsutil_h___ */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user