Compare commits
1 Commits
jsd
...
tags/Befor
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
280289bd3b |
@@ -1,24 +1,26 @@
|
||||
# Microsoft Developer Studio Project File - Name="xpcom" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Project File - Name="LiveConnect" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 5.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=xpcom - Win32 Debug
|
||||
CFG=LiveConnect - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "xpcom.mak".
|
||||
!MESSAGE NMAKE /f "LiveConnect.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "xpcom.mak" CFG="xpcom - Win32 Debug"
|
||||
!MESSAGE NMAKE /f "LiveConnect.mak" CFG="LiveConnect - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "xpcom - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "xpcom - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "LiveConnect - Win32 Release" (based on\
|
||||
"Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "LiveConnect - Win32 Debug" (based on\
|
||||
"Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
@@ -28,7 +30,7 @@ CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "xpcom - Win32 Release"
|
||||
!IF "$(CFG)" == "LiveConnect - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
@@ -39,9 +41,10 @@ RSC=rc.exe
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /Zi /O2 /I ".." /I "$(JDK)\include" /I "$(JDK)\include\win32" /D "NDEBUG" /D "XP_PC" /D "JSFILE" /D "WIN32" /D "_WINDOWS" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o NUL /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
@@ -51,9 +54,9 @@ BSC32=bscmake.exe
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ..\Release\js32.lib $(JDK)\lib\javai.lib /nologo /subsystem:windows /dll /debug /machine:I386
|
||||
|
||||
!ELSEIF "$(CFG)" == "xpcom - Win32 Debug"
|
||||
!ELSEIF "$(CFG)" == "LiveConnect - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
@@ -67,7 +70,7 @@ LINK32=link.exe
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "EXPORT_JS_API" /D "_WIN32" /D "WIN32" /D "_DEBUG" /D "DEBUG" /D "XP_PC" /D "_WINDOWS" /D "JSFILE" /D "JS_THREADSAFE" /D "NSPR20" /FR /YX /FD /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I ".." /I "$(JDK)\include" /I "$(JDK)\include\win32" /D "_DEBUG" /D "_CONSOLE" /D "DEBUG" /D "XP_PC" /D "JSFILE" /D "WIN32" /D "_WINDOWS" /FR /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o NUL /win32
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
@@ -77,65 +80,61 @@ BSC32=bscmake.exe
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib H:\trees\ns\dist\WINNT4.0_DBG.OBJ\lib\libnspr21.lib h:\trees\mozilla.org\mozilla\dist\WIN32_D.OBJ\lib\xpcom32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ..\Debug\js32.lib $(JDK)\lib\javai_g.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"Debug/LiveConnect_g.dll" /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "xpcom - Win32 Release"
|
||||
# Name "xpcom - Win32 Debug"
|
||||
# Name "LiveConnect - Win32 Release"
|
||||
# Name "LiveConnect - Win32 Debug"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsContext.cpp
|
||||
SOURCE=..\liveconnect\jsj.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsContext.h
|
||||
SOURCE=..\liveconnect\jsj_array.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsIContext.h
|
||||
SOURCE=..\liveconnect\jsj_class.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsIErrorReporter.h
|
||||
SOURCE=..\liveconnect\jsj_convert.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsIFunction.h
|
||||
SOURCE=..\liveconnect\jsj_field.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsIRuntime.h
|
||||
SOURCE=.\jsj_JavaArray.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsIScript.h
|
||||
SOURCE=.\jsj_JavaClass.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsIScriptable.cpp
|
||||
SOURCE=.\jsj_JavaObject.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsIScriptable.h
|
||||
SOURCE=.\jsj_JavaPackage.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsRuntime.cpp
|
||||
SOURCE=.\jsj_JSObject.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsRuntime.h
|
||||
SOURCE=..\liveconnect\jsj_method.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\JSWrapper.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\JSWrapper.h
|
||||
SOURCE=..\liveconnect\jsj_utils.c
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
106
mozilla/js/ref/liveconnect/LiveConnectShell.dsp
Normal file
106
mozilla/js/ref/liveconnect/LiveConnectShell.dsp
Normal file
@@ -0,0 +1,106 @@
|
||||
# Microsoft Developer Studio Project File - Name="LiveConnectShell" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 5.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=LiveConnectShell - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "LiveConnectShell.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "LiveConnectShell.mak" CFG="LiveConnectShell - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "LiveConnectShell - Win32 Release" (based on\
|
||||
"Win32 (x86) Console Application")
|
||||
!MESSAGE "LiveConnectShell - Win32 Debug" (based on\
|
||||
"Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "LiveConnectShell - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "LiveConnectShell_"
|
||||
# PROP BASE Intermediate_Dir "LiveConnectShell_"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "$(JDK)\include" /I "$(JDK)\include\win32" /I "." /D "_WIN32" /D "WIN32" /D "NDEBUG" /D "XP_PC" /D "_WINDOWS" /D "JSFILE" /D "LIVECONNECT" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"Release/lcshell.exe"
|
||||
# Begin Special Build Tool
|
||||
SOURCE=$(InputPath)
|
||||
PostBuild_Desc=Copy DLL(s) to build directory
|
||||
PostBuild_Cmds=COPY ..\Release\js32.dll .\Release
|
||||
# End Special Build Tool
|
||||
|
||||
!ELSEIF "$(CFG)" == "LiveConnectShell - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "LiveConnectShell0"
|
||||
# PROP BASE Intermediate_Dir "LiveConnectShell0"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "$(JDK)\include" /I "$(JDK)\include\win32" /I "." /D "LIVECONNECT" /D "_WIN32" /D "WIN32" /D "_DEBUG" /D "DEBUG" /D "XP_PC" /D "_WINDOWS" /D "JSFILE" /FR /YX /FD /c
|
||||
# SUBTRACT CPP /u
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"Debug/lcshell.exe" /pdbtype:sept
|
||||
# Begin Special Build Tool
|
||||
SOURCE=$(InputPath)
|
||||
PostBuild_Desc=Copy DLL(s) to build directory
|
||||
PostBuild_Cmds=COPY ..\Debug\js32.dll .\Debug
|
||||
# End Special Build Tool
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "LiveConnectShell - Win32 Release"
|
||||
# Name "LiveConnectShell - Win32 Debug"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\js.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Debug\js32.lib
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
@@ -3,7 +3,7 @@ Microsoft Developer Studio Workspace File, Format Version 5.00
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "js32"=.\js32.dsp - Package Owner=<4>
|
||||
Project: "LiveConnect"=.\LiveConnect.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
@@ -15,7 +15,7 @@ Package=<4>
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "jsshell"=.\js.dsp - Package Owner=<4>
|
||||
Project: "LiveConnectShell"=.\LiveConnectShell.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
@@ -24,24 +24,12 @@ Package=<5>
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name js32
|
||||
Project_Dep_Name LiveConnect
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "miniNSPR"=.\miniNSPR.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
301
mozilla/js/ref/liveconnect/README.html
Normal file
301
mozilla/js/ref/liveconnect/README.html
Normal file
@@ -0,0 +1,301 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
|
||||
<META NAME="Author" CONTENT="Scott Furman">
|
||||
<META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (WinNT; I) [Netscape]">
|
||||
<TITLE>README for LiveConnect</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
|
||||
<CENTER>
|
||||
<H2>
|
||||
<FONT COLOR="#CC0000"><FONT SIZE=+3>WARNING:</FONT></FONT></H2></CENTER>
|
||||
|
||||
<CENTER>
|
||||
<H2>
|
||||
<FONT COLOR="#CC0000">This document is a skeleton, still <BR>
|
||||
very much under construction.</FONT></H2></CENTER>
|
||||
|
||||
<H2>
|
||||
Introduction</H2>
|
||||
This is the README file for the JavaScript LiveConnect implementation.
|
||||
It consists of build conventions and instructions, source code conventions,
|
||||
a design walk-through, and a brief file-by-file description of the source.
|
||||
|
||||
<P>This document assumes basic familiarity with JSRef, the reference implementation
|
||||
of JavaScript, and with the LiveConnect technology (LiveConnect allows
|
||||
JavaScript and Java virtual machines to be connected. It enables
|
||||
JavaScript to access Java fields, invoke Java methods and makes it possible
|
||||
for Java to access JavaScript object properties and evaluate JavaScript.
|
||||
More information on LiveConnect can be found by searching the index on
|
||||
Netscape's <A HREF="http://developer.netscape.com">DevEdge site</A>.)
|
||||
|
||||
<P>JSRef builds a library or DLL containing the JavaScript runtime (compiler,
|
||||
interpreter, decompiler, garbage collector, atom manager, standard classes).
|
||||
The LiveConnect project/makefiles build a library that links both with
|
||||
JSRef and with a Java Virtual Machine (JVM) that implements the Java Native
|
||||
Interface (JNI), as specified by JavaSoft. It then compiles a small
|
||||
"shell" program and links that with the library to make an interpreter
|
||||
that can be used interactively and with test scripts.
|
||||
|
||||
<P><I>Scott Furman, 4/8/98</I>
|
||||
<H2>
|
||||
Build conventions</H2>
|
||||
Update your JVM's <TT><FONT SIZE=+1>CLASSPATH</FONT></TT> to point to the
|
||||
<TT><FONT SIZE=+1>liveconnect/classes</FONT></TT> subdirectory. If
|
||||
you do not, LiveConnect will still operate but with the limitation that
|
||||
JS objects may not be passed as arguments of Java methods and it will not
|
||||
be possible to call from Java into JavaScript, i.e. the <I>netscape.javascript.JSObject</I>
|
||||
class will be inaccessible. If your <TT><FONT SIZE=+1>CLASSPATH</FONT></TT>
|
||||
is set improperly, you will see a message like, "<TT><FONT SIZE=+1>initialization
|
||||
error: Can't load class netscape/javascript/JSObject</FONT></TT>" when
|
||||
starting a LiveConnect debug build.
|
||||
|
||||
<P>To enable multi-threaded execution, define the <TT><FONT SIZE=+1>JS_THREADSAFE</FONT></TT>
|
||||
cpp macro and flesh out the stubs and required headers in jslock.c/.h.
|
||||
See the JS API docs for more. JSRef must also be built with <TT><FONT SIZE=+1>JS_THREADSAFE</FONT></TT>.
|
||||
<BR>
|
||||
<UL><B>Windows</B>
|
||||
<UL>
|
||||
<LI>
|
||||
Use MSDEV5.0 with the <TT><FONT SIZE=+1>LiveConnectShell.dsw</FONT></TT>
|
||||
project file.</LI>
|
||||
|
||||
<LI>
|
||||
You must first build the JS runtime, js32.dll, by using the normal JSRef
|
||||
build procedure.</LI>
|
||||
|
||||
<LI>
|
||||
Identify the JVM that you are linking against by setting the <TT><FONT SIZE=+1>JDK</FONT></TT>
|
||||
environment variable to point to the top-level JDK directory, e.g. <TT><FONT SIZE=+1>D:\jdk1.1.5</FONT></TT>.
|
||||
This is used to establish paths for header file inclusion, linking and
|
||||
execution. If you are not using Sun's JVM, the project files may
|
||||
require manual tweaking to set these paths correctly.</LI>
|
||||
|
||||
<LI>
|
||||
The output files (DLLs and executables) are placed in the <TT><FONT SIZE=+1>js/ref/liveconnect/Debug</FONT></TT>
|
||||
or <TT><FONT SIZE=+1>js/ref/liveconnect/Release</FONT></TT> directories.</LI>
|
||||
|
||||
<LI>
|
||||
The LiveConnect-enabled shell is named <TT><FONT SIZE=+1>lcshell.exe</FONT></TT>
|
||||
and appears in the output directory.</LI>
|
||||
|
||||
<LI>
|
||||
You must have the JVM DLL in your <TT><FONT SIZE=+1>PATH</FONT></TT> environment
|
||||
variable in order to run. If you are using the Sun JDK, the DLL appears
|
||||
in the JDK's bin directory.<BR>
|
||||
<BR></LI>
|
||||
</UL>
|
||||
<B>Mac</B>
|
||||
<UL>
|
||||
<LI>
|
||||
<FONT COLOR="#FF0000">LiveConnect is known to build on the Mac, but no
|
||||
project files created yet</FONT></LI>
|
||||
|
||||
<LI>
|
||||
Use CodeWarrior 1.x (???.prj.hqx) or 2 (???.prj2.hqx).<BR>
|
||||
<BR></LI>
|
||||
</UL>
|
||||
<B>Unix</B>
|
||||
<UL>
|
||||
<LI>
|
||||
<FONT COLOR="#FF0000">No Makefiles created yet</FONT></LI>
|
||||
|
||||
<LI>
|
||||
Use vendor cc or gcc (ftp://prep.ai.mit.edu/pub/gnu) for compiling,
|
||||
and use gmake for building.</LI>
|
||||
|
||||
<LI>
|
||||
To compile optimized code, set BUILD_OPT=1 on the nmake/gmake command line
|
||||
or preset it in the environment or makefile. The C preprocessor macro
|
||||
DEBUG will be undefined, and NDEBUG (archaic Unix-ism for "No Debugging")
|
||||
will be defined. Without BUILD_OPT, DEBUG is predefined and NDEBUG
|
||||
is undefined.</LI>
|
||||
|
||||
<LI>
|
||||
Your own debug flag, DEBUG_$USER, will be defined or undefined as BUILD_OPT
|
||||
is unset or set.</LI>
|
||||
|
||||
<LI>
|
||||
To add C compiler options from the make command line, set XCFLAGS=-Dfoo.</LI>
|
||||
|
||||
<LI>
|
||||
To predefine -D or -U options in the makefile, set DEFINES.</LI>
|
||||
|
||||
<LI>
|
||||
To predefine -I options in the makefile, set INCLUDES.</LI>
|
||||
</UL>
|
||||
</UL>
|
||||
|
||||
<H2>
|
||||
Naming and coding conventions:</H2>
|
||||
|
||||
<UL>
|
||||
<LI>
|
||||
Public function names begin with JSJ_ followed by capitalized "intercaps",
|
||||
e.g. JSJ_ConnectToJavaVM.</LI>
|
||||
|
||||
<LI>
|
||||
Extern but library-private function names use a jsj_ prefix and mixed case,
|
||||
e.g. jsj_LookupSymbol.</LI>
|
||||
|
||||
<LI>
|
||||
Most static function names have unprefixed, underscore-separated names:
|
||||
get_char.</LI>
|
||||
|
||||
<LI>
|
||||
But static native methods of JS objects have intercaps names, e.g., JavaObject_getProperty().</LI>
|
||||
|
||||
<LI>
|
||||
And library-private and static data use underscores, not intercaps (but
|
||||
library-private data do use a js_ prefix).</LI>
|
||||
|
||||
<LI>
|
||||
Scalar type names are lowercase and js-prefixed: jsdouble.</LI>
|
||||
|
||||
<LI>
|
||||
Aggregate type names are JS-prefixed and mixed-case: JSObject.</LI>
|
||||
|
||||
<LI>
|
||||
Macros are generally ALL_CAPS and underscored, to call out potential side
|
||||
effects, multiple uses of a formal argument, etc.</LI>
|
||||
|
||||
<LI>
|
||||
Four spaces of indentation per statement nesting level. The files
|
||||
are space-filled, so adjusting of your tab setting should be unnecessary.</LI>
|
||||
|
||||
<LI>
|
||||
DLL entry points have their return type expanded within a PR_PUBLIC_API()
|
||||
macro call, to get the right Windows secret type qualifiers in the right
|
||||
places for both 16- and 32-bit builds.</LI>
|
||||
|
||||
<LI>
|
||||
Callback functions that might be called from a DLL are similarly macroized
|
||||
with PR_STATIC_CALLBACK (if the function otherwise would be static to hide
|
||||
its name) or PR_CALLBACK (this macro takes no type argument; it should
|
||||
be used after the return type and before the function name).</LI>
|
||||
</UL>
|
||||
|
||||
<H2>
|
||||
The LiveConnect API</H2>
|
||||
All public LiveConnect entry points and callbacks are documented in jsjava.h,
|
||||
the header file that exports those functions.
|
||||
<H2>
|
||||
Design walk-through</H2>
|
||||
|
||||
<BR>
|
||||
<H2>
|
||||
File walk-through</H2>
|
||||
|
||||
<TABLE BORDER=3 CELLSPACING=0 CELLPADDING=4 >
|
||||
<TR>
|
||||
<TD>jsjava.h</TD>
|
||||
|
||||
<TD>LiveConnect's only public header file. Defines all public API
|
||||
entry points, callbacks and types. </TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>jsj_private.h</TD>
|
||||
|
||||
<TD>LiveConnect internal header file for intra-module sharing of functions
|
||||
and types</TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>jsj.c</TD>
|
||||
|
||||
<TD>Public LiveConnect API entry points and initialization code</TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>jsj_array.c</TD>
|
||||
|
||||
<TD>Read and write elements of a Java array, performing needed conversions
|
||||
to/from JS types.</TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>jsj_class.c</TD>
|
||||
|
||||
<TD>Construct and manipulate JavaClassDescriptor structs, which are the
|
||||
native representation for Java classes. JavaClassDescriptors are
|
||||
used to describe the methods and fields of a class, including their type
|
||||
signatures, and include a reference to the peer <I>java.lang.Class</I>
|
||||
object. Since each Java object has a class, there is a JavaClassDescriptor
|
||||
associated with the JavaScript reflection of each Java Object.</TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>jsj_convert.c</TD>
|
||||
|
||||
<TD>Convert between Java and JavaScript values of all types, which may
|
||||
require calling routines in other files to wrap JS objects as Java objects
|
||||
and vice-versa.</TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>jsj_field.c</TD>
|
||||
|
||||
<TD>Reflect Java fields as properties of JavaObject objects and implement
|
||||
getter/setter access to those fields.</TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>jsj_JavaArray.c</TD>
|
||||
|
||||
<TD>Implementation of the JavaScript JavaArray class. Instances of
|
||||
JavaArray are used to reflect Java arrays.</TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>jsj_JavaClass.c</TD>
|
||||
|
||||
<TD>Implementation of the JavaScript JavaClass class. Instances
|
||||
of JavaClass are used to reflect Java classes.</TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>jsj_JavaObject.c</TD>
|
||||
|
||||
<TD>Implementation of the JavaScript JavaObject class. Instances
|
||||
of JavaObject are used to reflect Java objects, except for Java arrays,
|
||||
although some of the code in this file is used by the JavaArray code.</TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>jsj_JavaPackage.c</TD>
|
||||
|
||||
<TD>Implementation of the JavaScript JavaPackage class. Instances
|
||||
of JavaPackage are used to reflect Java packages. The JS properties
|
||||
of a JavaPackage are either nested JavaPackage objects or a JavaClass object.</TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>jsj_JSObject.c</TD>
|
||||
|
||||
<TD>Implementation of the native methods for the <I>netscape.javascript.JSObject</I>
|
||||
Java class, which are used for calling into JavaScript from Java.
|
||||
It also contains the code that wraps JS objects as instances of <I>netscape.javascript.JSObject
|
||||
</I>and the code that handles propagation of exceptions both into and out
|
||||
of Java.</TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>jsj_method.c</TD>
|
||||
|
||||
<TD>Reflect Java methods as properties of JavaObject objects and make it
|
||||
possible to invoke those methods. Includes overloaded method resolution
|
||||
and argument/return-value conversion code.</TD>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD>jsj_utils.c</TD>
|
||||
|
||||
<TD>Low-level utility code fo reporting errors, etc.</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
<BR>
|
||||
</BODY>
|
||||
</HTML>
|
||||
@@ -53,20 +53,14 @@ public final class JSObject {
|
||||
*/
|
||||
private static native void initClass();
|
||||
static {
|
||||
// On MRJ, this property won't exist, because the library is preloaded.
|
||||
String liveConnectLibrary = System.getProperty("netscape.jsj.dll", null);
|
||||
if (liveConnectLibrary != null) {
|
||||
System.loadLibrary(liveConnectLibrary);
|
||||
initClass();
|
||||
}
|
||||
System.loadLibrary("LiveConnect");
|
||||
initClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* it is illegal to construct a JSObject manually
|
||||
*/
|
||||
private JSObject(int jsobj_addr) {
|
||||
internal = jsobj_addr;
|
||||
}
|
||||
private JSObject(int jsobj_addr) {internal = jsobj_addr;}
|
||||
|
||||
/**
|
||||
* Retrieves a named member of a JavaScript object.
|
||||
@@ -134,17 +128,4 @@ public final class JSObject {
|
||||
* JavaScript object.
|
||||
*/
|
||||
protected native void finalize();
|
||||
|
||||
/**
|
||||
* Override java.lang.Object.equals() because identity is not preserved
|
||||
* with instances of JSObject.
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
JSObject jsobj;
|
||||
|
||||
if (!(obj instanceof JSObject))
|
||||
return false;
|
||||
jsobj = (JSObject)obj;
|
||||
return (internal == jsobj.internal);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
@@ -27,10 +27,16 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "prassert.h"
|
||||
#include "prprintf.h"
|
||||
|
||||
#include "jsj_private.h" /* LiveConnect internals */
|
||||
#include "jsjava.h" /* LiveConnect external API */
|
||||
|
||||
/* FIXME - The JNI environment should not be a global. It needs to be in thread-local storage. */
|
||||
JNIEnv *jENV;
|
||||
|
||||
/*
|
||||
* At certain times during initialization, there may be no JavaScript context
|
||||
* available to direct error reports to, in which case the error messages
|
||||
@@ -43,15 +49,13 @@ report_java_initialization_error(JNIEnv *jEnv, const char *js_error_msg)
|
||||
const char *error_msg, *java_error_msg;
|
||||
|
||||
java_error_msg = NULL;
|
||||
#if 0 /* This can never work here, because jsj_GetJavaErrorMessage relies on
|
||||
jlThrowable_toString which is set up by the initialization that calls
|
||||
this function. */
|
||||
|
||||
if (jEnv) {
|
||||
java_error_msg = jsj_GetJavaErrorMessage(jEnv);
|
||||
(*jEnv)->ExceptionClear(jEnv);
|
||||
}
|
||||
#endif
|
||||
if (java_error_msg) {
|
||||
|
||||
if (java_error_msg) {
|
||||
error_msg = PR_smprintf("initialization error: %s (%s)\n",
|
||||
js_error_msg, java_error_msg);
|
||||
free((void*)java_error_msg);
|
||||
@@ -65,7 +69,7 @@ report_java_initialization_error(JNIEnv *jEnv, const char *js_error_msg)
|
||||
|
||||
/*
|
||||
* Opaque JVM handles to Java classes and methods required for Java reflection.
|
||||
* These are computed and cached during initialization.
|
||||
* These are computed and cached at initialization.
|
||||
*/
|
||||
|
||||
jclass jlObject; /* java.lang.Object */
|
||||
@@ -129,7 +133,6 @@ jfieldID njJSException_filename; /* netscape.javascript.JSException.filen
|
||||
{ \
|
||||
jclass _##class = (*jEnv)->FindClass(jEnv, #qualified_name); \
|
||||
if (_##class == 0) { \
|
||||
(*jEnv)->ExceptionClear(jEnv); \
|
||||
report_java_initialization_error(jEnv, \
|
||||
"Can't load class " #qualified_name); \
|
||||
return JS_FALSE; \
|
||||
@@ -260,46 +263,8 @@ init_java_VM_reflection(JSJavaVM *jsjava_vm, JNIEnv *jEnv)
|
||||
|
||||
LOAD_FIELD_OBJ(java.lang.Void, TYPE, "Ljava/lang/Class;", jlVoid);
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
#if XP_MAC
|
||||
|
||||
/**
|
||||
* Workaround for the fact that MRJ loads a different instance of the shared library.
|
||||
*/
|
||||
|
||||
#include "netscape_javascript_JSObject.h"
|
||||
|
||||
static JSObject_RegisterNativeMethods(JNIEnv* jEnv)
|
||||
{
|
||||
// Manually load the required native methods.
|
||||
static JNINativeMethod nativeMethods[] = {
|
||||
"initClass", "()V", (void*)&Java_netscape_javascript_JSObject_initClass,
|
||||
"getMember", "(Ljava/lang/String;)Ljava/lang/Object;", (void*)&Java_netscape_javascript_JSObject_getMember,
|
||||
"getSlot", "(I)Ljava/lang/Object;", (void*)&Java_netscape_javascript_JSObject_getSlot,
|
||||
"setMember", "(Ljava/lang/String;Ljava/lang/Object;)V", (void*)&Java_netscape_javascript_JSObject_setMember,
|
||||
"setSlot", "(ILjava/lang/Object;)V", (void*)&Java_netscape_javascript_JSObject_setSlot,
|
||||
"removeMember", "(Ljava/lang/String;)V", (void*)&Java_netscape_javascript_JSObject_removeMember,
|
||||
"call", "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;", (void*)&Java_netscape_javascript_JSObject_call,
|
||||
"eval", "(Ljava/lang/String;)Ljava/lang/Object;", (void*)&Java_netscape_javascript_JSObject_eval,
|
||||
|
||||
"toString", "()Ljava/lang/String;", (void*)&Java_netscape_javascript_JSObject_toString,
|
||||
"getWindow", "(Ljava/applet/Applet;)Lnetscape/javascript/JSObject;", (void*)&Java_netscape_javascript_JSObject_getWindow,
|
||||
"finalize", "()V", (void*)&Java_netscape_javascript_JSObject_finalize,
|
||||
/* "equals", "(Ljava/lang/Object;)Z", (void*)&Java_netscape_javascript_JSObject_equals */
|
||||
};
|
||||
(*jEnv)->RegisterNatives(jEnv, njJSObject, nativeMethods, sizeof(nativeMethods) / sizeof(JNINativeMethod));
|
||||
if ((*jEnv)->ExceptionOccurred(jEnv)) {
|
||||
report_java_initialization_error(jEnv, "Couldn't initialize JSObject native methods.");
|
||||
(*jEnv)->ExceptionClear(jEnv);
|
||||
}
|
||||
/* call the initClass method, since we nailed the static initializer for testing. */
|
||||
Java_netscape_javascript_JSObject_initClass(jEnv, njJSObject);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Load Netscape-specific Java extension classes, methods, and fields */
|
||||
static JSBool
|
||||
init_netscape_java_classes(JSJavaVM *jsjava_vm, JNIEnv *jEnv)
|
||||
@@ -308,10 +273,6 @@ init_netscape_java_classes(JSJavaVM *jsjava_vm, JNIEnv *jEnv)
|
||||
LOAD_CLASS(netscape/javascript/JSException, njJSException);
|
||||
LOAD_CLASS(netscape/javascript/JSUtil, njJSUtil);
|
||||
|
||||
#if XP_MAC
|
||||
JSObject_RegisterNativeMethods(jEnv);
|
||||
#endif
|
||||
|
||||
LOAD_CONSTRUCTOR(netscape.javascript.JSObject,
|
||||
JSObject, "(I)V", njJSObject);
|
||||
LOAD_CONSTRUCTOR(netscape.javascript.JSException,
|
||||
@@ -344,16 +305,11 @@ JSJavaVM *jsjava_vm_list = NULL;
|
||||
* The classpath argument is ignored, however, if java_vm_arg is non-NULL.
|
||||
*/
|
||||
JSJavaVM *
|
||||
JSJ_ConnectToJavaVM(SystemJavaVM *java_vm_arg, void* initargs)
|
||||
JSJ_ConnectToJavaVM(JavaVM *java_vm_arg, const char *user_classpath)
|
||||
{
|
||||
SystemJavaVM* java_vm;
|
||||
JavaVM *java_vm;
|
||||
JSJavaVM *jsjava_vm;
|
||||
JNIEnv *jEnv;
|
||||
|
||||
PR_ASSERT(JSJ_callbacks);
|
||||
PR_ASSERT(JSJ_callbacks->attach_current_thread);
|
||||
PR_ASSERT(JSJ_callbacks->detach_current_thread);
|
||||
PR_ASSERT(JSJ_callbacks->get_java_vm);
|
||||
const char *full_classpath;
|
||||
|
||||
jsjava_vm = (JSJavaVM*)malloc(sizeof(JSJavaVM));
|
||||
if (!jsjava_vm)
|
||||
@@ -364,20 +320,31 @@ JSJ_ConnectToJavaVM(SystemJavaVM *java_vm_arg, void* initargs)
|
||||
|
||||
/* If a Java VM was passed in, try to attach to it on the current thread. */
|
||||
if (java_vm) {
|
||||
jEnv = JSJ_callbacks->attach_current_thread(java_vm);
|
||||
if (jEnv == NULL) {
|
||||
if ((*java_vm)->AttachCurrentThread(java_vm, &jENV, NULL) < 0) {
|
||||
jsj_LogError("Failed to attach to Java VM thread\n");
|
||||
free(jsjava_vm);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PRBool ok;
|
||||
PR_ASSERT(JSJ_callbacks->create_java_vm);
|
||||
PR_ASSERT(JSJ_callbacks->destroy_java_vm);
|
||||
} else {
|
||||
/* No Java VM supplied, so create our own */
|
||||
JDK1_1InitArgs vm_args;
|
||||
|
||||
/* Magic constant indicates JRE version 1.1 */
|
||||
vm_args.version = 0x00010001;
|
||||
JNI_GetDefaultJavaVMInitArgs(&vm_args);
|
||||
|
||||
/* Prepend the classpath argument to the default JVM classpath */
|
||||
if (user_classpath) {
|
||||
full_classpath = PR_smprintf("%s;%s", user_classpath, vm_args.classpath);
|
||||
if (!full_classpath) {
|
||||
free(jsjava_vm);
|
||||
return NULL;
|
||||
}
|
||||
vm_args.classpath = (char*)full_classpath;
|
||||
}
|
||||
|
||||
ok = JSJ_callbacks->create_java_vm(&java_vm, &jEnv, initargs);
|
||||
if (!ok || java_vm == NULL) {
|
||||
/* Attempt to create our own VM */
|
||||
if (JNI_CreateJavaVM(&java_vm, &jENV, &vm_args) < 0) {
|
||||
jsj_LogError("Failed to create Java VM\n");
|
||||
free(jsjava_vm);
|
||||
return NULL;
|
||||
@@ -386,13 +353,12 @@ JSJ_ConnectToJavaVM(SystemJavaVM *java_vm_arg, void* initargs)
|
||||
/* Remember that we created the VM so that we know to destroy it later */
|
||||
jsjava_vm->jsj_created_java_vm = JS_TRUE;
|
||||
}
|
||||
|
||||
jsjava_vm->java_vm = java_vm;
|
||||
jsjava_vm->main_thread_env = jEnv;
|
||||
jsjava_vm->main_thread_env = jENV;
|
||||
|
||||
/* Load the Java classes, and the method and field descriptors required for
|
||||
Java reflection. */
|
||||
if (!init_java_VM_reflection(jsjava_vm, jEnv)) {
|
||||
if (!init_java_VM_reflection(jsjava_vm, jENV)) {
|
||||
JSJ_DisconnectFromJavaVM(jsjava_vm);
|
||||
return NULL;
|
||||
}
|
||||
@@ -404,7 +370,7 @@ JSJ_ConnectToJavaVM(SystemJavaVM *java_vm_arg, void* initargs)
|
||||
* of failure, LiveConnect is still operative, but only when calling
|
||||
* from JS to Java and not vice-versa.
|
||||
*/
|
||||
init_netscape_java_classes(jsjava_vm, jEnv);
|
||||
init_netscape_java_classes(jsjava_vm, jENV);
|
||||
|
||||
/* Put this VM on the list of all created VMs */
|
||||
jsjava_vm->next = jsjava_vm_list;
|
||||
@@ -432,7 +398,6 @@ JSJ_Init(JSJCallbacks *callbacks)
|
||||
* and, more importantly, will avoid unnecessary network accesses if classes
|
||||
* are being loaded over the network.)
|
||||
*/
|
||||
JSBool
|
||||
JSJ_InitJSContext(JSContext *cx, JSObject *global_obj,
|
||||
JavaPackageDef *predefined_packages)
|
||||
{
|
||||
@@ -452,16 +417,13 @@ JSJ_InitJSContext(JSContext *cx, JSObject *global_obj,
|
||||
if (!jsj_init_JavaArray(cx, global_obj))
|
||||
return JS_FALSE;
|
||||
|
||||
if (!jsj_init_JavaMember(cx, global_obj))
|
||||
return JS_FALSE;
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/* Eliminate a reference to a Java class */
|
||||
/* Obtain a reference to a Java class */
|
||||
#define UNLOAD_CLASS(qualified_name, class) \
|
||||
if (class) { \
|
||||
(*jEnv)->DeleteGlobalRef(jEnv, class); \
|
||||
(*jENV)->DeleteGlobalRef(jENV, class); \
|
||||
class = NULL; \
|
||||
}
|
||||
|
||||
@@ -474,19 +436,11 @@ JSJ_InitJSContext(JSContext *cx, JSObject *global_obj,
|
||||
void
|
||||
JSJ_DisconnectFromJavaVM(JSJavaVM *jsjava_vm)
|
||||
{
|
||||
JNIEnv *jEnv;
|
||||
SystemJavaVM *java_vm;
|
||||
JSJavaVM *j, **jp;
|
||||
/* FIXME - Clean up the various hash tables */
|
||||
|
||||
java_vm = jsjava_vm->java_vm;
|
||||
jEnv = jsjava_vm->main_thread_env;
|
||||
|
||||
/* Drop all references to Java objects and classes */
|
||||
jsj_DiscardJavaObjReflections(jEnv);
|
||||
jsj_DiscardJavaClassReflections(jEnv);
|
||||
|
||||
if (jsjava_vm->jsj_created_java_vm) {
|
||||
(void)JSJ_callbacks->destroy_java_vm(java_vm, jEnv);
|
||||
if (jsjava_vm->jsj_created_java_vm) {
|
||||
JavaVM *java_vm = jsjava_vm->java_vm;
|
||||
(*java_vm)->DestroyJavaVM(java_vm);
|
||||
} else {
|
||||
UNLOAD_CLASS(java/lang/Object, jlObject);
|
||||
UNLOAD_CLASS(java/lang/Class, jlClass);
|
||||
@@ -503,18 +457,6 @@ JSJ_DisconnectFromJavaVM(JSJavaVM *jsjava_vm)
|
||||
UNLOAD_CLASS(netscape/javascript/JSException, njJSException);
|
||||
UNLOAD_CLASS(netscape/javascript/JSUtil, njJSUtil);
|
||||
}
|
||||
|
||||
|
||||
/* Remove this VM from the list of all JSJavaVM objects. */
|
||||
for (jp = &jsjava_vm_list; (j = *jp) != NULL; jp = &j->next) {
|
||||
if (j == jsjava_vm) {
|
||||
*jp = jsjava_vm->next;
|
||||
break;
|
||||
}
|
||||
}
|
||||
PR_ASSERT(j);
|
||||
|
||||
free(jsjava_vm);
|
||||
}
|
||||
|
||||
static JSJavaThreadState *thread_list = NULL;
|
||||
@@ -534,7 +476,7 @@ new_jsjava_thread_state(JSJavaVM *jsjava_vm, const char *thread_name, JNIEnv *jE
|
||||
if (thread_name)
|
||||
jsj_env->name = strdup(thread_name);
|
||||
|
||||
/* THREADSAFETY - need to protect against races */
|
||||
/* FIXME - need to protect against races */
|
||||
jsj_env->next = thread_list;
|
||||
thread_list = jsj_env;
|
||||
|
||||
@@ -547,11 +489,11 @@ find_jsjava_thread(JNIEnv *jEnv)
|
||||
JSJavaThreadState *e, **p, *jsj_env;
|
||||
jsj_env = NULL;
|
||||
|
||||
/* THREADSAFETY - need to protect against races in manipulating the thread list */
|
||||
/* FIXME - need to protect against races in manipulating the thread list */
|
||||
|
||||
/* Search for the thread state among the list of all created
|
||||
LiveConnect threads */
|
||||
for (p = &thread_list; (e = *p) != NULL; p = &(e->next)) {
|
||||
for (p=&thread_list; e = *p; p = &(e->next)) {
|
||||
if (e->jEnv == jEnv) {
|
||||
jsj_env = e;
|
||||
*p = jsj_env->next;
|
||||
@@ -566,17 +508,16 @@ find_jsjava_thread(JNIEnv *jEnv)
|
||||
return jsj_env;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(JSJavaThreadState *)
|
||||
PR_PUBLIC_API(JSJavaThreadState *)
|
||||
JSJ_AttachCurrentThreadToJava(JSJavaVM *jsjava_vm, const char *name, JNIEnv **java_envp)
|
||||
{
|
||||
JNIEnv *jEnv;
|
||||
SystemJavaVM *java_vm;
|
||||
JavaVM *java_vm;
|
||||
JSJavaThreadState *jsj_env;
|
||||
|
||||
/* Try to attach a Java thread to the current native thread */
|
||||
java_vm = jsjava_vm->java_vm;
|
||||
jEnv = JSJ_callbacks->attach_current_thread(java_vm);
|
||||
if (jEnv == NULL)
|
||||
if ((*java_vm)->AttachCurrentThread(java_vm, &jEnv, NULL) < 0)
|
||||
return NULL;
|
||||
|
||||
/* If we found an existing thread state, just return it. */
|
||||
@@ -593,7 +534,7 @@ JSJ_AttachCurrentThreadToJava(JSJavaVM *jsjava_vm, const char *name, JNIEnv **ja
|
||||
}
|
||||
|
||||
static JSJavaVM *
|
||||
map_java_vm_to_jsjava_vm(SystemJavaVM *java_vm)
|
||||
map_java_vm_to_jsjava_vm(JavaVM *java_vm)
|
||||
{
|
||||
JSJavaVM *v;
|
||||
for (v = jsjava_vm_list; v; v = v->next) {
|
||||
@@ -617,7 +558,7 @@ JSJavaThreadState *
|
||||
jsj_MapJavaThreadToJSJavaThreadState(JNIEnv *jEnv, char **errp)
|
||||
{
|
||||
JSJavaThreadState *jsj_env;
|
||||
SystemJavaVM *java_vm;
|
||||
JavaVM *java_vm;
|
||||
JSJavaVM *jsjava_vm;
|
||||
|
||||
/* If we found an existing thread state, just return it. */
|
||||
@@ -629,8 +570,7 @@ jsj_MapJavaThreadToJSJavaThreadState(JNIEnv *jEnv, char **errp)
|
||||
Invoke the callback to create one on-the-fly. */
|
||||
|
||||
/* First, figure out which Java VM is calling us */
|
||||
java_vm = JSJ_callbacks->get_java_vm(jEnv);
|
||||
if (jsjava_vm == NULL)
|
||||
if ((*jEnv)->GetJavaVM(jEnv, &java_vm) < 0)
|
||||
return NULL;
|
||||
|
||||
/* Get our private JavaVM data */
|
||||
@@ -657,7 +597,7 @@ jsj_MapJavaThreadToJSJavaThreadState(JNIEnv *jEnv, char **errp)
|
||||
* before Java is invoked on that thread.) The return value is the previous
|
||||
* context associated with the given Java thread.
|
||||
*/
|
||||
PR_IMPLEMENT(JSContext *)
|
||||
PR_PUBLIC_API(JSContext *)
|
||||
JSJ_SetDefaultJSContextForJavaThread(JSContext *cx, JSJavaThreadState *jsj_env)
|
||||
{
|
||||
JSContext *old_context;
|
||||
@@ -666,24 +606,22 @@ JSJ_SetDefaultJSContextForJavaThread(JSContext *cx, JSJavaThreadState *jsj_env)
|
||||
return old_context;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(JSBool)
|
||||
PR_PUBLIC_API(JSBool)
|
||||
JSJ_DetachCurrentThreadFromJava(JSJavaThreadState *jsj_env)
|
||||
{
|
||||
SystemJavaVM *java_vm;
|
||||
JNIEnv* jEnv;
|
||||
JavaVM *java_vm;
|
||||
JSJavaThreadState *e, **p;
|
||||
|
||||
/* Disassociate the current native thread from its corresponding Java thread */
|
||||
java_vm = jsj_env->jsjava_vm->java_vm;
|
||||
jEnv = jsj_env->jEnv;
|
||||
if (!JSJ_callbacks->detach_current_thread(java_vm, jEnv))
|
||||
if ((*java_vm)->DetachCurrentThread(java_vm) < 0)
|
||||
return JS_FALSE;
|
||||
|
||||
/* Destroy the LiveConnect execution environment passed in */
|
||||
jsj_ClearPendingJSErrors(jsj_env);
|
||||
|
||||
/* THREADSAFETY - need to protect against races */
|
||||
for (p = &thread_list; (e = *p) != NULL; p = &(e->next)) {
|
||||
/* FIXME - need to protect against races */
|
||||
for (p=&thread_list; e = *p; p = &(e->next)) {
|
||||
if (e == jsj_env) {
|
||||
*p = jsj_env->next;
|
||||
break;
|
||||
@@ -704,13 +642,11 @@ JSJ_ConvertJavaObjectToJSValue(JSContext *cx, jobject java_obj, jsval *vp)
|
||||
if (!jEnv)
|
||||
return JS_FALSE;
|
||||
|
||||
return jsj_ConvertJavaObjectToJSValue(cx, jEnv, java_obj, vp);
|
||||
jsj_ConvertJavaObjectToJSValue(cx, jEnv, java_obj, vp);
|
||||
}
|
||||
|
||||
/*===========================================================================*/
|
||||
|
||||
#ifndef MOZILLA_CLIENT
|
||||
|
||||
/* The convenience functions below present a complete, but simplified
|
||||
LiveConnect API which is designed to handle the special case of a single
|
||||
Java-VM, single-threaded operation, and use of only one JSContext. */
|
||||
@@ -731,96 +667,23 @@ default_map_js_context_to_jsj_thread(JSContext *cx, char **errp)
|
||||
|
||||
/* Trivial implementation of callback function */
|
||||
static JSContext *
|
||||
default_map_jsj_thread_to_js_context(JSJavaThreadState *jsj_env, JNIEnv *jEnv, char **errp)
|
||||
default_map_jsj_thread_to_js_context(JSJavaThreadState *jsj_env, char **errp)
|
||||
{
|
||||
return the_cx;
|
||||
}
|
||||
|
||||
/* Trivial implementation of callback function */
|
||||
static JSObject *
|
||||
JSObject *
|
||||
default_map_java_object_to_js_object(JNIEnv *jEnv, jobject hint, char **errp)
|
||||
{
|
||||
return the_global_js_obj;
|
||||
}
|
||||
|
||||
static PRBool PR_CALLBACK
|
||||
default_create_java_vm(SystemJavaVM* *jvm, JNIEnv* *initialEnv, void* initargs)
|
||||
{
|
||||
jint err;
|
||||
const char* user_classpath = (const char*)initargs;
|
||||
|
||||
/* No Java VM supplied, so create our own */
|
||||
JDK1_1InitArgs vm_args;
|
||||
|
||||
/* Magic constant indicates JRE version 1.1 */
|
||||
vm_args.version = 0x00010001;
|
||||
JNI_GetDefaultJavaVMInitArgs(&vm_args);
|
||||
|
||||
/* Prepend the classpath argument to the default JVM classpath */
|
||||
if (user_classpath) {
|
||||
#ifdef XP_UNIX
|
||||
const char *full_classpath = PR_smprintf("%s:%s", user_classpath, vm_args.classpath);
|
||||
#else
|
||||
const char *full_classpath = PR_smprintf("%s;%s", user_classpath, vm_args.classpath);
|
||||
#endif
|
||||
if (!full_classpath) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
vm_args.classpath = (char*)full_classpath;
|
||||
}
|
||||
|
||||
err = JNI_CreateJavaVM((JavaVM**)jvm, initialEnv, &vm_args);
|
||||
return err == 0;
|
||||
}
|
||||
|
||||
static PRBool PR_CALLBACK
|
||||
default_destroy_java_vm(SystemJavaVM* jvm, JNIEnv* initialEnv)
|
||||
{
|
||||
JavaVM* java_vm = (JavaVM*)jvm;
|
||||
jint err = (*java_vm)->DestroyJavaVM(java_vm);
|
||||
return err == 0;
|
||||
}
|
||||
|
||||
static JNIEnv* PR_CALLBACK
|
||||
default_attach_current_thread(SystemJavaVM* jvm)
|
||||
{
|
||||
JavaVM* java_vm = (JavaVM*)jvm;
|
||||
JNIEnv* env = NULL;
|
||||
jint err = (*java_vm)->AttachCurrentThread(java_vm, &env, NULL);
|
||||
return env;
|
||||
}
|
||||
|
||||
static PRBool PR_CALLBACK
|
||||
default_detach_current_thread(SystemJavaVM* jvm, JNIEnv* env)
|
||||
{
|
||||
JavaVM* java_vm = (JavaVM*)jvm;
|
||||
/* assert that env is the JNIEnv of the current thread */
|
||||
jint err = (*java_vm)->DetachCurrentThread(java_vm);
|
||||
return err == 0;
|
||||
}
|
||||
|
||||
static SystemJavaVM* PR_CALLBACK
|
||||
default_get_java_vm(JNIEnv* env)
|
||||
{
|
||||
JavaVM* java_vm = NULL;
|
||||
jint err = (*env)->GetJavaVM(env, &java_vm);
|
||||
return (SystemJavaVM*)java_vm;
|
||||
}
|
||||
|
||||
/* Trivial implementations of callback functions */
|
||||
JSJCallbacks jsj_default_callbacks = {
|
||||
default_map_jsj_thread_to_js_context,
|
||||
default_map_js_context_to_jsj_thread,
|
||||
default_map_java_object_to_js_object,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
default_create_java_vm,
|
||||
default_destroy_java_vm,
|
||||
default_attach_current_thread,
|
||||
default_detach_current_thread,
|
||||
default_get_java_vm
|
||||
default_map_java_object_to_js_object
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -831,12 +694,11 @@ JSJCallbacks jsj_default_callbacks = {
|
||||
* The classpath argument is ignored, however, if java_vm is non-NULL.
|
||||
*/
|
||||
JSBool
|
||||
JSJ_SimpleInit(JSContext *cx, JSObject *global_obj, SystemJavaVM *java_vm, const char *classpath)
|
||||
JSJ_SimpleInit(JSContext *cx, JSObject *global_obj, JavaVM *java_vm, const char *classpath)
|
||||
{
|
||||
JNIEnv *jEnv;
|
||||
|
||||
PR_ASSERT(!the_jsj_vm);
|
||||
the_jsj_vm = JSJ_ConnectToJavaVM(java_vm, (void*)classpath);
|
||||
|
||||
the_jsj_vm = JSJ_ConnectToJavaVM(java_vm, classpath);
|
||||
if (!the_jsj_vm)
|
||||
return JS_FALSE;
|
||||
|
||||
@@ -847,10 +709,10 @@ JSJ_SimpleInit(JSContext *cx, JSObject *global_obj, SystemJavaVM *java_vm, const
|
||||
the_cx = cx;
|
||||
the_global_js_obj = global_obj;
|
||||
|
||||
the_jsj_thread = JSJ_AttachCurrentThreadToJava(the_jsj_vm, "main thread", &jEnv);
|
||||
the_jsj_thread = JSJ_AttachCurrentThreadToJava(the_jsj_vm, "main thread", &jENV);
|
||||
if (!the_jsj_thread)
|
||||
goto error;
|
||||
JSJ_SetDefaultJSContextForJavaThread(cx, the_jsj_thread);
|
||||
|
||||
return JS_TRUE;
|
||||
|
||||
error:
|
||||
@@ -862,7 +724,7 @@ error:
|
||||
* Free up all LiveConnect resources. Destroy the Java VM if it was
|
||||
* created by LiveConnect.
|
||||
*/
|
||||
PR_IMPLEMENT(void)
|
||||
PR_PUBLIC_API(void)
|
||||
JSJ_SimpleShutdown()
|
||||
{
|
||||
PR_ASSERT(the_jsj_vm);
|
||||
@@ -873,4 +735,3 @@ JSJ_SimpleShutdown()
|
||||
the_jsj_thread = NULL;
|
||||
}
|
||||
|
||||
#endif /* MOZILLA_CLIENT */
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
@@ -28,12 +28,14 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prtypes.h"
|
||||
#include "prprintf.h"
|
||||
#include "prassert.h"
|
||||
|
||||
#include "jsj_private.h"
|
||||
#include "jsjava.h"
|
||||
|
||||
#include "jscntxt.h" /* For js_ReportErrorAgain().
|
||||
TODO - get rid of private header */
|
||||
#include "jscntxt.h" /* For js_ReportErrorAgain(). FIXME - get rid of private header */
|
||||
|
||||
#include "netscape_javascript_JSObject.h" /* javah-generated headers */
|
||||
|
||||
@@ -50,7 +52,6 @@ struct CapturedJSError {
|
||||
|
||||
/*********************** Reflection of JSObjects ****************************/
|
||||
|
||||
#ifdef PRESERVE_JSOBJECT_IDENTITY
|
||||
/*
|
||||
* This is a hash table that maps from JS objects to Java objects.
|
||||
* It is used to ensure that the same Java object results when a JS
|
||||
@@ -70,17 +71,11 @@ static PRHashTable *js_obj_reflections = NULL;
|
||||
* read/write or * write/write access.
|
||||
*/
|
||||
static PRMonitor *js_obj_reflections_monitor = NULL;
|
||||
#endif /* JS_THREADSAFE */
|
||||
#endif /* PRESERVE_JSOBJECT_IDENTITY */
|
||||
#endif
|
||||
|
||||
JSBool
|
||||
jsj_init_js_obj_reflections_table()
|
||||
static JSBool
|
||||
init_js_obj_reflections_table()
|
||||
{
|
||||
#ifdef PRESERVE_JSOBJECT_IDENTITY
|
||||
if(js_obj_reflections != NULL)
|
||||
{
|
||||
return JS_TRUE;
|
||||
}
|
||||
js_obj_reflections = PR_NewHashTable(128, NULL, PR_CompareValues,
|
||||
PR_CompareValues, NULL, NULL);
|
||||
if (!js_obj_reflections)
|
||||
@@ -92,8 +87,7 @@ jsj_init_js_obj_reflections_table()
|
||||
PR_HashTableDestroy(js_obj_reflections);
|
||||
return JS_FALSE;
|
||||
}
|
||||
#endif /* JS_THREADSAFE */
|
||||
#endif /* PRESERVE_JSOBJECT_IDENTITY */
|
||||
#endif
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
@@ -106,9 +100,6 @@ jsj_init_js_obj_reflections_table()
|
||||
*
|
||||
* If an error occurs, returns NULL and reports an error.
|
||||
*/
|
||||
|
||||
#ifdef PRESERVE_JSOBJECT_IDENTITY
|
||||
|
||||
jobject
|
||||
jsj_WrapJSObject(JSContext *cx, JNIEnv *jEnv, JSObject *js_obj)
|
||||
{
|
||||
@@ -123,15 +114,7 @@ jsj_WrapJSObject(JSContext *cx, JNIEnv *jEnv, JSObject *js_obj)
|
||||
|
||||
/* First, look in the hash table for an existing reflection of the same
|
||||
JavaScript object. If one is found, return it. */
|
||||
hep = PR_HashTableRawLookup(js_obj_reflections, (PRHashNumber)js_obj, js_obj);
|
||||
|
||||
/* If the same JSObject is reflected into Java more than once then we should
|
||||
return the same Java object, both for efficiency and so that the '=='
|
||||
operator works as expected in Java when comparing two JSObjects.
|
||||
However, it is not possible to hold a reference to a Java object without
|
||||
inhibiting GC of that object, at least not in a portable way, i.e.
|
||||
a weak reference. So, for now, JSObject identity is broken. */
|
||||
|
||||
hep = PR_HashTableRawLookup(js_obj_reflections, (prhashcode)js_obj, js_obj);
|
||||
he = *hep;
|
||||
if (he) {
|
||||
java_wrapper_obj = (jobject)he->value;
|
||||
@@ -142,14 +125,8 @@ jsj_WrapJSObject(JSContext *cx, JNIEnv *jEnv, JSObject *js_obj)
|
||||
|
||||
/* No existing reflection found, so create a new Java object that wraps
|
||||
the JavaScript object by storing its address in a private integer field. */
|
||||
#if 0
|
||||
java_wrapper_obj =
|
||||
(*jEnv)->NewObject(jEnv, njJSObject, njJSObject_JSObject, (jint)js_obj);
|
||||
#else
|
||||
if (JSJ_callbacks->get_java_wrapper != NULL) {
|
||||
java_wrapper_obj = JSJ_callbacks->get_java_wrapper(jEnv, (jint)js_obj);
|
||||
}
|
||||
#endif /*! OJI */
|
||||
if (!java_wrapper_obj) {
|
||||
jsj_UnexpectedJavaError(cx, jEnv, "Couldn't create new instance of "
|
||||
"netscape.javascript.JSObject");
|
||||
@@ -157,7 +134,7 @@ jsj_WrapJSObject(JSContext *cx, JNIEnv *jEnv, JSObject *js_obj)
|
||||
}
|
||||
|
||||
/* Add the new reflection to the hash table. */
|
||||
he = PR_HashTableRawAdd(js_obj_reflections, hep, (PRHashNumber)js_obj,
|
||||
he = PR_HashTableRawAdd(js_obj_reflections, hep, (prhashcode)js_obj,
|
||||
js_obj, java_wrapper_obj);
|
||||
if (he) {
|
||||
/* Tell the JavaScript GC about this object since the only reference
|
||||
@@ -169,14 +146,6 @@ jsj_WrapJSObject(JSContext *cx, JNIEnv *jEnv, JSObject *js_obj)
|
||||
java_wrapper_obj = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Release local reference to wrapper object, since some JVMs seem reticent
|
||||
* about collecting it otherwise.
|
||||
*/
|
||||
/* FIXME -- beard: this seems to make calls into Java with JSObject's fail. */
|
||||
/* We should really be creating a global ref if we are putting it in a hash table. */
|
||||
/* (*jEnv)->DeleteLocalRef(jEnv, java_wrapper_obj); */
|
||||
|
||||
done:
|
||||
#ifdef JS_THREADSAFE
|
||||
PR_ExitMonitor(js_obj_reflections_monitor);
|
||||
@@ -190,8 +159,8 @@ done:
|
||||
* to Java objects. This is called from the finalizer of an instance of
|
||||
* netscape.javascript.JSObject.
|
||||
*/
|
||||
JSBool
|
||||
jsj_remove_js_obj_reflection_from_hashtable(JSContext *cx, JSObject *js_obj)
|
||||
static JSBool
|
||||
remove_js_obj_reflection_from_hashtable(JSContext *cx, JSObject *js_obj)
|
||||
{
|
||||
PRHashEntry *he, **hep;
|
||||
JSBool success = JS_FALSE;
|
||||
@@ -201,7 +170,7 @@ jsj_remove_js_obj_reflection_from_hashtable(JSContext *cx, JSObject *js_obj)
|
||||
#endif
|
||||
|
||||
/* Get the hash-table entry for this wrapper object */
|
||||
hep = PR_HashTableRawLookup(js_obj_reflections, (PRHashNumber)js_obj, js_obj);
|
||||
hep = PR_HashTableRawLookup(js_obj_reflections, (prhashcode)js_obj, js_obj);
|
||||
he = *hep;
|
||||
|
||||
PR_ASSERT(he);
|
||||
@@ -220,70 +189,6 @@ jsj_remove_js_obj_reflection_from_hashtable(JSContext *cx, JSObject *js_obj)
|
||||
return success;
|
||||
}
|
||||
|
||||
#else /* !PRESERVE_JSOBJECT_IDENTITY */
|
||||
|
||||
/* This object provides is the "anchor" by which netscape.javscript.JSObject
|
||||
objects hold a reference to native JSObjects. */
|
||||
typedef struct JSObjectRoot {
|
||||
JSObject *js_obj;
|
||||
JSContext *cx; /* Creating context, needed for finalization */
|
||||
} JSObjectHandle;
|
||||
|
||||
/*
|
||||
* The caller must call DeleteLocalRef() on the returned object when no more
|
||||
* references remain.
|
||||
*/
|
||||
jobject
|
||||
jsj_WrapJSObject(JSContext *cx, JNIEnv *jEnv, JSObject *js_obj)
|
||||
{
|
||||
jobject java_wrapper_obj;
|
||||
JSObjectHandle *handle;
|
||||
|
||||
/* Create a tiny stub object to act as the GC root that points to the
|
||||
JSObject from its netscape.javascript.JSObject counterpart. */
|
||||
handle = (JSObjectHandle*)JS_malloc(cx, sizeof(JSObjectHandle));
|
||||
if (!handle)
|
||||
return NULL;
|
||||
handle->js_obj = js_obj;
|
||||
handle->cx = cx;
|
||||
|
||||
/* No existing reflection found, so create a new Java object that wraps
|
||||
the JavaScript object by storing its address in a private integer field. */
|
||||
#if 0
|
||||
java_wrapper_obj =
|
||||
(*jEnv)->NewObject(jEnv, njJSObject, njJSObject_JSObject, (jint)handle);
|
||||
#else
|
||||
if (JSJ_callbacks->get_java_wrapper != NULL) {
|
||||
java_wrapper_obj = JSJ_callbacks->get_java_wrapper(jEnv, (jint)js_obj);
|
||||
}
|
||||
#endif /*! OJI */
|
||||
if (!java_wrapper_obj) {
|
||||
jsj_UnexpectedJavaError(cx, jEnv, "Couldn't create new instance of "
|
||||
"netscape.javascript.JSObject");
|
||||
goto done;
|
||||
}
|
||||
|
||||
JS_AddRoot(cx, &handle->js_obj);
|
||||
|
||||
done:
|
||||
|
||||
return java_wrapper_obj;
|
||||
}
|
||||
|
||||
JSObject *
|
||||
jsj_UnwrapJSObjectWrapper(JNIEnv *jEnv, jobject java_wrapper_obj)
|
||||
{
|
||||
JSObjectHandle *handle;
|
||||
|
||||
handle = (JSObjectHandle*)((*jEnv)->GetIntField(jEnv, java_wrapper_obj, njJSObject_internal));
|
||||
PR_ASSERT(handle);
|
||||
if (!handle)
|
||||
return NULL;
|
||||
return handle->js_obj;
|
||||
}
|
||||
|
||||
#endif /* !PRESERVE_JSOBJECT_IDENTITY */
|
||||
|
||||
/*************** Handling of Java exceptions in JavaScript ******************/
|
||||
|
||||
/*
|
||||
@@ -484,15 +389,6 @@ throw_any_pending_js_error_as_a_java_exception(JSJavaThreadState *jsj_env)
|
||||
goto done;
|
||||
}
|
||||
|
||||
/*
|
||||
* Release local references to Java objects, since some JVMs seem reticent
|
||||
* about collecting them otherwise.
|
||||
*/
|
||||
(*jEnv)->DeleteLocalRef(jEnv, message_jstr);
|
||||
(*jEnv)->DeleteLocalRef(jEnv, filename_jstr);
|
||||
(*jEnv)->DeleteLocalRef(jEnv, linebuf_jstr);
|
||||
(*jEnv)->DeleteLocalRef(jEnv, java_exception);
|
||||
|
||||
goto done;
|
||||
|
||||
out_of_memory:
|
||||
@@ -586,11 +482,9 @@ done:
|
||||
*
|
||||
* Returns NULL on failure.
|
||||
*/
|
||||
|
||||
|
||||
JSJavaThreadState *
|
||||
jsj_enter_js(JNIEnv *jEnv, jobject java_wrapper_obj,
|
||||
JSContext **cxp, JSObject **js_objp, JavaToJSSavedState* saved_state)
|
||||
enter_js(JNIEnv *jEnv, jobject java_wrapper_obj,
|
||||
JSContext **cxp, JSObject **js_objp, JSErrorReporter *old_error_reporterp)
|
||||
{
|
||||
JSContext *cx;
|
||||
char *err_msg;
|
||||
@@ -602,19 +496,14 @@ jsj_enter_js(JNIEnv *jEnv, jobject java_wrapper_obj,
|
||||
|
||||
/* Invoke callback, presumably used to implement concurrency constraints */
|
||||
if (JSJ_callbacks->enter_js_from_java) {
|
||||
if (!JSJ_callbacks->enter_js_from_java(jEnv, &err_msg))
|
||||
if (!JSJ_callbacks->enter_js_from_java(&err_msg))
|
||||
goto entry_failure;
|
||||
}
|
||||
|
||||
/* Check the JSObject pointer in the wrapper object. */
|
||||
/* Check the JSObject pointer in the wrapper object for null while holding
|
||||
the JS lock to deal with shutdown issues. */
|
||||
if (js_objp) {
|
||||
|
||||
#ifdef PRESERVE_JSOBJECT_IDENTITY
|
||||
js_obj = (JSObject *)((*jEnv)->GetIntField(jEnv, java_wrapper_obj, njJSObject_internal));
|
||||
#else /* !PRESERVE_JSOBJECT_IDENTITY */
|
||||
js_obj = jsj_UnwrapJSObjectWrapper(jEnv, java_wrapper_obj);
|
||||
#endif /* PRESERVE_JSOBJECT_IDENTITY */
|
||||
|
||||
PR_ASSERT(js_obj);
|
||||
if (!js_obj)
|
||||
goto error;
|
||||
@@ -633,7 +522,7 @@ jsj_enter_js(JNIEnv *jEnv, jobject java_wrapper_obj,
|
||||
Java and back into JS. Invoke a callback to obtain/create a
|
||||
JSContext for us to use. */
|
||||
if (JSJ_callbacks->map_jsj_thread_to_js_context) {
|
||||
cx = JSJ_callbacks->map_jsj_thread_to_js_context(jsj_env, jEnv, &err_msg);
|
||||
cx = JSJ_callbacks->map_jsj_thread_to_js_context(jsj_env, &err_msg);
|
||||
if (!cx)
|
||||
goto error;
|
||||
} else {
|
||||
@@ -648,15 +537,15 @@ jsj_enter_js(JNIEnv *jEnv, jobject java_wrapper_obj,
|
||||
* Capture all JS error reports so that they can be thrown into the Java
|
||||
* caller as an instance of netscape.javascript.JSException.
|
||||
*/
|
||||
saved_state->error_reporter = JS_SetErrorReporter(cx, capture_js_error_reports_for_java);
|
||||
saved_state->java_jsj_env = jsj_SetJavaJSJEnv(jsj_env);
|
||||
*old_error_reporterp =
|
||||
JS_SetErrorReporter(cx, capture_js_error_reports_for_java);
|
||||
|
||||
return jsj_env;
|
||||
|
||||
error:
|
||||
/* Invoke callback, presumably used to implement concurrency constraints */
|
||||
if (JSJ_callbacks->exit_js)
|
||||
JSJ_callbacks->exit_js(jEnv);
|
||||
JSJ_callbacks->exit_js();
|
||||
|
||||
entry_failure:
|
||||
if (err_msg) {
|
||||
@@ -673,14 +562,13 @@ entry_failure:
|
||||
/*
|
||||
* This utility function is called just prior to returning into Java from JS.
|
||||
*/
|
||||
JSBool
|
||||
jsj_exit_js(JSContext *cx, JSJavaThreadState *jsj_env, JavaToJSSavedState* original_state)
|
||||
static JSBool
|
||||
exit_js(JSContext *cx, JSJavaThreadState *jsj_env, JSErrorReporter original_reporter)
|
||||
{
|
||||
JNIEnv *jEnv;
|
||||
|
||||
/* Restore the JS error reporter */
|
||||
JS_SetErrorReporter(cx, original_state->error_reporter);
|
||||
jsj_SetJavaJSJEnv(original_state->java_jsj_env);
|
||||
JS_SetErrorReporter(cx, original_reporter);
|
||||
|
||||
jEnv = jsj_env->jEnv;
|
||||
|
||||
@@ -702,15 +590,15 @@ jsj_exit_js(JSContext *cx, JSJavaThreadState *jsj_env, JavaToJSSavedState* origi
|
||||
|
||||
/* Invoke callback, presumably used to implement concurrency constraints */
|
||||
if (JSJ_callbacks->exit_js)
|
||||
JSJ_callbacks->exit_js(jEnv);
|
||||
JSJ_callbacks->exit_js();
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/* Get the JavaClassDescriptor that corresponds to java.lang.Object */
|
||||
JavaClassDescriptor *
|
||||
jsj_get_jlObject_descriptor(JSContext *cx, JNIEnv *jEnv)
|
||||
static JavaClassDescriptor *
|
||||
get_jlObject_descriptor(JSContext *cx, JNIEnv *jEnv)
|
||||
{
|
||||
/* The JavaClassDescriptor for java.lang.Object */
|
||||
static JavaClassDescriptor *jlObject_descriptor = NULL;
|
||||
@@ -722,10 +610,6 @@ jsj_get_jlObject_descriptor(JSContext *cx, JNIEnv *jEnv)
|
||||
|
||||
/****************** Implementation of methods of JSObject *******************/
|
||||
|
||||
#ifdef XP_MAC
|
||||
#pragma export on
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Class: netscape_javascript_JSObject
|
||||
* Method: initClass
|
||||
@@ -734,7 +618,7 @@ jsj_get_jlObject_descriptor(JSContext *cx, JNIEnv *jEnv)
|
||||
JNIEXPORT void JNICALL
|
||||
Java_netscape_javascript_JSObject_initClass(JNIEnv *jEnv, jclass java_class)
|
||||
{
|
||||
jsj_init_js_obj_reflections_table();
|
||||
init_js_obj_reflections_table();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -751,15 +635,14 @@ Java_netscape_javascript_JSObject_getMember(JNIEnv *jEnv,
|
||||
JSObject *js_obj;
|
||||
jsval js_val;
|
||||
int dummy_cost;
|
||||
JSBool dummy_bool;
|
||||
const jchar *property_name_ucs2;
|
||||
jsize property_name_len;
|
||||
JavaToJSSavedState saved_state;
|
||||
JSErrorReporter saved_reporter;
|
||||
jobject member;
|
||||
jboolean is_copy;
|
||||
JSJavaThreadState *jsj_env;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_state);
|
||||
jsj_env = enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_reporter);
|
||||
if (!jsj_env)
|
||||
return NULL;
|
||||
|
||||
@@ -781,13 +664,13 @@ Java_netscape_javascript_JSObject_getMember(JNIEnv *jEnv,
|
||||
if (!JS_GetUCProperty(cx, js_obj, property_name_ucs2, property_name_len, &js_val))
|
||||
goto done;
|
||||
|
||||
jsj_ConvertJSValueToJavaObject(cx, jEnv, js_val, jsj_get_jlObject_descriptor(cx, jEnv),
|
||||
&dummy_cost, &member, &dummy_bool);
|
||||
jsj_ConvertJSValueToJavaObject(cx, jEnv, js_val, get_jlObject_descriptor(cx, jEnv),
|
||||
&dummy_cost, &member);
|
||||
|
||||
done:
|
||||
if (property_name_ucs2)
|
||||
(*jEnv)->ReleaseStringChars(jEnv, property_name_jstr, property_name_ucs2);
|
||||
if (!jsj_exit_js(cx, jsj_env, &saved_state))
|
||||
if (!exit_js(cx, jsj_env, saved_reporter))
|
||||
return NULL;
|
||||
|
||||
return member;
|
||||
@@ -807,24 +690,23 @@ Java_netscape_javascript_JSObject_getSlot(JNIEnv *jEnv,
|
||||
JSObject *js_obj;
|
||||
jsval js_val;
|
||||
int dummy_cost;
|
||||
JSBool dummy_bool;
|
||||
JavaToJSSavedState saved_state;
|
||||
JSErrorReporter saved_reporter;
|
||||
jobject member;
|
||||
JSJavaThreadState *jsj_env;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_state);
|
||||
jsj_env = enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_reporter);
|
||||
if (!jsj_env)
|
||||
return NULL;
|
||||
|
||||
|
||||
if (!JS_GetElement(cx, js_obj, slot, &js_val))
|
||||
goto done;
|
||||
if (!jsj_ConvertJSValueToJavaObject(cx, jEnv, js_val, jsj_get_jlObject_descriptor(cx, jEnv),
|
||||
&dummy_cost, &member, &dummy_bool))
|
||||
if (!jsj_ConvertJSValueToJavaObject(cx, jEnv, js_val, get_jlObject_descriptor(cx, jEnv),
|
||||
&dummy_cost, &member))
|
||||
goto done;
|
||||
|
||||
done:
|
||||
if (!jsj_exit_js(cx, jsj_env, &saved_state))
|
||||
if (!exit_js(cx, jsj_env, saved_reporter))
|
||||
return NULL;
|
||||
|
||||
return member;
|
||||
@@ -846,11 +728,11 @@ Java_netscape_javascript_JSObject_setMember(JNIEnv *jEnv,
|
||||
jsval js_val;
|
||||
const jchar *property_name_ucs2;
|
||||
jsize property_name_len;
|
||||
JavaToJSSavedState saved_state;
|
||||
JSErrorReporter saved_reporter;
|
||||
jboolean is_copy;
|
||||
JSJavaThreadState *jsj_env;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_state);
|
||||
jsj_env = enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_reporter);
|
||||
if (!jsj_env)
|
||||
return;
|
||||
|
||||
@@ -860,6 +742,7 @@ Java_netscape_javascript_JSObject_setMember(JNIEnv *jEnv,
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* FIXME - can property watchers be used to avoid security checks ? */
|
||||
/* Get the Unicode string for the JS property name */
|
||||
property_name_ucs2 = (*jEnv)->GetStringChars(jEnv, property_name_jstr, &is_copy);
|
||||
if (!property_name_ucs2) {
|
||||
@@ -876,7 +759,7 @@ Java_netscape_javascript_JSObject_setMember(JNIEnv *jEnv,
|
||||
done:
|
||||
if (property_name_ucs2)
|
||||
(*jEnv)->ReleaseStringChars(jEnv, property_name_jstr, property_name_ucs2);
|
||||
jsj_exit_js(cx, jsj_env, &saved_state);
|
||||
exit_js(cx, jsj_env, saved_reporter);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -893,10 +776,10 @@ Java_netscape_javascript_JSObject_setSlot(JNIEnv *jEnv,
|
||||
JSContext *cx;
|
||||
JSObject *js_obj;
|
||||
jsval js_val;
|
||||
JavaToJSSavedState saved_state;
|
||||
JSErrorReporter saved_reporter;
|
||||
JSJavaThreadState *jsj_env;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_state);
|
||||
jsj_env = enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_reporter);
|
||||
if (!jsj_env)
|
||||
return;
|
||||
|
||||
@@ -905,7 +788,7 @@ Java_netscape_javascript_JSObject_setSlot(JNIEnv *jEnv,
|
||||
JS_SetElement(cx, js_obj, slot, &js_val);
|
||||
|
||||
done:
|
||||
jsj_exit_js(cx, jsj_env, &saved_state);
|
||||
exit_js(cx, jsj_env, saved_reporter);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -923,11 +806,11 @@ Java_netscape_javascript_JSObject_removeMember(JNIEnv *jEnv,
|
||||
jsval js_val;
|
||||
const jchar *property_name_ucs2;
|
||||
jsize property_name_len;
|
||||
JavaToJSSavedState saved_state;
|
||||
JSErrorReporter saved_reporter;
|
||||
jboolean is_copy;
|
||||
JSJavaThreadState *jsj_env;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_state);
|
||||
jsj_env = enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_reporter);
|
||||
if (!jsj_env)
|
||||
return;
|
||||
|
||||
@@ -948,7 +831,7 @@ Java_netscape_javascript_JSObject_removeMember(JNIEnv *jEnv,
|
||||
(*jEnv)->ReleaseStringChars(jEnv, property_name_jstr, property_name_ucs2);
|
||||
|
||||
done:
|
||||
jsj_exit_js(cx, jsj_env, &saved_state);
|
||||
exit_js(cx, jsj_env, saved_reporter);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -967,15 +850,14 @@ Java_netscape_javascript_JSObject_call(JNIEnv *jEnv, jobject java_wrapper_obj,
|
||||
JSObject *js_obj;
|
||||
jsval js_val, function_val;
|
||||
int dummy_cost;
|
||||
JSBool dummy_bool;
|
||||
const jchar *function_name_ucs2;
|
||||
jsize function_name_len;
|
||||
JavaToJSSavedState saved_state;
|
||||
JSErrorReporter saved_reporter;
|
||||
jboolean is_copy;
|
||||
jobject result;
|
||||
JSJavaThreadState *jsj_env;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_state);
|
||||
jsj_env = enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_reporter);
|
||||
if (!jsj_env)
|
||||
return NULL;
|
||||
|
||||
@@ -1021,8 +903,8 @@ Java_netscape_javascript_JSObject_call(JNIEnv *jEnv, jobject java_wrapper_obj,
|
||||
if (!JS_CallFunctionValue(cx, js_obj, function_val, argc, argv, &js_val))
|
||||
goto cleanup_argv;
|
||||
|
||||
jsj_ConvertJSValueToJavaObject(cx, jEnv, js_val, jsj_get_jlObject_descriptor(cx, jEnv),
|
||||
&dummy_cost, &result, &dummy_bool);
|
||||
jsj_ConvertJSValueToJavaObject(cx, jEnv, js_val, get_jlObject_descriptor(cx, jEnv),
|
||||
&dummy_cost, &result);
|
||||
|
||||
cleanup_argv:
|
||||
if (argv) {
|
||||
@@ -1034,7 +916,7 @@ cleanup_argv:
|
||||
done:
|
||||
if (function_name_ucs2)
|
||||
(*jEnv)->ReleaseStringChars(jEnv, function_name_jstr, function_name_ucs2);
|
||||
if (!jsj_exit_js(cx, jsj_env, &saved_state))
|
||||
if (!exit_js(cx, jsj_env, saved_reporter))
|
||||
return NULL;
|
||||
|
||||
return result;
|
||||
@@ -1057,15 +939,14 @@ Java_netscape_javascript_JSObject_eval(JNIEnv *jEnv,
|
||||
JSObject *js_obj;
|
||||
jsval js_val;
|
||||
int dummy_cost;
|
||||
JSBool dummy_bool;
|
||||
const jchar *eval_ucs2;
|
||||
jsize eval_len;
|
||||
JavaToJSSavedState saved_state;
|
||||
JSErrorReporter saved_reporter;
|
||||
jboolean is_copy;
|
||||
jobject result;
|
||||
JSJavaThreadState *jsj_env;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_state);
|
||||
jsj_env = enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_reporter);
|
||||
if (!jsj_env)
|
||||
return NULL;
|
||||
|
||||
@@ -1087,7 +968,7 @@ Java_netscape_javascript_JSObject_eval(JNIEnv *jEnv,
|
||||
/* Set up security stuff */
|
||||
principals = NULL;
|
||||
if (JSJ_callbacks->get_JSPrincipals_from_java_caller)
|
||||
principals = JSJ_callbacks->get_JSPrincipals_from_java_caller(jEnv, cx);
|
||||
principals = JSJ_callbacks->get_JSPrincipals_from_java_caller(jEnv);
|
||||
codebase = principals ? principals->codebase : NULL;
|
||||
|
||||
/* Have the JS engine evaluate the unicode string */
|
||||
@@ -1098,13 +979,13 @@ Java_netscape_javascript_JSObject_eval(JNIEnv *jEnv,
|
||||
goto done;
|
||||
|
||||
/* Convert result to a subclass of java.lang.Object */
|
||||
jsj_ConvertJSValueToJavaObject(cx, jEnv, js_val, jsj_get_jlObject_descriptor(cx, jEnv),
|
||||
&dummy_cost, &result, &dummy_bool);
|
||||
jsj_ConvertJSValueToJavaObject(cx, jEnv, js_val, get_jlObject_descriptor(cx, jEnv),
|
||||
&dummy_cost, &result);
|
||||
|
||||
done:
|
||||
if (eval_ucs2)
|
||||
(*jEnv)->ReleaseStringChars(jEnv, eval_jstr, eval_ucs2);
|
||||
if (!jsj_exit_js(cx, jsj_env, &saved_state))
|
||||
if (!exit_js(cx, jsj_env, saved_reporter))
|
||||
return NULL;
|
||||
|
||||
return result;
|
||||
@@ -1123,10 +1004,10 @@ Java_netscape_javascript_JSObject_toString(JNIEnv *jEnv,
|
||||
JSContext *cx;
|
||||
JSObject *js_obj;
|
||||
JSString *jsstr;
|
||||
JavaToJSSavedState saved_state;
|
||||
JSErrorReporter saved_reporter;
|
||||
JSJavaThreadState *jsj_env;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_state);
|
||||
jsj_env = enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_reporter);
|
||||
if (!jsj_env)
|
||||
return NULL;
|
||||
|
||||
@@ -1137,7 +1018,7 @@ Java_netscape_javascript_JSObject_toString(JNIEnv *jEnv,
|
||||
if (!result)
|
||||
result = (*jEnv)->NewStringUTF(jEnv, "*JavaObject*");
|
||||
|
||||
if (!jsj_exit_js(cx, jsj_env, &saved_state))
|
||||
if (!exit_js(cx, jsj_env, saved_reporter))
|
||||
return NULL;
|
||||
|
||||
return result;
|
||||
@@ -1158,12 +1039,11 @@ Java_netscape_javascript_JSObject_getWindow(JNIEnv *jEnv,
|
||||
JSObject *js_obj;
|
||||
jsval js_val;
|
||||
int dummy_cost;
|
||||
JSBool dummy_bool;
|
||||
JavaToJSSavedState saved_state;
|
||||
JSErrorReporter saved_reporter;
|
||||
jobject java_obj;
|
||||
JSJavaThreadState *jsj_env;
|
||||
|
||||
jsj_env = jsj_enter_js(jEnv, NULL, &cx, NULL, &saved_state);
|
||||
jsj_env = enter_js(jEnv, NULL, &cx, NULL, &saved_reporter);
|
||||
if (!jsj_env)
|
||||
return NULL;
|
||||
|
||||
@@ -1178,10 +1058,10 @@ Java_netscape_javascript_JSObject_getWindow(JNIEnv *jEnv,
|
||||
goto done;
|
||||
}
|
||||
js_val = OBJECT_TO_JSVAL(js_obj);
|
||||
jsj_ConvertJSValueToJavaObject(cx, jEnv, js_val, jsj_get_jlObject_descriptor(cx, jEnv),
|
||||
&dummy_cost, &java_obj, &dummy_bool);
|
||||
jsj_ConvertJSValueToJavaObject(cx, jEnv, js_val, get_jlObject_descriptor(cx, jEnv),
|
||||
&dummy_cost, &java_obj);
|
||||
done:
|
||||
if (!jsj_exit_js(cx, jsj_env, &saved_state))
|
||||
if (!exit_js(cx, jsj_env, saved_reporter))
|
||||
return NULL;
|
||||
|
||||
return java_obj;
|
||||
@@ -1195,49 +1075,15 @@ done:
|
||||
JNIEXPORT void JNICALL
|
||||
Java_netscape_javascript_JSObject_finalize(JNIEnv *jEnv, jobject java_wrapper_obj)
|
||||
{
|
||||
JSBool success;
|
||||
JSContext *cx;
|
||||
JSObjectHandle *handle;
|
||||
|
||||
success = JS_FALSE;
|
||||
|
||||
handle = (JSObjectHandle *)((*jEnv)->GetIntField(jEnv, java_wrapper_obj, njJSObject_internal));
|
||||
PR_ASSERT(handle);
|
||||
if (!handle)
|
||||
JSErrorReporter saved_reporter;
|
||||
JSJavaThreadState *jsj_env;
|
||||
JSObject *js_obj;
|
||||
|
||||
jsj_env = enter_js(jEnv, java_wrapper_obj, &cx, &js_obj, &saved_reporter);
|
||||
if (!jsj_env) /* Note: memory leak if we exit here */
|
||||
return;
|
||||
cx = handle->cx;
|
||||
|
||||
success = JS_RemoveRoot(cx, &handle->js_obj);
|
||||
JS_free(cx, handle);
|
||||
|
||||
PR_ASSERT(success);
|
||||
remove_js_obj_reflection_from_hashtable(cx, js_obj);
|
||||
exit_js(cx, jsj_env, saved_reporter);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: netscape_javascript_JSObject
|
||||
* Method: equals
|
||||
* Signature: (Ljava/lang/Object;)Z
|
||||
*/
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_netscape_javascript_JSObject_equals(JNIEnv *jEnv,
|
||||
jobject java_wrapper_obj,
|
||||
jobject comparison_obj)
|
||||
{
|
||||
#ifdef PRESERVE_JSOBJECT_IDENTITY
|
||||
# error "Missing code should be added here"
|
||||
#else
|
||||
JSObject *js_obj1, *js_obj2;
|
||||
|
||||
/* Check that we're comparing with another netscape.javascript.JSObject */
|
||||
if (!comparison_obj)
|
||||
return 0;
|
||||
if (!(*jEnv)->IsInstanceOf(jEnv, comparison_obj, njJSObject))
|
||||
return 0;
|
||||
|
||||
js_obj1 = jsj_UnwrapJSObjectWrapper(jEnv, java_wrapper_obj);
|
||||
js_obj2 = jsj_UnwrapJSObjectWrapper(jEnv, comparison_obj);
|
||||
|
||||
return (js_obj1 == js_obj2);
|
||||
#endif /* PRESERVE_JSOBJECT_IDENTITY */
|
||||
}
|
||||
@@ -26,51 +26,10 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prassert.h"
|
||||
|
||||
#include "jsj_private.h" /* LiveConnect internals */
|
||||
|
||||
/* Shorthands for ASCII (7-bit) decimal and hex conversion. */
|
||||
#define JS7_ISDEC(c) (((c) >= '0') && ((c) <= '9'))
|
||||
#define JS7_UNDEC(c) ((c) - '0')
|
||||
|
||||
/*
|
||||
* Convert any jsval v to an integer jsval if ToString(v)
|
||||
* contains a base-10 integer that fits into 31 bits.
|
||||
* Otherwise return v.
|
||||
*/
|
||||
static jsval
|
||||
try_convert_to_jsint(JSContext *cx, jsval idval)
|
||||
{
|
||||
const jschar *cp;
|
||||
JSString *jsstr;
|
||||
|
||||
jsstr = JS_ValueToString(cx, idval);
|
||||
if (!jsstr)
|
||||
return idval;
|
||||
|
||||
cp = JS_GetStringChars(jsstr);
|
||||
if (JS7_ISDEC(*cp)) {
|
||||
jsuint index = JS7_UNDEC(*cp++);
|
||||
jsuint oldIndex = 0;
|
||||
jsuint c = 0;
|
||||
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)))) {
|
||||
return INT_TO_JSVAL(index);
|
||||
}
|
||||
}
|
||||
return idval;
|
||||
}
|
||||
|
||||
|
||||
static JSBool
|
||||
access_java_array_element(JSContext *cx,
|
||||
JNIEnv *jEnv,
|
||||
@@ -92,7 +51,7 @@ access_java_array_element(JSContext *cx,
|
||||
if (!java_wrapper) {
|
||||
const char *property_name;
|
||||
if (JS_IdToValue(cx, id, &idval) && JSVAL_IS_STRING(idval) &&
|
||||
(property_name = JS_GetStringBytes(JSVAL_TO_STRING(idval))) != NULL) {
|
||||
(property_name = JS_GetStringBytes(JSVAL_TO_STRING(idval)))) {
|
||||
if (!strcmp(property_name, "constructor")) {
|
||||
*vp = JSVAL_VOID;
|
||||
return JS_TRUE;
|
||||
@@ -108,9 +67,6 @@ access_java_array_element(JSContext *cx,
|
||||
|
||||
JS_IdToValue(cx, id, &idval);
|
||||
|
||||
if (!JSVAL_IS_INT(idval))
|
||||
idval = try_convert_to_jsint(cx, idval);
|
||||
|
||||
if (!JSVAL_IS_INT(idval)) {
|
||||
/*
|
||||
* Usually, properties of JavaArray objects are indexed by integers, but
|
||||
@@ -123,17 +79,9 @@ access_java_array_element(JSContext *cx,
|
||||
member_name = JS_GetStringBytes(JSVAL_TO_STRING(idval));
|
||||
|
||||
if (do_assignment) {
|
||||
JSVersion version = JS_GetVersion(cx);
|
||||
|
||||
if (!JSVERSION_IS_ECMA(version)) {
|
||||
|
||||
JS_ReportError(cx, "Attempt to write to invalid Java array "
|
||||
"element \"%s\"", member_name);
|
||||
return JS_FALSE;
|
||||
} else {
|
||||
*vp = JSVAL_VOID;
|
||||
return JS_TRUE;
|
||||
}
|
||||
JS_ReportError(cx, "Attempt to write to invalid Java array "
|
||||
"element \"%s\"", member_name);
|
||||
return JS_FALSE;
|
||||
} else {
|
||||
if (!strcmp(member_name, "length")) {
|
||||
array_length = jsj_GetJavaArrayLength(cx, jEnv, java_array);
|
||||
@@ -222,7 +170,7 @@ JavaArray_defineProperty(JSContext *cx, JSObject *obj, jsid id, jsval value,
|
||||
JSPropertyOp getter, JSPropertyOp setter,
|
||||
uintN attrs, JSProperty **propp)
|
||||
{
|
||||
JS_ReportError(cx, "Cannot define a new property in a JavaArray");
|
||||
JS_ReportError(cx, "Elements of JavaArray objects may not be deleted");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@@ -240,7 +188,7 @@ JavaArray_setAttributes(JSContext *cx, JSObject *obj, jsid id,
|
||||
JSProperty *prop, uintN *attrsp)
|
||||
{
|
||||
/* We don't maintain JS property attributes for Java class members */
|
||||
if (*attrsp != (JSPROP_PERMANENT|JSPROP_ENUMERATE)) {
|
||||
if (*attrsp != JSPROP_PERMANENT|JSPROP_ENUMERATE) {
|
||||
PR_ASSERT(0);
|
||||
return JS_FALSE;
|
||||
}
|
||||
@@ -252,18 +200,8 @@ JavaArray_setAttributes(JSContext *cx, JSObject *obj, jsid id,
|
||||
static JSBool
|
||||
JavaArray_deleteProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
{
|
||||
JSVersion version = JS_GetVersion(cx);
|
||||
|
||||
*vp = JSVAL_FALSE;
|
||||
|
||||
if (!JSVERSION_IS_ECMA(version)) {
|
||||
JS_ReportError(cx, "Properties of JavaArray objects may not be deleted");
|
||||
return JS_FALSE;
|
||||
} else {
|
||||
/* Attempts to delete permanent properties are silently ignored
|
||||
by ECMAScript. */
|
||||
return JS_TRUE;
|
||||
}
|
||||
JS_ReportError(cx, "Elements of JavaArray objects may not be deleted");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
@@ -370,7 +308,7 @@ JSObjectOps JavaArray_ops = {
|
||||
NULL /* hasInstance */
|
||||
};
|
||||
|
||||
static JSObjectOps *
|
||||
JSObjectOps *
|
||||
JavaArray_getObjectOps(JSContext *cx, JSClass *clazz)
|
||||
{
|
||||
return &JavaArray_ops;
|
||||
@@ -36,6 +36,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "prprintf.h"
|
||||
#include "prassert.h"
|
||||
|
||||
#include "jsj_private.h" /* LiveConnect internals */
|
||||
|
||||
static JSBool
|
||||
@@ -75,9 +79,8 @@ JavaClass_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
|
||||
return JS_TRUE;
|
||||
|
||||
default:
|
||||
break;
|
||||
return JS_TRUE;
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
@@ -161,7 +164,7 @@ JavaClass_getPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
} else {
|
||||
JSFunction *function;
|
||||
|
||||
/* TODO - eliminate JSFUN_BOUND_METHOD */
|
||||
/* FIXME - eliminate JSFUN_BOUND_METHOD */
|
||||
JS_IdToValue(cx, id, &idval);
|
||||
member_name = JS_GetStringBytes(JSVAL_TO_STRING(idval));
|
||||
function = JS_NewFunction(cx, jsj_JavaStaticMethodWrapper, 0,
|
||||
@@ -170,8 +173,8 @@ JavaClass_getPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
return JS_FALSE;
|
||||
|
||||
*vp = OBJECT_TO_JSVAL(JS_GetFunctionObject(function));
|
||||
return JS_TRUE;
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
@@ -231,7 +234,7 @@ JavaClass_finalize(JSContext *cx, JSObject *obj)
|
||||
if (!jEnv)
|
||||
return;
|
||||
|
||||
/* printf("Finalizing %s\n", class_descriptor->name); */
|
||||
printf("Finalizing %s\n", class_descriptor->name);
|
||||
jsj_ReleaseJavaClassDescriptor(cx, jEnv, class_descriptor);
|
||||
}
|
||||
|
||||
@@ -245,25 +248,18 @@ JavaClass_lookupProperty(JSContext *cx, JSObject *obj, jsid id,
|
||||
)
|
||||
{
|
||||
JNIEnv *jEnv;
|
||||
JSErrorReporter old_reporter;
|
||||
|
||||
/* printf("In JavaClass_lookupProperty()\n"); */
|
||||
|
||||
|
||||
/* Get the Java per-thread environment pointer for this JSContext */
|
||||
jsj_MapJSContextToJSJThread(cx, &jEnv);
|
||||
if (!jEnv)
|
||||
return JS_FALSE;
|
||||
|
||||
old_reporter = JS_SetErrorReporter(cx, NULL);
|
||||
if (lookup_static_member_by_id(cx, jEnv, obj, NULL, id, NULL)) {
|
||||
*objp = obj;
|
||||
*propp = (JSProperty*)1;
|
||||
} else {
|
||||
*objp = NULL;
|
||||
*propp = NULL;
|
||||
}
|
||||
|
||||
JS_SetErrorReporter(cx, old_reporter);
|
||||
if (!lookup_static_member_by_id(cx, jEnv, obj, NULL, id, NULL))
|
||||
return JS_FALSE;
|
||||
*objp = obj;
|
||||
*propp = (JSProperty*)1;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
@@ -272,7 +268,7 @@ JavaClass_defineProperty(JSContext *cx, JSObject *obj, jsid id, jsval value,
|
||||
JSPropertyOp getter, JSPropertyOp setter,
|
||||
uintN attrs, JSProperty **propp)
|
||||
{
|
||||
JS_ReportError(cx, "Cannot define a new property in a JavaClass");
|
||||
JS_ReportError(cx, "Properties of JavaClass objects may not be deleted");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@@ -290,7 +286,7 @@ JavaClass_setAttributes(JSContext *cx, JSObject *obj, jsid id,
|
||||
JSProperty *prop, uintN *attrsp)
|
||||
{
|
||||
/* We don't maintain JS property attributes for Java class members */
|
||||
if (*attrsp != (JSPROP_PERMANENT|JSPROP_ENUMERATE)) {
|
||||
if (*attrsp != JSPROP_PERMANENT|JSPROP_ENUMERATE) {
|
||||
PR_ASSERT(0);
|
||||
return JS_FALSE;
|
||||
}
|
||||
@@ -302,18 +298,8 @@ JavaClass_setAttributes(JSContext *cx, JSObject *obj, jsid id,
|
||||
static JSBool
|
||||
JavaClass_deleteProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
{
|
||||
JSVersion version = JS_GetVersion(cx);
|
||||
|
||||
*vp = JSVAL_FALSE;
|
||||
|
||||
if (!JSVERSION_IS_ECMA(version)) {
|
||||
JS_ReportError(cx, "Properties of JavaClass objects may not be deleted");
|
||||
return JS_FALSE;
|
||||
} else {
|
||||
/* Attempts to delete permanent properties are silently ignored
|
||||
by ECMAScript. */
|
||||
return JS_TRUE;
|
||||
}
|
||||
JS_ReportError(cx, "Properties of JavaClass objects may not be deleted");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
@@ -347,7 +333,7 @@ JavaClass_newEnumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
jsj_MapJSContextToJSJThread(cx, &jEnv);
|
||||
if (!jEnv)
|
||||
return JS_FALSE;
|
||||
member_descriptor = jsj_GetClassStaticMembers(cx, jEnv, class_descriptor);
|
||||
member_descriptor = jsj_GetClassInstanceMembers(cx, jEnv, class_descriptor);
|
||||
*statep = PRIVATE_TO_JSVAL(member_descriptor);
|
||||
if (idp)
|
||||
*idp = INT_TO_JSVAL(class_descriptor->num_instance_members);
|
||||
@@ -465,7 +451,7 @@ JSObjectOps JavaClass_ops = {
|
||||
JavaClass_hasInstance, /* hasInstance */
|
||||
};
|
||||
|
||||
static JSObjectOps *
|
||||
JSObjectOps *
|
||||
JavaClass_getObjectOps(JSContext *cx, JSClass *clazz)
|
||||
{
|
||||
return &JavaClass_ops;
|
||||
@@ -478,7 +464,7 @@ JSClass JavaClass_class = {
|
||||
JavaClass_getObjectOps,
|
||||
};
|
||||
|
||||
static JSObject *
|
||||
JSObject *
|
||||
jsj_new_JavaClass(JSContext *cx, JNIEnv *jEnv, JSObject* parent_obj,
|
||||
JavaClassDescriptor *class_descriptor)
|
||||
{
|
||||
@@ -542,12 +528,12 @@ getClass(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
return JS_FALSE;
|
||||
|
||||
if (argc != 1 ||
|
||||
!JSVAL_IS_OBJECT(argv[0]) ||
|
||||
!(obj_arg = JSVAL_TO_OBJECT(argv[0])) ||
|
||||
(!JS_InstanceOf(cx, obj_arg, &JavaObject_class, 0) &&
|
||||
!JSVAL_IS_OBJECT(argv[0]) ||
|
||||
!(obj_arg = JSVAL_TO_OBJECT(argv[0])) ||
|
||||
(!JS_InstanceOf(cx, obj_arg, &JavaObject_class, 0) &&
|
||||
!JS_InstanceOf(cx, obj_arg, &JavaArray_class, 0))) {
|
||||
JS_ReportError(cx, "getClass expects a Java object argument");
|
||||
return JS_FALSE;
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
java_wrapper = JS_GetPrivate(cx, obj_arg);
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
@@ -28,9 +28,9 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "prassert.h"
|
||||
|
||||
#include "jsj_private.h" /* LiveConnect internals */
|
||||
#include "jsj_hash.h" /* Hash table with Java object as key */
|
||||
|
||||
|
||||
/*
|
||||
@@ -47,7 +47,7 @@
|
||||
* When the corresponding JS object instance is finalized, the entry is
|
||||
* removed from the table, and a Java GC root for the Java object is removed.
|
||||
*/
|
||||
static JSJHashTable *java_obj_reflections = NULL;
|
||||
static PRHashTable *java_obj_reflections = NULL;
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
static PRMonitor *java_obj_reflections_monitor = NULL;
|
||||
@@ -57,8 +57,8 @@ static JSBool
|
||||
init_java_obj_reflections_table()
|
||||
{
|
||||
java_obj_reflections =
|
||||
JSJ_NewHashTable(512, jsj_HashJavaObject, jsj_JavaObjectComparator,
|
||||
NULL, NULL, NULL);
|
||||
PR_NewHashTable(512, jsj_HashJavaObject, jsj_JavaObjectComparator,
|
||||
NULL, NULL, NULL);
|
||||
if (!java_obj_reflections)
|
||||
return JS_FALSE;
|
||||
|
||||
@@ -79,23 +79,23 @@ jsj_WrapJavaObject(JSContext *cx,
|
||||
jobject java_obj,
|
||||
jclass java_class)
|
||||
{
|
||||
JSJHashNumber hash_code;
|
||||
prhashcode hash_code;
|
||||
JSClass *js_class;
|
||||
JSObject *js_wrapper_obj;
|
||||
JavaObjectWrapper *java_wrapper;
|
||||
JavaClassDescriptor *class_descriptor;
|
||||
JSJHashEntry *he, **hep;
|
||||
PRHashEntry *he, **hep;
|
||||
|
||||
js_wrapper_obj = NULL;
|
||||
|
||||
hash_code = jsj_HashJavaObject((void*)java_obj, (void*)jEnv);
|
||||
hash_code = jsj_HashJavaObject((void*)java_obj);
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
PR_EnterMonitor(java_obj_reflections_monitor);
|
||||
#endif
|
||||
|
||||
hep = JSJ_HashTableRawLookup(java_obj_reflections,
|
||||
hash_code, java_obj, (void*)jEnv);
|
||||
hep = PR_HashTableRawLookup(java_obj_reflections,
|
||||
hash_code, java_obj);
|
||||
he = *hep;
|
||||
if (he) {
|
||||
js_wrapper_obj = (JSObject *)he->value;
|
||||
@@ -128,17 +128,16 @@ jsj_WrapJavaObject(JSContext *cx,
|
||||
}
|
||||
JS_SetPrivate(cx, js_wrapper_obj, java_wrapper);
|
||||
java_wrapper->class_descriptor = class_descriptor;
|
||||
|
||||
java_obj = (*jEnv)->NewGlobalRef(jEnv, java_obj);
|
||||
java_wrapper->java_obj = java_obj;
|
||||
if (!java_obj)
|
||||
goto out_of_memory;
|
||||
java_wrapper->members = NULL;
|
||||
|
||||
/* Add the JavaObject to the hash table */
|
||||
he = JSJ_HashTableRawAdd(java_obj_reflections, hep, hash_code,
|
||||
java_obj, js_wrapper_obj, (void*)jEnv);
|
||||
if (!he) {
|
||||
(*jEnv)->DeleteGlobalRef(jEnv, java_obj);
|
||||
he = PR_HashTableRawAdd(java_obj_reflections, hep, hash_code,
|
||||
java_obj, js_wrapper_obj);
|
||||
if (he) {
|
||||
java_wrapper->java_obj = (*jEnv)->NewGlobalRef(jEnv, java_obj);
|
||||
if (!java_wrapper->java_obj)
|
||||
goto out_of_memory;
|
||||
} else {
|
||||
goto out_of_memory;
|
||||
}
|
||||
|
||||
@@ -157,24 +156,23 @@ out_of_memory:
|
||||
}
|
||||
|
||||
static void
|
||||
remove_java_obj_reflection_from_hashtable(jobject java_obj, JNIEnv *jEnv)
|
||||
remove_java_obj_reflection_from_hashtable(jobject java_obj)
|
||||
{
|
||||
JSJHashNumber hash_code;
|
||||
JSJHashEntry *he, **hep;
|
||||
prhashcode hash_code;
|
||||
PRHashEntry *he, **hep;
|
||||
|
||||
hash_code = jsj_HashJavaObject((void*)java_obj, (void*)jEnv);
|
||||
hash_code = jsj_HashJavaObject((void*)java_obj);
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
PR_EnterMonitor(java_obj_reflections_monitor);
|
||||
#endif
|
||||
|
||||
hep = JSJ_HashTableRawLookup(java_obj_reflections, hash_code,
|
||||
java_obj, (void*)jEnv);
|
||||
hep = PR_HashTableRawLookup(java_obj_reflections, hash_code, java_obj);
|
||||
he = *hep;
|
||||
|
||||
PR_ASSERT(he);
|
||||
if (he)
|
||||
JSJ_HashTableRawRemove(java_obj_reflections, hep, he, (void*)jEnv);
|
||||
PR_HashTableRawRemove(java_obj_reflections, hep, he);
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
PR_ExitMonitor(java_obj_reflections_monitor);
|
||||
@@ -197,46 +195,36 @@ JavaObject_finalize(JSContext *cx, JSObject *obj)
|
||||
return;
|
||||
java_obj = java_wrapper->java_obj;
|
||||
|
||||
if (java_obj) {
|
||||
remove_java_obj_reflection_from_hashtable(java_obj, jEnv);
|
||||
(*jEnv)->DeleteGlobalRef(jEnv, java_obj);
|
||||
}
|
||||
remove_java_obj_reflection_from_hashtable(java_obj);
|
||||
|
||||
(*jEnv)->DeleteGlobalRef(jEnv, java_obj);
|
||||
jsj_ReleaseJavaClassDescriptor(cx, jEnv, java_wrapper->class_descriptor);
|
||||
/* FIXME - Delete JavaMemberValues */
|
||||
/* if (java_wrapper->invoke_java_method_func_obj)
|
||||
JS_RemoveRoot(cx, &java_wrapper->invoke_java_method_func_obj); */
|
||||
JS_free(cx, java_wrapper);
|
||||
}
|
||||
|
||||
/* Trivial helper for jsj_DiscardJavaObjReflections(), below */
|
||||
static PRIntn
|
||||
enumerate_remove_java_obj(JSJHashEntry *he, PRIntn i, void *arg)
|
||||
/*
|
||||
static JSBool
|
||||
JavaObject_toString(JSContext *cx, JSObject *obj,
|
||||
uintN argc, jsval *argv, jsval *vp)
|
||||
{
|
||||
JNIEnv *jEnv = (JNIEnv*)arg;
|
||||
jobject java_obj;
|
||||
JavaObjectWrapper *java_wrapper;
|
||||
JSObject *java_wrapper_obj;
|
||||
JavaClassDescriptor *class_descriptor;
|
||||
|
||||
java_wrapper_obj = (JSObject *)he->value;
|
||||
java_wrapper = JS_GetPrivate(NULL, java_wrapper_obj);
|
||||
java_obj = java_wrapper->java_obj;
|
||||
(*jEnv)->DeleteGlobalRef(jEnv, java_obj);
|
||||
java_wrapper->java_obj = NULL;
|
||||
return HT_ENUMERATE_REMOVE;
|
||||
}
|
||||
|
||||
/* This shutdown routine discards all JNI references to Java objects
|
||||
that have been reflected into JS, even if there are still references
|
||||
to them from JS. */
|
||||
void
|
||||
jsj_DiscardJavaObjReflections(JNIEnv *jEnv)
|
||||
{
|
||||
if (java_obj_reflections) {
|
||||
JSJ_HashTableEnumerateEntries(java_obj_reflections,
|
||||
enumerate_remove_java_obj,
|
||||
(void*)jEnv);
|
||||
JSJ_HashTableDestroy(java_obj_reflections);
|
||||
java_obj_reflections = NULL;
|
||||
java_wrapper = JS_GetPrivate(cx, obj);
|
||||
if (!java_wrapper) {
|
||||
JS_ReportError(cx, "illegal operation on JavaObject prototype object");
|
||||
return JS_FALSE;
|
||||
}
|
||||
class_descriptor = java_wrapper->class_descriptor;
|
||||
java_obj = java_wrapper->java_obj;
|
||||
|
||||
return jsj_ConvertJavaObjectToJSString(cx, class_descriptor, java_obj, vp);
|
||||
}
|
||||
|
||||
*/
|
||||
PR_CALLBACK JSBool
|
||||
JavaObject_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
|
||||
{
|
||||
@@ -281,11 +269,11 @@ JavaObject_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
|
||||
|
||||
case JSTYPE_NUMBER:
|
||||
/* Call Java doubleValue() method, if applicable */
|
||||
return jsj_ConvertJavaObjectToJSNumber(cx, jEnv, class_descriptor, java_obj, vp);
|
||||
return jsj_ConvertJavaObjectToJSNumber(cx, jEnv, java_obj, vp);
|
||||
|
||||
case JSTYPE_BOOLEAN:
|
||||
/* Call booleanValue() method, if applicable */
|
||||
return jsj_ConvertJavaObjectToJSBoolean(cx, jEnv, class_descriptor, java_obj, vp);
|
||||
return jsj_ConvertJavaObjectToJSBoolean(cx, jEnv, java_obj, vp);
|
||||
|
||||
default:
|
||||
PR_ASSERT(0);
|
||||
@@ -296,10 +284,11 @@ JavaObject_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
|
||||
static JSBool
|
||||
lookup_member_by_id(JSContext *cx, JNIEnv *jEnv, JSObject *obj,
|
||||
JavaObjectWrapper **java_wrapperp,
|
||||
jsid id,
|
||||
jsid id, JavaMemberVal **memberp,
|
||||
JavaMemberDescriptor **member_descriptorp)
|
||||
{
|
||||
jsval idval;
|
||||
JavaMemberVal *member, **prev_memberp;
|
||||
JavaObjectWrapper *java_wrapper;
|
||||
JavaMemberDescriptor *member_descriptor;
|
||||
const char *member_name, *property_name;
|
||||
@@ -308,7 +297,7 @@ lookup_member_by_id(JSContext *cx, JNIEnv *jEnv, JSObject *obj,
|
||||
java_wrapper = JS_GetPrivate(cx, obj);
|
||||
if (!java_wrapper) {
|
||||
if (JS_IdToValue(cx, id, &idval) && JSVAL_IS_STRING(idval) &&
|
||||
(property_name = JS_GetStringBytes(JSVAL_TO_STRING(idval))) != NULL) {
|
||||
(property_name = JS_GetStringBytes(JSVAL_TO_STRING(idval)))) {
|
||||
if (!strcmp(property_name, "constructor")) {
|
||||
*java_wrapperp = NULL;
|
||||
*member_descriptorp = NULL;
|
||||
@@ -323,7 +312,52 @@ lookup_member_by_id(JSContext *cx, JNIEnv *jEnv, JSObject *obj,
|
||||
PR_ASSERT(class_descriptor->type == JAVA_SIGNATURE_CLASS ||
|
||||
class_descriptor->type == JAVA_SIGNATURE_ARRAY);
|
||||
|
||||
member_descriptor = jsj_LookupJavaMemberDescriptorById(cx, jEnv, class_descriptor, id);
|
||||
/* FIXME - not thread-safe */
|
||||
prev_memberp = &java_wrapper->members;
|
||||
for (member = *prev_memberp; member; member = member->next) {
|
||||
member_descriptor = member->descriptor;
|
||||
if (member_descriptor->id == id) {
|
||||
*prev_memberp = member->next;
|
||||
member->next = java_wrapper->members;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!member) {
|
||||
JSFunction *function;
|
||||
JSObject *function_obj;
|
||||
|
||||
member_descriptor = jsj_LookupJavaMemberDescriptorById(cx, jEnv, class_descriptor, id);
|
||||
if (member_descriptor && member_descriptor->methods) {
|
||||
member = (JavaMemberVal*)JS_malloc(cx, sizeof(JavaMemberVal));
|
||||
if (!member)
|
||||
return JS_FALSE;
|
||||
JS_IdToValue(cx, id, &idval);
|
||||
member_name = JS_GetStringBytes(JSVAL_TO_STRING(idval));
|
||||
|
||||
/* printf("Adding %s\n", member_name); */
|
||||
|
||||
/* FIXME - eliminate JSFUN_BOUND_METHOD */
|
||||
/* TODO - Use JS_CloneFunction() to save memory */
|
||||
function = JS_NewFunction(cx, jsj_JavaInstanceMethodWrapper, 0,
|
||||
JSFUN_BOUND_METHOD, obj, member_name);
|
||||
if (!function) {
|
||||
JS_free(cx, member);
|
||||
return JS_FALSE;
|
||||
}
|
||||
function_obj = JS_GetFunctionObject(function);
|
||||
member->invoke_method_func_val = OBJECT_TO_JSVAL(function_obj);
|
||||
member->descriptor = member_descriptor;
|
||||
member->next = NULL;
|
||||
JS_AddRoot(cx, &member->invoke_method_func_val);
|
||||
}
|
||||
}
|
||||
|
||||
/* Place member at head of list of members for faster access next time */
|
||||
if (member) {
|
||||
member->next = java_wrapper->members;
|
||||
java_wrapper->members = member;
|
||||
}
|
||||
|
||||
if (!member_descriptor) {
|
||||
JS_IdToValue(cx, id, &idval);
|
||||
if (!JSVAL_IS_STRING(idval)) {
|
||||
@@ -343,6 +377,8 @@ lookup_member_by_id(JSContext *cx, JNIEnv *jEnv, JSObject *obj,
|
||||
/* Success. Handle the multiple return values */
|
||||
if (java_wrapperp)
|
||||
*java_wrapperp = java_wrapper;
|
||||
if (memberp)
|
||||
*memberp = member;
|
||||
if (member_descriptorp)
|
||||
*member_descriptorp = member_descriptor;
|
||||
return JS_TRUE;
|
||||
@@ -353,11 +389,9 @@ JavaObject_getPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
{
|
||||
jobject java_obj;
|
||||
JavaMemberDescriptor *member_descriptor;
|
||||
JavaMemberVal *member;
|
||||
JavaObjectWrapper *java_wrapper;
|
||||
JNIEnv *jEnv;
|
||||
JSObject *funobj;
|
||||
jsval field_val, method_val;
|
||||
JSBool success;
|
||||
|
||||
/* printf("In JavaObject_getProperty\n"); */
|
||||
|
||||
@@ -366,7 +400,7 @@ JavaObject_getPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
if (!jEnv)
|
||||
return JS_FALSE;
|
||||
|
||||
if (!lookup_member_by_id(cx, jEnv, obj, &java_wrapper, id, &member_descriptor))
|
||||
if (!lookup_member_by_id(cx, jEnv, obj, &java_wrapper, id, &member, &member_descriptor))
|
||||
return JS_FALSE;
|
||||
|
||||
/* Handle access to "constructor" property of prototype object with
|
||||
@@ -377,56 +411,16 @@ JavaObject_getPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
}
|
||||
|
||||
java_obj = java_wrapper->java_obj;
|
||||
field_val = method_val = JSVAL_VOID;
|
||||
|
||||
/* If a field member, get the value of the field */
|
||||
if (member_descriptor->field) {
|
||||
success = jsj_GetJavaFieldValue(cx, jEnv, member_descriptor->field, java_obj, &field_val);
|
||||
if (!success)
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
/* If a method member, build a wrapper around the Java method */
|
||||
if (member_descriptor->methods) {
|
||||
/* Create a function object with this JavaObject as its parent, so that
|
||||
JSFUN_BOUND_METHOD binds it as the default 'this' for the function. */
|
||||
funobj = JS_CloneFunctionObject(cx, member_descriptor->invoke_func_obj, obj);
|
||||
if (!funobj)
|
||||
return JS_FALSE;
|
||||
method_val = OBJECT_TO_JSVAL(funobj);
|
||||
}
|
||||
|
||||
#if TEST_JAVAMEMBER
|
||||
/* Always create a JavaMember object, even though it's inefficient */
|
||||
obj = jsj_CreateJavaMember(cx, method_val, field_val);
|
||||
if (!obj)
|
||||
return JS_FALSE;
|
||||
*vp = OBJECT_TO_JSVAL(obj);
|
||||
#else /* !TEST_JAVAMEMBER */
|
||||
|
||||
if (member_descriptor->field) {
|
||||
if (!member_descriptor->methods) {
|
||||
/* Return value of Java field */
|
||||
*vp = field_val;
|
||||
return jsj_GetJavaFieldValue(cx, jEnv, member_descriptor->field, java_obj, vp);
|
||||
} else {
|
||||
/* Handle special case of access to a property that could refer
|
||||
to either a Java field or a method that share the same name.
|
||||
In Java, such ambiguity is not possible because the compiler
|
||||
can statically determine which is being accessed. */
|
||||
obj = jsj_CreateJavaMember(cx, method_val, field_val);
|
||||
if (!obj)
|
||||
return JS_FALSE;
|
||||
*vp = OBJECT_TO_JSVAL(obj);
|
||||
PR_ASSERT(0);
|
||||
}
|
||||
|
||||
} else {
|
||||
/* Return wrapper around Java method */
|
||||
*vp = method_val;
|
||||
*vp = member->invoke_method_func_val;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
#endif /* !TEST_JAVAMEMBER */
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
@@ -447,7 +441,7 @@ JavaObject_setPropertyById(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
if (!jEnv)
|
||||
return JS_FALSE;
|
||||
|
||||
if (!lookup_member_by_id(cx, jEnv, obj, &java_wrapper, id, &member_descriptor))
|
||||
if (!lookup_member_by_id(cx, jEnv, obj, &java_wrapper, id, NULL, &member_descriptor))
|
||||
return JS_FALSE;
|
||||
|
||||
/* Check for the case where there is a method with the give name, but no field
|
||||
@@ -471,6 +465,38 @@ no_such_field:
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
PR_CALLBACK JSBool
|
||||
JavaObject_enumerate(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
JavaObjectWrapper *java_wrapper;
|
||||
JavaClassDescriptor *class_descriptor;
|
||||
JavaMemberDescriptor *member_descriptor;
|
||||
JNIEnv *jEnv;
|
||||
|
||||
/* printf("In JavaObject_enumerate\n"); */
|
||||
|
||||
java_wrapper = JS_GetPrivate(cx, obj);
|
||||
|
||||
/* Check if this is the prototype object */
|
||||
if (!java_wrapper)
|
||||
return JS_TRUE;
|
||||
|
||||
/* Get the Java per-thread environment pointer for this JSContext */
|
||||
jsj_MapJSContextToJSJThread(cx, &jEnv);
|
||||
if (!jEnv)
|
||||
return JS_FALSE;
|
||||
|
||||
class_descriptor = java_wrapper->class_descriptor;
|
||||
member_descriptor = jsj_GetClassInstanceMembers(cx, jEnv, class_descriptor);
|
||||
while (member_descriptor) {
|
||||
JS_DefineProperty(cx, obj, member_descriptor->name, JSVAL_VOID, 0, 0,
|
||||
JSPROP_PERMANENT|JSPROP_ENUMERATE);
|
||||
member_descriptor = member_descriptor->next;
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
static JSBool
|
||||
JavaObject_lookupProperty(JSContext *cx, JSObject *obj, jsid id,
|
||||
JSObject **objp, JSProperty **propp
|
||||
@@ -480,7 +506,6 @@ JavaObject_lookupProperty(JSContext *cx, JSObject *obj, jsid id,
|
||||
)
|
||||
{
|
||||
JNIEnv *jEnv;
|
||||
JSErrorReporter old_reporter;
|
||||
|
||||
/* printf("In JavaObject_lookupProperty()\n"); */
|
||||
|
||||
@@ -489,16 +514,10 @@ JavaObject_lookupProperty(JSContext *cx, JSObject *obj, jsid id,
|
||||
if (!jEnv)
|
||||
return JS_FALSE;
|
||||
|
||||
old_reporter = JS_SetErrorReporter(cx, NULL);
|
||||
if (lookup_member_by_id(cx, jEnv, obj, NULL, id, NULL)) {
|
||||
*objp = obj;
|
||||
*propp = (JSProperty*)1;
|
||||
} else {
|
||||
*objp = NULL;
|
||||
*propp = NULL;
|
||||
}
|
||||
|
||||
JS_SetErrorReporter(cx, old_reporter);
|
||||
if (!lookup_member_by_id(cx, jEnv, obj, NULL, id, NULL, NULL))
|
||||
return JS_FALSE;
|
||||
*objp = obj;
|
||||
*propp = (JSProperty*)1;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
@@ -507,7 +526,7 @@ JavaObject_defineProperty(JSContext *cx, JSObject *obj, jsid id, jsval value,
|
||||
JSPropertyOp getter, JSPropertyOp setter,
|
||||
uintN attrs, JSProperty **propp)
|
||||
{
|
||||
JS_ReportError(cx, "Cannot define a new property in a JavaObject");
|
||||
JS_ReportError(cx, "Properties of JavaObject objects may not be deleted");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@@ -525,7 +544,7 @@ JavaObject_setAttributes(JSContext *cx, JSObject *obj, jsid id,
|
||||
JSProperty *prop, uintN *attrsp)
|
||||
{
|
||||
/* We don't maintain JS property attributes for Java class members */
|
||||
if (*attrsp != (JSPROP_PERMANENT|JSPROP_ENUMERATE)) {
|
||||
if (*attrsp != JSPROP_PERMANENT|JSPROP_ENUMERATE) {
|
||||
PR_ASSERT(0);
|
||||
return JS_FALSE;
|
||||
}
|
||||
@@ -537,25 +556,15 @@ JavaObject_setAttributes(JSContext *cx, JSObject *obj, jsid id,
|
||||
static JSBool
|
||||
JavaObject_deleteProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
{
|
||||
JSVersion version = JS_GetVersion(cx);
|
||||
|
||||
*vp = JSVAL_FALSE;
|
||||
|
||||
if (!JSVERSION_IS_ECMA(version)) {
|
||||
JS_ReportError(cx, "Properties of JavaObject objects may not be deleted");
|
||||
return JS_FALSE;
|
||||
} else {
|
||||
/* Attempts to delete permanent properties are silently ignored
|
||||
by ECMAScript. */
|
||||
return JS_TRUE;
|
||||
}
|
||||
JS_ReportError(cx, "Properties of JavaObject objects may not be deleted");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
JavaObject_defaultValue(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
|
||||
{
|
||||
/* printf("In JavaObject_defaultValue()\n"); */
|
||||
return JavaObject_convert(cx, obj, type, vp);
|
||||
return JavaObject_convert(cx, obj, JSTYPE_STRING, vp);
|
||||
}
|
||||
|
||||
static JSBool
|
||||
@@ -654,7 +663,7 @@ JSObjectOps JavaObject_ops = {
|
||||
NULL, /* hasInstance */
|
||||
};
|
||||
|
||||
static JSObjectOps *
|
||||
JSObjectOps *
|
||||
JavaObject_getObjectOps(JSContext *cx, JSClass *clazz)
|
||||
{
|
||||
return &JavaObject_ops;
|
||||
@@ -36,6 +36,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "prprintf.h"
|
||||
|
||||
#include "jsj_private.h" /* LiveConnect internals */
|
||||
#include "jsjava.h"
|
||||
|
||||
@@ -51,7 +54,7 @@ typedef struct {
|
||||
int flags; /* e.g. PKG_SYSTEM, PKG_CLASS */
|
||||
} JavaPackage_Private;
|
||||
|
||||
static JSObject *
|
||||
JSObject *
|
||||
define_JavaPackage(JSContext *cx, JSObject *parent_obj,
|
||||
const char *obj_name, const char *path, int flags)
|
||||
{
|
||||
@@ -99,7 +102,8 @@ JavaPackage_setProperty(JSContext *cx, JSObject *obj, jsval slot, jsval *vp)
|
||||
"JavaPackage prototype object");
|
||||
return JS_FALSE;
|
||||
}
|
||||
JS_ReportError(cx, "You may not add properties to a JavaPackage object");
|
||||
JS_ReportError(cx, "You may not add properties to %s, "
|
||||
"as it is not a JavaScript object", package->path);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
@@ -117,26 +121,15 @@ JavaPackage_resolve(JSContext *cx, JSObject *obj, jsval id)
|
||||
char *subPath, *newPath;
|
||||
const char *path;
|
||||
JNIEnv *jEnv;
|
||||
|
||||
|
||||
package = (JavaPackage_Private *)JS_GetPrivate(cx, obj);
|
||||
if (!package)
|
||||
return JS_TRUE;
|
||||
|
||||
if (!JSVAL_IS_STRING(id))
|
||||
return JS_TRUE;
|
||||
if (!package) {
|
||||
fprintf(stderr, "JavaPackage_resolve: no private data!\n");
|
||||
return JS_FALSE;
|
||||
}
|
||||
path = package->path;
|
||||
subPath = JS_GetStringBytes(JSVAL_TO_STRING(id));
|
||||
|
||||
/*
|
||||
* There will be an attempt to invoke the toString() method when producing
|
||||
* the string representation of a JavaPackage. When this occurs, avoid
|
||||
* creating a bogus toString package. (This means that no one can ever
|
||||
* create a package with the simple name "toString", but we'll live with
|
||||
* that limitation.)
|
||||
*/
|
||||
if (!strcmp(subPath, "toString"))
|
||||
return JS_FALSE;
|
||||
|
||||
path = package->path;
|
||||
newPath = PR_smprintf("%s%s%s", path, (path[0] ? "/" : ""), subPath);
|
||||
if (!newPath) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
@@ -182,18 +175,6 @@ JavaPackage_resolve(JSContext *cx, JSObject *obj, jsval id)
|
||||
}
|
||||
} else {
|
||||
|
||||
/* We assume that any failed attempt to load a class is because it
|
||||
doesn't exist. If we wanted to do a better job, we would check
|
||||
the exception type and make sure that it's NoClassDefFoundError */
|
||||
(*jEnv)->ExceptionClear(jEnv);
|
||||
|
||||
/* beard: this has to be done here, so built-in classes will be defined. */
|
||||
/* Painful hack for pre_define_java_packages() */
|
||||
if (quiet_resolve_failure) {
|
||||
ok = JS_FALSE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* If there's no class of the given name, then we must be referring to
|
||||
* a package. However, don't allow bogus sub-packages of pre-defined
|
||||
@@ -206,9 +187,13 @@ JavaPackage_resolve(JSContext *cx, JSObject *obj, jsval id)
|
||||
if (package->flags & PKG_SYSTEM) {
|
||||
char *msg, *cp;
|
||||
|
||||
/* Painful hack for pre_define_java_packages() */
|
||||
if (quiet_resolve_failure)
|
||||
return JS_FALSE;
|
||||
|
||||
msg = PR_smprintf("No Java system package with name \"%s\" was identified "
|
||||
"and no Java class with that name exists either",
|
||||
newPath);
|
||||
"at initialization time and no Java class "
|
||||
"with that name exists either", newPath);
|
||||
|
||||
/* Check for OOM */
|
||||
if (msg) {
|
||||
@@ -220,18 +205,16 @@ JavaPackage_resolve(JSContext *cx, JSObject *obj, jsval id)
|
||||
free((char*)msg);
|
||||
}
|
||||
|
||||
ok = JS_FALSE;
|
||||
goto out;
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!define_JavaPackage(cx, obj, subPath, newPath, 0)) {
|
||||
ok = JS_FALSE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
/* printf("JavaPackage \'%s\' created\n", newPath); */
|
||||
printf("JavaPackage \'%s/%s\' created\n", subPath, newPath);
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -256,8 +239,6 @@ JavaPackage_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
|
||||
switch (type) {
|
||||
|
||||
/* Pretty-printing of JavaPackage */
|
||||
case JSTYPE_VOID: /* Default value */
|
||||
case JSTYPE_NUMBER:
|
||||
case JSTYPE_STRING:
|
||||
/* Convert '/' to '.' so that it looks like Java language syntax. */
|
||||
if (!package->path)
|
||||
@@ -318,53 +299,25 @@ JSClass JavaPackage_class = {
|
||||
|
||||
JavaPackageDef
|
||||
standard_java_packages[] = {
|
||||
{"java", NULL, PKG_USER},
|
||||
{"java.applet", NULL, PKG_USER},
|
||||
{"java.awt", NULL, PKG_USER},
|
||||
{"java.awt.datatransfer",
|
||||
NULL, PKG_SYSTEM},
|
||||
{"java", NULL, PKG_SYSTEM},
|
||||
{"java.awt", NULL, PKG_SYSTEM},
|
||||
{"java.awt.event", NULL, PKG_SYSTEM},
|
||||
{"java.awt.image", NULL, PKG_SYSTEM},
|
||||
{"java.awt.peer", NULL, PKG_SYSTEM},
|
||||
{"java.beans", NULL, PKG_USER},
|
||||
{"java.beans", NULL, PKG_SYSTEM},
|
||||
{"java.io", NULL, PKG_SYSTEM},
|
||||
{"java.lang", NULL, PKG_USER},
|
||||
{"java.lang", NULL, PKG_SYSTEM},
|
||||
{"java.lang.reflect", NULL, PKG_SYSTEM},
|
||||
{"java.math", NULL, PKG_SYSTEM},
|
||||
{"java.net", NULL, PKG_USER},
|
||||
{"java.rmi", NULL, PKG_USER},
|
||||
{"java.rmi.dgc", NULL, PKG_USER},
|
||||
{"java.rmi.user", NULL, PKG_USER},
|
||||
{"java.rmi.registry", NULL, PKG_USER},
|
||||
{"java.rmi.server", NULL, PKG_USER},
|
||||
{"java.security", NULL, PKG_USER},
|
||||
{"java.security.acl", NULL, PKG_SYSTEM},
|
||||
{"java.security.interfaces",
|
||||
NULL, PKG_SYSTEM},
|
||||
{"java.sql", NULL, PKG_USER},
|
||||
{"java.text", NULL, PKG_USER},
|
||||
{"java.text.resources", NULL, PKG_SYSTEM},
|
||||
{"java.util", NULL, PKG_USER},
|
||||
{"java.net", NULL, PKG_SYSTEM},
|
||||
{"java.text", NULL, PKG_SYSTEM},
|
||||
{"java.util", NULL, PKG_SYSTEM},
|
||||
{"java.util.zip", NULL, PKG_SYSTEM},
|
||||
|
||||
{"netscape", NULL, PKG_USER},
|
||||
{"netscape.applet", NULL, PKG_SYSTEM},
|
||||
{"netscape.application",NULL, PKG_SYSTEM},
|
||||
{"netscape.debug", NULL, PKG_SYSTEM},
|
||||
{"netscape", NULL, PKG_SYSTEM},
|
||||
{"netscape.javascript", NULL, PKG_SYSTEM},
|
||||
{"netscape.ldap", NULL, PKG_SYSTEM},
|
||||
{"netscape.misc", NULL, PKG_SYSTEM},
|
||||
{"netscape.net", NULL, PKG_SYSTEM},
|
||||
{"netscape.plugin", NULL, PKG_SYSTEM},
|
||||
{"netscape.util", NULL, PKG_SYSTEM},
|
||||
{"netscape.secfile", NULL, PKG_SYSTEM},
|
||||
{"netscape.security", NULL, PKG_SYSTEM},
|
||||
{"netscape.WAI", NULL, PKG_SYSTEM},
|
||||
|
||||
{"sun", NULL, PKG_USER},
|
||||
{"Packages", "", PKG_USER},
|
||||
|
||||
{NULL, NULL, 0}
|
||||
0
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -463,20 +416,6 @@ error:
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
JavaPackage_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *rval)
|
||||
{
|
||||
if (!JS_InstanceOf(cx, obj, &JavaPackage_class, argv))
|
||||
return JS_FALSE;
|
||||
return JavaPackage_convert(cx, obj, JSTYPE_STRING, rval);
|
||||
}
|
||||
|
||||
static JSFunctionSpec JavaPackage_methods[] = {
|
||||
{"toString", JavaPackage_toString, 0},
|
||||
{0}
|
||||
};
|
||||
|
||||
/*
|
||||
* One-time initialization for the JavaPackage class. (This is not
|
||||
* run once per thread, rather it's run once for a given JSContext.)
|
||||
@@ -486,8 +425,7 @@ jsj_init_JavaPackage(JSContext *cx, JSObject *global_obj,
|
||||
JavaPackageDef *additional_predefined_packages) {
|
||||
|
||||
/* Define JavaPackage class */
|
||||
if (!JS_InitClass(cx, global_obj, 0, &JavaPackage_class,
|
||||
0, 0, 0, JavaPackage_methods, 0, 0))
|
||||
if (!JS_InitClass(cx, global_obj, 0, &JavaPackage_class, 0, 0, 0, 0, 0, 0))
|
||||
return JS_FALSE;
|
||||
|
||||
/* Add top-level packages, e.g. : java, netscape, sun */
|
||||
@@ -23,6 +23,9 @@
|
||||
* It contains the code for reading and writing elements of a Java array.
|
||||
*/
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "prassert.h"
|
||||
|
||||
#include "jsj_private.h" /* LiveConnect internals */
|
||||
|
||||
/*
|
||||
@@ -109,10 +112,9 @@ jsj_SetJavaArrayElement(JSContext *cx, JNIEnv *jEnv, jarray java_array, jsize in
|
||||
int dummy_cost;
|
||||
jvalue java_value;
|
||||
JavaSignatureChar component_type;
|
||||
JSBool is_local_ref;
|
||||
|
||||
if (!jsj_ConvertJSValueToJavaValue(cx, jEnv, js_val, array_component_signature,
|
||||
&dummy_cost, &java_value, &is_local_ref))
|
||||
&dummy_cost, &java_value))
|
||||
return JS_FALSE;
|
||||
|
||||
#define SET_ELEMENT_FROM_PRIMITIVE_JAVA_ARRAY(Type,member) \
|
||||
@@ -161,8 +163,6 @@ jsj_SetJavaArrayElement(JSContext *cx, JNIEnv *jEnv, jarray java_array, jsize in
|
||||
case JAVA_SIGNATURE_CLASS:
|
||||
case JAVA_SIGNATURE_ARRAY:
|
||||
(*jEnv)->SetObjectArrayElement(jEnv, java_array, index, java_value.l);
|
||||
if (is_local_ref) \
|
||||
(*jEnv)->DeleteLocalRef(jEnv, java_value.l);
|
||||
if ((*jEnv)->ExceptionOccurred(jEnv)) {
|
||||
jsj_ReportJavaError(cx, jEnv, "Error assigning to Java object array");
|
||||
return JS_FALSE;
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
@@ -30,12 +30,17 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "prprintf.h"
|
||||
#include "prassert.h"
|
||||
|
||||
#include "jsj_private.h" /* LiveConnect internals */
|
||||
#include "jsj_hash.h" /* Hash tables */
|
||||
|
||||
#include "prhash.h" /* Hash tables */
|
||||
|
||||
/* A one-to-one mapping between all referenced java.lang.Class objects and
|
||||
their corresponding JavaClassDescriptor objects */
|
||||
static JSJHashTable *java_class_reflections;
|
||||
static PRHashTable *java_class_reflections;
|
||||
|
||||
/*
|
||||
* Given a JVM handle to a java.lang.Class object, malloc a C-string
|
||||
@@ -274,9 +279,6 @@ destroy_java_member_descriptor(JSContext *cx, JNIEnv *jEnv, JavaMemberDescriptor
|
||||
jsj_DestroyMethodSpec(cx, jEnv, method);
|
||||
method = next_method;
|
||||
}
|
||||
|
||||
if (member_descriptor->invoke_func_obj)
|
||||
JS_RemoveRoot(cx, &member_descriptor->invoke_func_obj);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -296,9 +298,8 @@ destroy_class_descriptor(JSContext *cx, JNIEnv *jEnv, JavaClassDescriptor *class
|
||||
{
|
||||
JS_FREE_IF(cx, (char *)class_descriptor->name);
|
||||
if (class_descriptor->java_class) {
|
||||
JSJ_HashTableRemove(java_class_reflections,
|
||||
class_descriptor->java_class, (void*)jEnv);
|
||||
(*jEnv)->DeleteGlobalRef(jEnv, class_descriptor->java_class);
|
||||
PR_HashTableRemove(java_class_reflections, class_descriptor->java_class);
|
||||
}
|
||||
|
||||
if (class_descriptor->array_component_signature)
|
||||
@@ -326,7 +327,7 @@ new_class_descriptor(JSContext *cx, JNIEnv *jEnv, jclass java_class)
|
||||
|
||||
java_class = (*jEnv)->NewGlobalRef(jEnv, java_class);
|
||||
if (!java_class) {
|
||||
jsj_UnexpectedJavaError(cx, jEnv, "Unable to reference Java class");
|
||||
jsj_ReportJavaError(cx, jEnv, "Unable to reference Java class");
|
||||
goto error;
|
||||
}
|
||||
class_descriptor->java_class = java_class;
|
||||
@@ -338,8 +339,7 @@ new_class_descriptor(JSContext *cx, JNIEnv *jEnv, jclass java_class)
|
||||
(*jEnv)->CallIntMethod(jEnv, java_class, jlClass_getModifiers);
|
||||
class_descriptor->ref_count = 1;
|
||||
|
||||
if (!JSJ_HashTableAdd(java_class_reflections, java_class, class_descriptor,
|
||||
(void*)jEnv))
|
||||
if (!PR_HashTableAdd(java_class_reflections, java_class, class_descriptor))
|
||||
goto error;
|
||||
|
||||
return class_descriptor;
|
||||
@@ -349,45 +349,12 @@ error:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Trivial helper for jsj_DiscardJavaClassReflections(), below */
|
||||
static PRIntn
|
||||
enumerate_remove_java_class(JSJHashEntry *he, PRIntn i, void *arg)
|
||||
{
|
||||
JNIEnv *jEnv = (JNIEnv*)arg;
|
||||
jclass java_class;
|
||||
JavaClassDescriptor *class_descriptor;
|
||||
|
||||
class_descriptor = (JavaClassDescriptor*)he->value;
|
||||
|
||||
java_class = class_descriptor->java_class;
|
||||
(*jEnv)->DeleteGlobalRef(jEnv, java_class);
|
||||
class_descriptor->java_class = NULL;
|
||||
|
||||
return HT_ENUMERATE_REMOVE;
|
||||
}
|
||||
|
||||
/* This shutdown routine discards all JNI references to Java objects
|
||||
that have been reflected into JS, even if there are still references
|
||||
to them from JS. */
|
||||
void
|
||||
jsj_DiscardJavaClassReflections(JNIEnv *jEnv)
|
||||
{
|
||||
if (java_class_reflections) {
|
||||
JSJ_HashTableEnumerateEntries(java_class_reflections,
|
||||
enumerate_remove_java_class,
|
||||
(void*)jEnv);
|
||||
JSJ_HashTableDestroy(java_class_reflections);
|
||||
java_class_reflections = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern JavaClassDescriptor *
|
||||
jsj_GetJavaClassDescriptor(JSContext *cx, JNIEnv *jEnv, jclass java_class)
|
||||
{
|
||||
JavaClassDescriptor *class_descriptor;
|
||||
class_descriptor = JSJ_HashTableLookup(java_class_reflections,
|
||||
(const void *)java_class,
|
||||
(void*)jEnv);
|
||||
class_descriptor = PR_HashTableLookup(java_class_reflections,
|
||||
(const void *)java_class);
|
||||
if (!class_descriptor)
|
||||
return new_class_descriptor(cx, jEnv, java_class);
|
||||
|
||||
@@ -596,8 +563,8 @@ JSBool
|
||||
jsj_InitJavaClassReflectionsTable()
|
||||
{
|
||||
java_class_reflections =
|
||||
JSJ_NewHashTable(64, jsj_HashJavaObject, jsj_JavaObjectComparator,
|
||||
NULL, NULL, NULL);
|
||||
PR_NewHashTable(64, jsj_HashJavaObject, jsj_JavaObjectComparator,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
if (!java_class_reflections)
|
||||
return JS_FALSE;
|
||||
@@ -26,27 +26,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "prprintf.h"
|
||||
#include "prassert.h"
|
||||
|
||||
#include "jsj_private.h" /* LiveConnect internals */
|
||||
|
||||
/* Floating-point double utilities, stolen from jsnum.h */
|
||||
#ifdef IS_LITTLE_ENDIAN
|
||||
#define JSDOUBLE_HI32(x) (((uint32 *)&(x))[1])
|
||||
#define JSDOUBLE_LO32(x) (((uint32 *)&(x))[0])
|
||||
#else
|
||||
#define JSDOUBLE_HI32(x) (((uint32 *)&(x))[0])
|
||||
#define JSDOUBLE_LO32(x) (((uint32 *)&(x))[1])
|
||||
#endif
|
||||
#define JSDOUBLE_HI32_SIGNBIT 0x80000000
|
||||
#define JSDOUBLE_HI32_EXPMASK 0x7ff00000
|
||||
#define JSDOUBLE_HI32_MANTMASK 0x000fffff
|
||||
|
||||
#define JSDOUBLE_IS_NaN(x) \
|
||||
((JSDOUBLE_HI32(x) & JSDOUBLE_HI32_EXPMASK) == JSDOUBLE_HI32_EXPMASK && \
|
||||
(JSDOUBLE_LO32(x) || (JSDOUBLE_HI32(x) & JSDOUBLE_HI32_MANTMASK)))
|
||||
|
||||
#define JSDOUBLE_IS_INFINITE(x) \
|
||||
((JSDOUBLE_HI32(x) & ~JSDOUBLE_HI32_SIGNBIT) == JSDOUBLE_HI32_EXPMASK && \
|
||||
!JSDOUBLE_LO32(x))
|
||||
|
||||
static JSBool
|
||||
convert_js_obj_to_JSObject_wrapper(JSContext *cx, JNIEnv *jEnv, JSObject *js_obj,
|
||||
@@ -95,19 +80,14 @@ jsj_ConvertJSStringToJavaString(JSContext *cx, JNIEnv *jEnv, JSString *js_str)
|
||||
*/
|
||||
JSBool
|
||||
jsj_ConvertJSValueToJavaObject(JSContext *cx, JNIEnv *jEnv, jsval v, JavaSignature *signature,
|
||||
int *cost, jobject *java_value, JSBool *is_local_refp)
|
||||
int *cost, jobject *java_value)
|
||||
{
|
||||
JSString *jsstr;
|
||||
jclass target_java_class;
|
||||
|
||||
PR_ASSERT(signature->type == JAVA_SIGNATURE_CLASS ||
|
||||
signature->type == JAVA_SIGNATURE_ARRAY);
|
||||
|
||||
/* Initialize to default case, in which no new Java object is
|
||||
synthesized to perform the conversion and, therefore, no JNI local
|
||||
references are being held. */
|
||||
*is_local_refp = JS_FALSE;
|
||||
|
||||
|
||||
/* Get the Java type of the target value */
|
||||
target_java_class = signature->java_class;
|
||||
|
||||
@@ -156,29 +136,27 @@ jsj_ConvertJSValueToJavaObject(JSContext *cx, JNIEnv *jEnv, jsval v, JavaSignatu
|
||||
}
|
||||
|
||||
/* Check if target type is netscape.javascript.JSObject wrapper class */
|
||||
if (convert_js_obj_to_JSObject_wrapper(cx, jEnv, js_obj, signature, cost, java_value)) {
|
||||
if (*java_value)
|
||||
*is_local_refp = JS_TRUE;
|
||||
if (convert_js_obj_to_JSObject_wrapper(cx, jEnv, js_obj, signature, cost, java_value))
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/* Fall through, to attempt conversion to a Java string */
|
||||
|
||||
} else if (JS_InstanceOf(cx, js_obj, &JavaMember_class, 0)) {
|
||||
|
||||
if (!JS_ConvertValue(cx, v, JSTYPE_OBJECT, &v))
|
||||
return JS_FALSE;
|
||||
return jsj_ConvertJSValueToJavaObject(cx, jEnv, v, signature, cost,
|
||||
java_value, is_local_refp);
|
||||
|
||||
} else if (JS_TypeOfValue(cx, v) == JSTYPE_FUNCTION) {
|
||||
/* JS functions can be wrapped as a netscape.javascript.JSObject */
|
||||
if (convert_js_obj_to_JSObject_wrapper(cx, jEnv, js_obj, signature, cost, java_value))
|
||||
return JS_TRUE;
|
||||
|
||||
/* That didn't work, so fall through, to attempt conversion to
|
||||
a java.lang.String ... */
|
||||
|
||||
/* Check for a Java object wrapped inside a JS object */
|
||||
} else {
|
||||
/* Otherwise, see if the target type is the netscape.javascript.JSObject
|
||||
wrapper class or one of its subclasses, in which case a
|
||||
reference is passed to the original JS object by wrapping it
|
||||
inside an instance of netscape.javascript.JSObject */
|
||||
if (convert_js_obj_to_JSObject_wrapper(cx, jEnv, js_obj, signature, cost, java_value)) {
|
||||
if (convert_js_obj_to_JSObject_wrapper(cx, jEnv, js_obj, signature, cost, java_value))
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/* Fall through, to attempt conversion to a Java string */
|
||||
}
|
||||
@@ -191,9 +169,7 @@ jsj_ConvertJSValueToJavaObject(JSContext *cx, JNIEnv *jEnv, jsval v, JavaSignatu
|
||||
if (!JS_ValueToNumber(cx, v, &d))
|
||||
goto conversion_error;
|
||||
*java_value = (*jEnv)->NewObject(jEnv, jlDouble, jlDouble_Double, d);
|
||||
if (*java_value) {
|
||||
*is_local_refp = JS_TRUE;
|
||||
} else {
|
||||
if (!*java_value) {
|
||||
jsj_UnexpectedJavaError(cx, jEnv,
|
||||
"Couldn't construct instance of java.lang.Double");
|
||||
return JS_FALSE;
|
||||
@@ -215,9 +191,7 @@ jsj_ConvertJSValueToJavaObject(JSContext *cx, JNIEnv *jEnv, jsval v, JavaSignatu
|
||||
goto conversion_error;
|
||||
*java_value =
|
||||
(*jEnv)->NewObject(jEnv, jlBoolean, jlBoolean_Boolean, b);
|
||||
if (*java_value) {
|
||||
*is_local_refp = JS_TRUE;
|
||||
} else {
|
||||
if (!*java_value) {
|
||||
jsj_UnexpectedJavaError(cx, jEnv, "Couldn't construct instance "
|
||||
"of java.lang.Boolean");
|
||||
return JS_FALSE;
|
||||
@@ -233,20 +207,15 @@ jsj_ConvertJSValueToJavaObject(JSContext *cx, JNIEnv *jEnv, jsval v, JavaSignatu
|
||||
|
||||
/* If no other conversion is possible, see if the target type is java.lang.String */
|
||||
if ((*jEnv)->IsAssignableFrom(jEnv, jlString, target_java_class)) {
|
||||
#ifdef LIVECONNECT_IMPROVEMENTS
|
||||
JSBool is_string = JSVAL_IS_STRING(v);
|
||||
#endif
|
||||
|
||||
/* Convert to JS string, if necessary, and then to a Java Unicode string */
|
||||
jsstr = JS_ValueToString(cx, v);
|
||||
if (jsstr) {
|
||||
if (java_value) {
|
||||
*java_value = jsj_ConvertJSStringToJavaString(cx, jEnv, jsstr);
|
||||
if (*java_value) {
|
||||
*is_local_refp = JS_TRUE;
|
||||
} else {
|
||||
if (!*java_value)
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
#ifdef LIVECONNECT_IMPROVEMENTS
|
||||
if (!is_string)
|
||||
@@ -260,21 +229,9 @@ conversion_error:
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
/* Valid ranges for Java numeric types */
|
||||
#define jbyte_MAX_VALUE 127.0
|
||||
#define jbyte_MIN_VALUE -128.0
|
||||
#define jchar_MAX_VALUE 65535.0
|
||||
#define jchar_MIN_VALUE 0.0
|
||||
#define jshort_MAX_VALUE 32767.0
|
||||
#define jshort_MIN_VALUE -32768.0
|
||||
#define jint_MAX_VALUE 2147483647.0
|
||||
#define jint_MIN_VALUE -2147483648.0
|
||||
#define jlong_MAX_VALUE 9223372036854775807.0
|
||||
#define jlong_MIN_VALUE -9223372036854775808.0
|
||||
|
||||
/* Utility macro for jsj_ConvertJSValueToJavaValue(), below */
|
||||
#define JSVAL_TO_INTEGRAL_JVALUE(type_name, member_name, member_type, jsval, java_value) \
|
||||
if (!JSVAL_IS_NUMBER(v)) { \
|
||||
if (!JSVAL_IS_NUMBER(v)) { \
|
||||
if (!JS_ConvertValue(cx, v, JSTYPE_NUMBER, &v)) \
|
||||
goto conversion_error; \
|
||||
(*cost)++; \
|
||||
@@ -289,108 +246,20 @@ conversion_error:
|
||||
/* Check to see if the jsval's magnitude is too large to be \
|
||||
representable in the target java type */ \
|
||||
if (member_name != ival) \
|
||||
goto numeric_conversion_error; \
|
||||
goto conversion_error; \
|
||||
} else { \
|
||||
jdouble dval = *JSVAL_TO_DOUBLE(v); \
|
||||
member_name = (member_type) dval; \
|
||||
\
|
||||
/* NaN becomes zero when converted to integral value */ \
|
||||
if (JSDOUBLE_IS_NaN(dval)) \
|
||||
member_name = 0; \
|
||||
\
|
||||
/* Unrepresentably large numbers, including infinities, */ \
|
||||
/* cause an error. */ \
|
||||
else if ((dval > member_type ## _MAX_VALUE) || \
|
||||
(dval < member_type ## _MIN_VALUE)) { \
|
||||
goto numeric_conversion_error; \
|
||||
} else \
|
||||
member_name = (member_type) dval; \
|
||||
\
|
||||
/* Don't allow a non-integral number to be converted \
|
||||
to an integral type */ \
|
||||
/* Actually, we have to allow this for LC1 compatibility */ \
|
||||
/* if ((jdouble)member_name != dval) \
|
||||
(*cost)++; */ \
|
||||
/* Don't allow a non-integral number */ \
|
||||
/* FIXME - should this be an error ? */ \
|
||||
if ((jdouble)member_name != dval) \
|
||||
(*cost)++; \
|
||||
} \
|
||||
if (java_value) \
|
||||
java_value->member_name = member_name; \
|
||||
}
|
||||
|
||||
#if XP_MAC
|
||||
|
||||
/* on MRJ jlong is typedef'd to wide, which is a struct. */
|
||||
#include <Math64.h>
|
||||
|
||||
static jsint jlong_to_jsint(jlong lvalue)
|
||||
{
|
||||
SInt64 val = WideToSInt64(lvalue);
|
||||
return S32Set(val);
|
||||
}
|
||||
|
||||
static jlong jsint_to_jlong(jsint ivalue)
|
||||
{
|
||||
SInt64 val = S64Set(ivalue);
|
||||
wide wval =SInt64ToWide(val);
|
||||
return *(jlong*)&wval;
|
||||
}
|
||||
|
||||
static jdouble jlong_to_jdouble(jlong lvalue)
|
||||
{
|
||||
SInt64 val = WideToSInt64(lvalue);
|
||||
return SInt64ToLongDouble(val);
|
||||
}
|
||||
|
||||
static jlong jdouble_to_jlong(jdouble dvalue)
|
||||
{
|
||||
SInt64 val = LongDoubleToSInt64(dvalue);
|
||||
wide wval = SInt64ToWide(val);
|
||||
return *(jlong*)&wval;
|
||||
}
|
||||
|
||||
/* Mac utility macro for jsj_ConvertJSValueToJavaValue(), below */
|
||||
#define JSVAL_TO_JLONG_JVALUE(member_name, member_type, jsvalue, java_value) \
|
||||
if (!JSVAL_IS_NUMBER(jsvalue)) { \
|
||||
if (!JS_ConvertValue(cx, jsvalue, JSTYPE_NUMBER, &jsvalue)) \
|
||||
goto conversion_error; \
|
||||
(*cost)++; \
|
||||
} \
|
||||
{ \
|
||||
member_type member_name; \
|
||||
\
|
||||
if (JSVAL_IS_INT(jsvalue)) { \
|
||||
jsint ival = JSVAL_TO_INT(jsvalue); \
|
||||
member_name = jsint_to_jlong(ival); \
|
||||
\
|
||||
} else { \
|
||||
jdouble dval = *JSVAL_TO_DOUBLE(jsvalue); \
|
||||
\
|
||||
/* NaN becomes zero when converted to integral value */ \
|
||||
if (JSDOUBLE_IS_NaN(dval)) \
|
||||
member_name = jsint_to_jlong(0); \
|
||||
\
|
||||
/* Unrepresentably large numbers, including infinities, */ \
|
||||
/* cause an error. */ \
|
||||
else if ((dval > member_type ## _MAX_VALUE) || \
|
||||
(dval < member_type ## _MIN_VALUE)) { \
|
||||
goto numeric_conversion_error; \
|
||||
} else \
|
||||
member_name = jdouble_to_jlong(dval); \
|
||||
\
|
||||
/* Don't allow a non-integral number to be converted \
|
||||
to an integral type */ \
|
||||
/* Actually, we have to allow this for LC1 compatibility */ \
|
||||
/*if (jlong_to_jdouble(member_name) != dval) \
|
||||
(*cost)++;*/ \
|
||||
} \
|
||||
if (java_value) \
|
||||
java_value->member_name = member_name; \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define jlong_to_jdouble(lvalue) ((jdouble) lvalue)
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Convert a JS value to a Java value of the given type signature. The cost
|
||||
* variable is incremented if coercion is required, e.g. the source value is
|
||||
@@ -406,17 +275,10 @@ if (!JSVAL_IS_NUMBER(jsvalue)) { \
|
||||
JSBool
|
||||
jsj_ConvertJSValueToJavaValue(JSContext *cx, JNIEnv *jEnv, jsval v,
|
||||
JavaSignature *signature,
|
||||
int *cost, jvalue *java_value, JSBool *is_local_refp)
|
||||
int *cost, jvalue *java_value)
|
||||
{
|
||||
JavaSignatureChar type;
|
||||
JSBool success = JS_FALSE;
|
||||
JavaSignatureChar type = signature->type;
|
||||
|
||||
/* Initialize to default case, in which no new Java object is
|
||||
synthesized to perform the conversion and, therefore, no JNI local
|
||||
references are being held. */
|
||||
*is_local_refp = JS_FALSE;
|
||||
|
||||
type = signature->type;
|
||||
switch (type) {
|
||||
case JAVA_SIGNATURE_BOOLEAN:
|
||||
if (!JSVAL_IS_BOOLEAN(v)) {
|
||||
@@ -449,11 +311,7 @@ jsj_ConvertJSValueToJavaValue(JSContext *cx, JNIEnv *jEnv, jsval v,
|
||||
break;
|
||||
|
||||
case JAVA_SIGNATURE_LONG:
|
||||
#if XP_MAC
|
||||
JSVAL_TO_JLONG_JVALUE(j, jlong, v, java_value);
|
||||
#else
|
||||
JSVAL_TO_INTEGRAL_JVALUE(long, j, jlong, v, java_value);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case JAVA_SIGNATURE_FLOAT:
|
||||
@@ -486,8 +344,7 @@ jsj_ConvertJSValueToJavaValue(JSContext *cx, JNIEnv *jEnv, jsval v,
|
||||
|
||||
case JAVA_SIGNATURE_CLASS:
|
||||
case JAVA_SIGNATURE_ARRAY:
|
||||
if (!jsj_ConvertJSValueToJavaObject(cx, jEnv, v, signature, cost,
|
||||
&java_value->l, is_local_refp))
|
||||
if (!jsj_ConvertJSValueToJavaObject(cx, jEnv, v, signature, cost, &java_value->l))
|
||||
goto conversion_error;
|
||||
break;
|
||||
|
||||
@@ -499,10 +356,6 @@ jsj_ConvertJSValueToJavaValue(JSContext *cx, JNIEnv *jEnv, jsval v,
|
||||
/* Success */
|
||||
return JS_TRUE;
|
||||
|
||||
numeric_conversion_error:
|
||||
success = JS_TRUE;
|
||||
/* Fall through ... */
|
||||
|
||||
conversion_error:
|
||||
|
||||
if (java_value) {
|
||||
@@ -519,9 +372,8 @@ conversion_error:
|
||||
JS_ReportError(cx, "Unable to convert JavaScript value %s to "
|
||||
"Java value of type %s",
|
||||
jsval_string, signature->name);
|
||||
return JS_FALSE;
|
||||
}
|
||||
return success;
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -547,7 +399,7 @@ jsj_ConvertJavaStringToJSString(JSContext *cx, JNIEnv *jEnv, jstring java_str)
|
||||
|
||||
js_str = NULL;
|
||||
|
||||
/* The string data passed into JS_NewUCString() is
|
||||
/* Unlike JS_NewString(), the string data passed into JS_NewUCString() is
|
||||
not copied, so make a copy of the Unicode character vector. */
|
||||
num_bytes = ucs2_str_len * sizeof(jchar);
|
||||
copy_ucs2_str = (jchar*)JS_malloc(cx, num_bytes);
|
||||
@@ -621,23 +473,27 @@ jsj_ConvertJavaObjectToJSString(JSContext *cx,
|
||||
*/
|
||||
JSBool
|
||||
jsj_ConvertJavaObjectToJSNumber(JSContext *cx, JNIEnv *jEnv,
|
||||
JavaClassDescriptor *class_descriptor,
|
||||
jobject java_obj, jsval *vp)
|
||||
{
|
||||
jdouble d;
|
||||
jmethodID doubleValue;
|
||||
jclass java_class;
|
||||
|
||||
java_class = class_descriptor->java_class;
|
||||
doubleValue = (*jEnv)->GetMethodID(jEnv, java_class, "doubleValue", "()D");
|
||||
if (!doubleValue) {
|
||||
/* There is no doubleValue() method for the object. Try toString()
|
||||
instead and the JS engine will attempt to convert the result to
|
||||
a number. */
|
||||
(*jEnv)->ExceptionClear(jEnv);
|
||||
return jsj_ConvertJavaObjectToJSString(cx, jEnv, class_descriptor,
|
||||
java_obj, vp);
|
||||
}
|
||||
#ifndef SUN_VM_IS_NOT_GARBAGE
|
||||
/* Late breaking news: calling GetMethodID() on an object that doesn't
|
||||
contain the given method may cause the Sun VM to crash. So we only
|
||||
call the method on instances of java.lang.Double */
|
||||
JSBool is_Double;
|
||||
|
||||
/* Make sure that we have a java.lang.Double */
|
||||
is_Double = (*jEnv)->IsInstanceOf(jEnv, java_obj, jlDouble);
|
||||
if (!is_Double)
|
||||
return JS_FALSE;
|
||||
doubleValue = jlDouble_doubleValue;
|
||||
#else
|
||||
doubleValue = (*jEnv)->GetMethodID(jEnv, java_obj, "doubleValue", "()D");
|
||||
if (!doubleValue)
|
||||
return JS_FALSE;
|
||||
#endif
|
||||
|
||||
d = (*jEnv)->CallDoubleMethod(jEnv, java_obj, doubleValue);
|
||||
if ((*jEnv)->ExceptionOccurred(jEnv)) {
|
||||
@@ -658,28 +514,28 @@ jsj_ConvertJavaObjectToJSNumber(JSContext *cx, JNIEnv *jEnv,
|
||||
*/
|
||||
extern JSBool
|
||||
jsj_ConvertJavaObjectToJSBoolean(JSContext *cx, JNIEnv *jEnv,
|
||||
JavaClassDescriptor *class_descriptor,
|
||||
jobject java_obj, jsval *vp)
|
||||
{
|
||||
jboolean b;
|
||||
jmethodID booleanValue;
|
||||
jclass java_class;
|
||||
|
||||
/* Null converts to false. */
|
||||
if (!java_obj) {
|
||||
*vp = JSVAL_FALSE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
java_class = class_descriptor->java_class;
|
||||
booleanValue = (*jEnv)->GetMethodID(jEnv, java_obj, "booleanValue", "()Z");
|
||||
#ifndef SUN_VM_IS_NOT_GARBAGE
|
||||
/* Late breaking news: calling GetMethodID() on an object that doesn't
|
||||
contain the given method may cause the Sun VM to crash. So we only
|
||||
call the method on instances of java.lang.Boolean */
|
||||
|
||||
JSBool is_Boolean;
|
||||
|
||||
/* Non-null Java object does not have a booleanValue() method, so
|
||||
it converts to true. */
|
||||
if (!booleanValue) {
|
||||
(*jEnv)->ExceptionClear(jEnv);
|
||||
*vp = JSVAL_TRUE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
/* Make sure that we have a java.lang.Boolean */
|
||||
is_Boolean = (*jEnv)->IsInstanceOf(jEnv, java_obj, jlBoolean);
|
||||
if (!is_Boolean)
|
||||
return JS_FALSE;
|
||||
booleanValue = jlBoolean_booleanValue;
|
||||
#else
|
||||
booleanValue = (*jEnv)->GetMethodID(jEnv, java_obj, "booleanValue", "()Z");
|
||||
if (!booleanValue)
|
||||
return JS_FALSE;
|
||||
#endif
|
||||
|
||||
b = (*jEnv)->CallBooleanMethod(jEnv, java_obj, booleanValue);
|
||||
if ((*jEnv)->ExceptionOccurred(jEnv)) {
|
||||
@@ -715,11 +571,7 @@ jsj_ConvertJavaObjectToJSValue(JSContext *cx, JNIEnv *jEnv,
|
||||
* it to obtain the original JS object.
|
||||
*/
|
||||
if (njJSObject && (*jEnv)->IsInstanceOf(jEnv, java_obj, njJSObject)) {
|
||||
#ifdef PRESERVE_JSOBJECT_IDENTITY
|
||||
js_obj = (JSObject *)((*jEnv)->GetIntField(jEnv, java_obj, njJSObject_internal));
|
||||
#else
|
||||
js_obj = jsj_UnwrapJSObjectWrapper(jEnv, java_obj);
|
||||
#endif
|
||||
PR_ASSERT(js_obj);
|
||||
if (!js_obj)
|
||||
return JS_FALSE;
|
||||
@@ -786,7 +638,7 @@ jsj_ConvertJavaValueToJSValue(JSContext *cx, JNIEnv *jEnv,
|
||||
return JS_TRUE;
|
||||
|
||||
case JAVA_SIGNATURE_LONG:
|
||||
return JS_NewDoubleValue(cx, jlong_to_jdouble(java_value->j), vp);
|
||||
return JS_NewDoubleValue(cx, (jsdouble)java_value->j, vp);
|
||||
|
||||
case JAVA_SIGNATURE_FLOAT:
|
||||
return JS_NewDoubleValue(cx, java_value->f, vp);
|
||||
@@ -26,6 +26,9 @@
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "prtypes.h"
|
||||
#include "prprintf.h"
|
||||
#include "prassert.h"
|
||||
|
||||
#include "jsj_private.h" /* LiveConnect internals */
|
||||
|
||||
@@ -246,7 +249,7 @@ jsj_GetJavaFieldValue(JSContext *cx, JNIEnv *jEnv, JavaFieldSpec *field_spec,
|
||||
java_value.member = \
|
||||
(*jEnv)->Get##Type##Field(jEnv, java_obj, fieldID); \
|
||||
if ((*jEnv)->ExceptionOccurred(jEnv)) { \
|
||||
jsj_UnexpectedJavaError(cx, jEnv, "Error reading Java field"); \
|
||||
jsj_ReportJavaError(cx, jEnv, "Error reading Java field"); \
|
||||
return JS_FALSE; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
@@ -304,7 +307,7 @@ JSBool
|
||||
jsj_SetJavaFieldValue(JSContext *cx, JNIEnv *jEnv, JavaFieldSpec *field_spec,
|
||||
jclass java_obj, jsval js_val)
|
||||
{
|
||||
JSBool is_static_field, is_local_ref;
|
||||
JSBool is_static_field;
|
||||
int dummy_cost;
|
||||
jvalue java_value;
|
||||
JavaSignature *signature;
|
||||
@@ -322,14 +325,13 @@ jsj_SetJavaFieldValue(JSContext *cx, JNIEnv *jEnv, JavaFieldSpec *field_spec,
|
||||
(*jEnv)->Set##Type##Field(jEnv, java_obj, fieldID,java_value.member);\
|
||||
} \
|
||||
if ((*jEnv)->ExceptionOccurred(jEnv)) { \
|
||||
jsj_UnexpectedJavaError(cx, jEnv, "Error assigning to Java field"); \
|
||||
jsj_ReportJavaError(cx, jEnv, "Error assigning to Java field"); \
|
||||
return JS_FALSE; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
signature = field_spec->signature;
|
||||
if (!jsj_ConvertJSValueToJavaValue(cx, jEnv, js_val, signature, &dummy_cost,
|
||||
&java_value, &is_local_ref))
|
||||
if (!jsj_ConvertJSValueToJavaValue(cx, jEnv, js_val, signature, &dummy_cost, &java_value))
|
||||
return JS_FALSE;
|
||||
|
||||
field_type = signature->type;
|
||||
@@ -369,8 +371,6 @@ jsj_SetJavaFieldValue(JSContext *cx, JNIEnv *jEnv, JavaFieldSpec *field_spec,
|
||||
case JAVA_SIGNATURE_CLASS:
|
||||
case JAVA_SIGNATURE_ARRAY:
|
||||
SET_JAVA_FIELD(Object,l);
|
||||
if (is_local_ref)
|
||||
(*jEnv)->DeleteLocalRef(jEnv, java_value.l);
|
||||
break;
|
||||
|
||||
#undef SET_JAVA_FIELD
|
||||
@@ -28,8 +28,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "prprintf.h"
|
||||
#include "prassert.h"
|
||||
|
||||
#include "jsj_private.h" /* LiveConnect internals */
|
||||
#include "jsjava.h" /* LiveConnect external API */
|
||||
#include "jsjava.h" /* LiveConnect external API */ /* FIXME - get rid of this include */
|
||||
|
||||
/*
|
||||
* A helper function for jsj_ConvertJavaMethodSignatureToString():
|
||||
@@ -317,8 +321,8 @@ jsj_InitJavaMethodSignature(JSContext *cx, JNIEnv *jEnv,
|
||||
|
||||
a = arg_signatures[i] = jsj_GetJavaClassDescriptor(cx, jEnv, arg_class);
|
||||
if (!a) {
|
||||
jsj_UnexpectedJavaError(cx, jEnv, "Could not determine Java class "
|
||||
"signature using java.lang.reflect");
|
||||
jsj_ReportJavaError(cx, jEnv, "Could not determine Java class "
|
||||
"signature using java.lang.reflect");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
@@ -362,14 +366,13 @@ add_java_method_to_class_descriptor(JSContext *cx, JNIEnv *jEnv,
|
||||
JSBool is_constructor)
|
||||
{
|
||||
jmethodID methodID;
|
||||
JSFunction *fun;
|
||||
jclass java_class = class_descriptor->java_class;
|
||||
|
||||
JavaMemberDescriptor *member_descriptor = NULL;
|
||||
const char *sig_cstr = NULL;
|
||||
const char *method_name = NULL;
|
||||
JavaMethodSignature *signature = NULL;
|
||||
JavaMethodSpec **specp, *method_spec = NULL;
|
||||
JavaMethodSpec *method_spec = NULL;
|
||||
|
||||
if (is_constructor) {
|
||||
member_descriptor = jsj_GetJavaClassConstructors(cx, class_descriptor);
|
||||
@@ -378,10 +381,6 @@ add_java_method_to_class_descriptor(JSContext *cx, JNIEnv *jEnv,
|
||||
member_descriptor = jsj_GetJavaStaticMemberDescriptor(cx, jEnv, class_descriptor, method_name_jstr);
|
||||
} else {
|
||||
member_descriptor = jsj_GetJavaMemberDescriptor(cx, jEnv, class_descriptor, method_name_jstr);
|
||||
fun = JS_NewFunction(cx, jsj_JavaInstanceMethodWrapper, 0,
|
||||
JSFUN_BOUND_METHOD, NULL, member_descriptor->name);
|
||||
member_descriptor->invoke_func_obj = JS_GetFunctionObject(fun);
|
||||
JS_AddRoot(cx, &member_descriptor->invoke_func_obj);
|
||||
}
|
||||
}
|
||||
if (!member_descriptor)
|
||||
@@ -420,12 +419,9 @@ add_java_method_to_class_descriptor(JSContext *cx, JNIEnv *jEnv,
|
||||
|
||||
JS_free(cx, (char*)sig_cstr);
|
||||
|
||||
/* Add method to end of list of overloaded methods for this class member */
|
||||
specp = &member_descriptor->methods;
|
||||
while (*specp) {
|
||||
specp = &(*specp)->next;
|
||||
}
|
||||
*specp = method_spec;
|
||||
/* Add method to list of overloaded methods for this class member */
|
||||
method_spec->next = member_descriptor->methods;
|
||||
member_descriptor->methods = method_spec;
|
||||
|
||||
return JS_TRUE;
|
||||
|
||||
@@ -548,15 +544,13 @@ method_signature_matches_JS_args(JSContext *cx, JNIEnv *jEnv, uintN argc, jsval
|
||||
{
|
||||
uintN i;
|
||||
JavaSignature *arg_signature;
|
||||
JSBool dummy_bool;
|
||||
|
||||
if (argc != (uintN)method_signature->num_args)
|
||||
return JS_FALSE;
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
arg_signature = method_signature->arg_signatures[i];
|
||||
if (!jsj_ConvertJSValueToJavaValue(cx, jEnv, argv[i], arg_signature, cost,
|
||||
NULL, &dummy_bool))
|
||||
if (!jsj_ConvertJSValueToJavaValue(cx, jEnv, argv[i], arg_signature, cost, NULL))
|
||||
return JS_FALSE;
|
||||
}
|
||||
return JS_TRUE;
|
||||
@@ -680,16 +674,11 @@ resolve_overloaded_method(JSContext *cx, JNIEnv *jEnv, JavaMemberDescriptor *mem
|
||||
if (!method_signature_matches_JS_args(cx, jEnv, argc, argv, &method->signature, &cost))
|
||||
continue;
|
||||
|
||||
#if 1
|
||||
if (cost < lowest_cost) {
|
||||
lowest_cost = cost;
|
||||
best_method_match = method;
|
||||
num_method_matches++;
|
||||
}
|
||||
#else
|
||||
best_method_match = method;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!best_method_match)
|
||||
@@ -710,10 +699,10 @@ resolve_overloaded_method(JSContext *cx, JNIEnv *jEnv, JavaMemberDescriptor *mem
|
||||
|
||||
static jvalue *
|
||||
convert_JS_method_args_to_java_argv(JSContext *cx, JNIEnv *jEnv, jsval *argv,
|
||||
JavaMethodSpec *method, JSBool **localvp)
|
||||
JavaMethodSpec *method)
|
||||
{
|
||||
jvalue *jargv;
|
||||
JSBool ok, *localv;
|
||||
JSBool ok;
|
||||
uintN i, argc;
|
||||
JavaSignature **arg_signatures;
|
||||
JavaMethodSignature *signature;
|
||||
@@ -728,29 +717,15 @@ convert_JS_method_args_to_java_argv(JSContext *cx, JNIEnv *jEnv, jsval *argv,
|
||||
|
||||
if (!jargv)
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* Allocate an array that contains a flag for each argument, indicating whether
|
||||
* or not the conversion from a JS value to a Java value resulted in a new
|
||||
* JNI local reference.
|
||||
*/
|
||||
localv = (JSBool *)JS_malloc(cx, sizeof(JSBool) * argc);
|
||||
*localvp = localv;
|
||||
if (!localv) {
|
||||
JS_free(cx, jargv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
int dummy_cost;
|
||||
|
||||
ok = jsj_ConvertJSValueToJavaValue(cx, jEnv, argv[i], arg_signatures[i],
|
||||
&dummy_cost, &jargv[i], &localv[i]);
|
||||
&dummy_cost, &jargv[i]);
|
||||
if (!ok) {
|
||||
JS_ReportError(cx, "Internal error: can't convert JS value to Java value");
|
||||
JS_free(cx, jargv);
|
||||
JS_free(cx, localv);
|
||||
*localvp = NULL;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@@ -762,13 +737,13 @@ static JSBool
|
||||
invoke_java_method(JSContext *cx, JSJavaThreadState *jsj_env,
|
||||
jobject java_class_or_instance,
|
||||
JavaClassDescriptor *class_descriptor,
|
||||
JavaMethodSpec *method,
|
||||
JavaMethodSpec *method,
|
||||
JSBool is_static_method,
|
||||
jsval *argv, jsval *vp)
|
||||
jsval *argv, jsval *vp)
|
||||
{
|
||||
jvalue java_value;
|
||||
jvalue *jargv;
|
||||
uintN argc, i;
|
||||
uintN argc;
|
||||
jobject java_object;
|
||||
jclass java_class;
|
||||
jmethodID methodID;
|
||||
@@ -776,9 +751,6 @@ invoke_java_method(JSContext *cx, JSJavaThreadState *jsj_env,
|
||||
JavaSignature *return_val_signature;
|
||||
JSContext *old_cx;
|
||||
JNIEnv *jEnv;
|
||||
JSBool *localv, error_occurred;
|
||||
|
||||
error_occurred = JS_FALSE;
|
||||
|
||||
methodID = method->methodID;
|
||||
signature = &method->signature;
|
||||
@@ -794,23 +766,11 @@ invoke_java_method(JSContext *cx, JSJavaThreadState *jsj_env,
|
||||
java_class = NULL;
|
||||
}
|
||||
|
||||
old_cx = JSJ_SetDefaultJSContextForJavaThread(cx, jsj_env);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (old_cx && (old_cx != cx)) {
|
||||
JS_ReportError(cx, "Java thread in simultaneous use by more than "
|
||||
"one JSContext ?");
|
||||
}
|
||||
#endif
|
||||
|
||||
jargv = NULL;
|
||||
localv = NULL;
|
||||
if (argc) {
|
||||
jargv = convert_JS_method_args_to_java_argv(cx, jEnv, argv, method, &localv);
|
||||
if (!jargv) {
|
||||
error_occurred = JS_TRUE;
|
||||
goto out;
|
||||
}
|
||||
jargv = convert_JS_method_args_to_java_argv(cx, jEnv, argv, method);
|
||||
if (!jargv)
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
#define CALL_JAVA_METHOD(type, member) \
|
||||
@@ -823,11 +783,16 @@ invoke_java_method(JSContext *cx, JSJavaThreadState *jsj_env,
|
||||
if ((*jEnv)->ExceptionOccurred(jEnv)) { \
|
||||
jsj_ReportJavaError(cx, jEnv, "Error calling method %s.%s()", \
|
||||
class_descriptor->name, method->name); \
|
||||
error_occurred = JS_TRUE; \
|
||||
goto out; \
|
||||
goto error; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
old_cx = JSJ_SetDefaultJSContextForJavaThread(cx, jsj_env);
|
||||
if (old_cx) {
|
||||
JS_ReportError(cx, "Java thread in simultaneous use by more than "
|
||||
"one JSContext ?");
|
||||
}
|
||||
|
||||
return_val_signature = signature->return_val_signature;
|
||||
switch(return_val_signature->type) {
|
||||
case JAVA_SIGNATURE_BYTE:
|
||||
@@ -875,8 +840,7 @@ invoke_java_method(JSContext *cx, JSJavaThreadState *jsj_env,
|
||||
if ((*jEnv)->ExceptionOccurred(jEnv)) {
|
||||
jsj_ReportJavaError(cx, jEnv, "Error calling method %s.%s()",
|
||||
class_descriptor->name, method->name);
|
||||
error_occurred = JS_TRUE;
|
||||
goto out;
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -885,23 +849,16 @@ invoke_java_method(JSContext *cx, JSJavaThreadState *jsj_env,
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
out:
|
||||
if (jargv)
|
||||
JS_free(cx, jargv);
|
||||
JSJ_SetDefaultJSContextForJavaThread(old_cx, jsj_env);
|
||||
|
||||
if (localv) {
|
||||
for (i = 0; i < argc; i++) {
|
||||
if (localv[i])
|
||||
(*jEnv)->DeleteLocalRef(jEnv, jargv[i].l);
|
||||
}
|
||||
JS_free(cx, localv);
|
||||
}
|
||||
return jsj_ConvertJavaValueToJSValue(cx, jEnv, return_val_signature, &java_value, vp);
|
||||
error:
|
||||
if (jargv)
|
||||
JS_free(cx, jargv);
|
||||
|
||||
if (error_occurred)
|
||||
return JS_FALSE;
|
||||
else
|
||||
return jsj_ConvertJavaValueToJSValue(cx, jEnv, return_val_signature, &java_value, vp);
|
||||
JSJ_SetDefaultJSContextForJavaThread(old_cx, jsj_env);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
@@ -1007,7 +964,7 @@ jsj_JavaInstanceMethodWrapper(JSContext *cx, JSObject *obj,
|
||||
return invoke_overloaded_java_method(cx, jsj_env, member_descriptor, JS_TRUE,
|
||||
java_class, class_descriptor, argc, argv, vp);
|
||||
}
|
||||
jsj_init_js_obj_reflections_table();
|
||||
|
||||
return invoke_overloaded_java_method(cx, jsj_env, member_descriptor,
|
||||
JS_FALSE, java_obj,
|
||||
class_descriptor, argc, argv, vp);
|
||||
@@ -1017,18 +974,16 @@ static JSBool
|
||||
invoke_java_constructor(JSContext *cx,
|
||||
JSJavaThreadState *jsj_env,
|
||||
jclass java_class,
|
||||
JavaMethodSpec *method,
|
||||
jsval *argv, jsval *vp)
|
||||
JavaMethodSpec *method,
|
||||
jsval *argv, jsval *vp)
|
||||
{
|
||||
jvalue *jargv;
|
||||
uintN argc, i;
|
||||
uintN argc;
|
||||
jobject java_object;
|
||||
jmethodID methodID;
|
||||
JavaMethodSignature *signature;
|
||||
JSContext *old_cx;
|
||||
JNIEnv *jEnv;
|
||||
JSBool *localv;
|
||||
JSBool error_occurred = JS_FALSE;
|
||||
|
||||
methodID = method->methodID;
|
||||
signature = &method->signature;
|
||||
@@ -1037,25 +992,18 @@ invoke_java_constructor(JSContext *cx,
|
||||
jEnv = jsj_env->jEnv;
|
||||
|
||||
jargv = NULL;
|
||||
localv = NULL;
|
||||
if (argc) {
|
||||
jargv = convert_JS_method_args_to_java_argv(cx, jEnv, argv, method, &localv);
|
||||
if (!jargv) {
|
||||
error_occurred = JS_TRUE;
|
||||
goto out;
|
||||
}
|
||||
jargv = convert_JS_method_args_to_java_argv(cx, jEnv, argv, method);
|
||||
if (!jargv)
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
old_cx = JSJ_SetDefaultJSContextForJavaThread(cx, jsj_env);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (old_cx && (old_cx != cx)) {
|
||||
if (old_cx) {
|
||||
JS_ReportError(cx, "Java thread in simultaneous use by more than "
|
||||
"one JSContext ?");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Call the constructor */
|
||||
java_object = (*jEnv)->NewObjectA(jEnv, java_class, methodID, jargv);
|
||||
|
||||
JSJ_SetDefaultJSContextForJavaThread(old_cx, jsj_env);
|
||||
@@ -1063,25 +1011,18 @@ invoke_java_constructor(JSContext *cx,
|
||||
if (!java_object) {
|
||||
jsj_ReportJavaError(cx, jEnv, "Error while constructing instance of %s",
|
||||
jsj_GetJavaClassName(cx, jEnv, java_class));
|
||||
error_occurred = JS_TRUE;
|
||||
goto out;
|
||||
goto error;
|
||||
}
|
||||
|
||||
out:
|
||||
if (localv) {
|
||||
for (i = 0; i < argc; i++) {
|
||||
if (localv[i])
|
||||
(*jEnv)->DeleteLocalRef(jEnv, jargv[i].l);
|
||||
}
|
||||
JS_free(cx, localv);
|
||||
}
|
||||
if (jargv)
|
||||
JS_free(cx, jargv);
|
||||
|
||||
return jsj_ConvertJavaObjectToJSValue(cx, jEnv, java_object, vp);
|
||||
|
||||
error:
|
||||
if (jargv)
|
||||
JS_free(cx, jargv);
|
||||
|
||||
if (error_occurred)
|
||||
return JS_FALSE;
|
||||
else
|
||||
return jsj_ConvertJavaObjectToJSValue(cx, jEnv, java_object, vp);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
@@ -29,28 +29,9 @@
|
||||
#ifndef _JSJAVA_PVT_H
|
||||
#define _JSJAVA_PVT_H
|
||||
|
||||
#include "prtypes.h"
|
||||
|
||||
/* NSPR1 compatibility definitions */
|
||||
#ifdef NSPR20
|
||||
# include "prprf.h"
|
||||
# include "prlog.h"
|
||||
# include "plhash.h" /* NSPR hash-tables */
|
||||
#else
|
||||
# include "prprintf.h"
|
||||
# include "prassert.h"
|
||||
# include "prhash.h" /* NSPR hash-tables */
|
||||
# define PRHashNumber prhashcode
|
||||
#endif
|
||||
|
||||
#ifdef XP_MAC
|
||||
# include "prosdep.h"
|
||||
#endif
|
||||
|
||||
#include "jsj_hash.h" /* Hash tables */
|
||||
#include "prhash.h" /* NSPR hash-tables */
|
||||
#include "jni.h" /* Java Native Interface */
|
||||
#include "jsapi.h" /* JavaScript engine API */
|
||||
#include "jsjava.h" /* LiveConnect public API */
|
||||
|
||||
|
||||
/*************************** Type Declarations ******************************/
|
||||
@@ -60,7 +41,11 @@ typedef struct JavaMemberDescriptor JavaMemberDescriptor;
|
||||
typedef struct JavaMethodSpec JavaMethodSpec;
|
||||
typedef struct JavaClassDescriptor JavaClassDescriptor;
|
||||
typedef struct JavaClassDescriptor JavaSignature;
|
||||
typedef struct JSJCallbacks JSJCallbacks;
|
||||
typedef struct CapturedJSError CapturedJSError;
|
||||
typedef struct JavaPackageDef JavaPackageDef;
|
||||
typedef struct JSJavaThreadState JSJavaThreadState;
|
||||
typedef struct JSJavaVM JSJavaVM;
|
||||
typedef struct JavaMemberVal JavaMemberVal;
|
||||
|
||||
/*
|
||||
@@ -100,12 +85,12 @@ typedef struct JavaFieldSpec {
|
||||
|
||||
/* A descriptor for the reflection of a single Java method.
|
||||
Each overloaded method has a separate corresponding JavaMethodSpec. */
|
||||
struct JavaMethodSpec {
|
||||
typedef struct JavaMethodSpec {
|
||||
jmethodID methodID; /* JVM opaque access handle for method */
|
||||
JavaMethodSignature signature;
|
||||
const char * name; /* UTF8; TODO - Should support Unicode method names */
|
||||
JavaMethodSpec * next; /* next method in chain of overloaded methods */
|
||||
};
|
||||
} JavaMethodSpec;
|
||||
|
||||
/*
|
||||
* A descriptor for the reflection of a single member of a Java object.
|
||||
@@ -114,17 +99,16 @@ struct JavaMethodSpec {
|
||||
* they are overloaded methods sharing the same simple name.) This same
|
||||
* descriptor type is used for both static or instance members.
|
||||
*/
|
||||
struct JavaMemberDescriptor {
|
||||
typedef struct JavaMemberDescriptor {
|
||||
const char * name; /* simple name of field and/or method */
|
||||
jsid id; /* hashed name for quick JS property lookup */
|
||||
JavaFieldSpec * field; /* field with the given name, if any */
|
||||
JavaMethodSpec * methods; /* Overloaded methods which share the same name, if any */
|
||||
JavaMemberDescriptor * next; /* next descriptor in same defining class */
|
||||
JSObject * invoke_func_obj; /* If non-null, JSFunction obj to invoke method */
|
||||
};
|
||||
} JavaMemberDescriptor;
|
||||
|
||||
/* This is the native portion of a reflected Java class */
|
||||
struct JavaClassDescriptor {
|
||||
typedef struct JavaClassDescriptor {
|
||||
const char * name; /* Name of class, e.g. "java/lang/Byte" */
|
||||
JavaSignatureChar type; /* class category: primitive type, object, array */
|
||||
jclass java_class; /* Opaque JVM handle to corresponding java.lang.Class */
|
||||
@@ -139,20 +123,21 @@ struct JavaClassDescriptor {
|
||||
e.g. abstract, private */
|
||||
int ref_count; /* # of references to this struct */
|
||||
JavaSignature * array_component_signature; /* Only non-NULL for array classes */
|
||||
};
|
||||
} JavaClassDescriptor;
|
||||
|
||||
/* This is the native portion of a reflected Java method or field */
|
||||
struct JavaMemberVal {
|
||||
typedef struct JavaMemberVal {
|
||||
jsval field_val; /* Captured value of Java field */
|
||||
jsval invoke_method_func_val; /* JSFunction wrapper around Java method invoker */
|
||||
JavaMemberDescriptor * descriptor;
|
||||
JavaMemberVal * next;
|
||||
};
|
||||
} JavaMemberVal;
|
||||
|
||||
/* This is the native portion of a reflected Java object */
|
||||
typedef struct JavaObjectWrapper {
|
||||
typedef struct {
|
||||
jobject java_obj; /* Opaque JVM ref to Java object */
|
||||
JavaClassDescriptor * class_descriptor; /* Java class info */
|
||||
JavaMemberVal * members; /* Reflected methods and fields */
|
||||
} JavaObjectWrapper;
|
||||
|
||||
/* These are definitions of the Java class/method/field modifier bits.
|
||||
@@ -166,44 +151,36 @@ typedef struct JavaObjectWrapper {
|
||||
|
||||
/* A JSJavaVM structure must be created for each Java VM that is accessed
|
||||
via LiveConnect */
|
||||
struct JSJavaVM {
|
||||
typedef struct JSJavaVM {
|
||||
/* TODO - all LiveConnect global variables should be migrated into this
|
||||
structure in order to allow more than one LiveConnect-enabled
|
||||
Java VM to exist within the same process. */
|
||||
SystemJavaVM * java_vm;
|
||||
JavaVM * java_vm;
|
||||
JNIEnv * main_thread_env; /* Main-thread Java environment */
|
||||
JSBool jsj_created_java_vm;
|
||||
int num_attached_threads;
|
||||
JSJavaVM * next; /* next VM among all created VMs */
|
||||
};
|
||||
} JSJavaVM;
|
||||
|
||||
/* Per-thread state that encapsulates the connection to the Java VM */
|
||||
struct JSJavaThreadState {
|
||||
typedef struct JSJavaThreadState {
|
||||
const char * name; /* Thread name, for debugging */
|
||||
JSJavaVM * jsjava_vm; /* All per-JVM state */
|
||||
JNIEnv * jEnv; /* Per-thread opaque handle to Java VM */
|
||||
CapturedJSError * pending_js_errors; /* JS errors to be thrown as Java exceptions */
|
||||
JSContext * cx; /* current JS context for thread */
|
||||
JSJavaThreadState * next; /* next thread state among all created threads */
|
||||
};
|
||||
|
||||
struct JavaToJSSavedState {
|
||||
JSErrorReporter error_reporter;
|
||||
JSJavaThreadState* java_jsj_env;
|
||||
};
|
||||
typedef struct JavaToJSSavedState JavaToJSSavedState;
|
||||
|
||||
|
||||
} JSJavaThreadState;
|
||||
|
||||
/******************************** Globals ***********************************/
|
||||
|
||||
extern JNIEnv *jENV;
|
||||
extern JSJCallbacks *JSJ_callbacks;
|
||||
|
||||
/* JavaScript classes that reflect Java objects */
|
||||
extern JSClass JavaObject_class;
|
||||
extern JSClass JavaArray_class;
|
||||
extern JSClass JavaClass_class;
|
||||
extern JSClass JavaMember_class;
|
||||
|
||||
/*
|
||||
* Opaque JVM handles to Java classes, methods and objects required for
|
||||
@@ -291,10 +268,10 @@ jsj_PurgeJavaMethodSignature(JSContext *cx, JNIEnv *jEnv, JavaMethodSignature *s
|
||||
|
||||
extern JSBool
|
||||
jsj_ConvertJSValueToJavaValue(JSContext *cx, JNIEnv *jEnv, jsval v, JavaSignature *signature,
|
||||
int *cost, jvalue *java_value, JSBool *is_local_refp);
|
||||
int *cost, jvalue *java_value);
|
||||
extern JSBool
|
||||
jsj_ConvertJSValueToJavaObject(JSContext *cx, JNIEnv *jEnv, jsval v, JavaSignature *signature,
|
||||
int *cost, jobject *java_value, JSBool *is_local_refp);
|
||||
int *cost, jobject *java_value);
|
||||
extern jstring
|
||||
jsj_ConvertJSStringToJavaString(JSContext *cx, JNIEnv *jEnv, JSString *js_str);
|
||||
|
||||
@@ -304,36 +281,16 @@ jsj_ConvertJavaValueToJSValue(JSContext *cx, JNIEnv *jEnv, JavaSignature *signat
|
||||
extern JSBool
|
||||
jsj_ConvertJavaObjectToJSValue(JSContext *cx, JNIEnv *jEnv,
|
||||
jobject java_obj, jsval *vp);
|
||||
|
||||
extern JSString *
|
||||
jsj_ConvertJavaStringToJSString(JSContext *cx, JNIEnv *jEnv, jstring java_str);
|
||||
|
||||
extern JSBool
|
||||
jsj_ConvertJavaObjectToJSString(JSContext *cx, JNIEnv *jEnv,
|
||||
JavaClassDescriptor *class_descriptor,
|
||||
jobject java_obj, jsval *vp);
|
||||
extern JSBool
|
||||
jsj_ConvertJavaObjectToJSNumber(JSContext *cx, JNIEnv *jEnv,
|
||||
JavaClassDescriptor *class_descriptor,
|
||||
jobject java_obj, jsval *vp);
|
||||
extern JSBool
|
||||
jsj_ConvertJavaObjectToJSBoolean(JSContext *cx, JNIEnv *jEnv,
|
||||
JavaClassDescriptor *class_descriptor,
|
||||
jobject java_obj, jsval *vp);
|
||||
extern JSJavaThreadState *
|
||||
jsj_enter_js(JNIEnv *jEnv, jobject java_wrapper_obj,
|
||||
JSContext **cxp, JSObject **js_objp, JavaToJSSavedState* saved_state);
|
||||
extern JSBool
|
||||
jsj_exit_js(JSContext *cx, JSJavaThreadState *jsj_env, JavaToJSSavedState* original_state);
|
||||
|
||||
extern JavaClassDescriptor *
|
||||
jsj_get_jlObject_descriptor(JSContext *cx, JNIEnv *jEnv);
|
||||
|
||||
extern JSBool
|
||||
jsj_remove_js_obj_reflection_from_hashtable(JSContext *cx, JSObject *js_obj);
|
||||
|
||||
extern JSBool
|
||||
jsj_init_js_obj_reflections_table();
|
||||
|
||||
/************************ Java package reflection **************************/
|
||||
extern JSBool
|
||||
@@ -344,10 +301,7 @@ jsj_init_JavaPackage(JSContext *, JSObject *,
|
||||
extern JSBool
|
||||
jsj_init_JavaClass(JSContext *cx, JSObject *global_obj);
|
||||
|
||||
extern void
|
||||
jsj_DiscardJavaClassReflections(JNIEnv *jEnv);
|
||||
|
||||
extern const char *
|
||||
const char *
|
||||
jsj_GetJavaClassName(JSContext *cx, JNIEnv *jEnv, jclass java_class);
|
||||
|
||||
extern JavaClassDescriptor *
|
||||
@@ -367,11 +321,21 @@ jsj_GetJavaMemberDescriptor(JSContext *cx,
|
||||
JavaClassDescriptor *class_descriptor,
|
||||
jstring member_name);
|
||||
|
||||
/* extern JavaMemberDescriptor *
|
||||
jsj_LookupJavaClassMember(JSContext *cx,
|
||||
JavaClassDescriptor *class_descriptor,
|
||||
const char *member_name);*/
|
||||
|
||||
extern JavaMemberDescriptor *
|
||||
jsj_LookupJavaMemberDescriptorById(JSContext *cx, JNIEnv *jEnv,
|
||||
JavaClassDescriptor *class_descriptor,
|
||||
jsid id);
|
||||
|
||||
/* extern JavaMemberDescriptor *
|
||||
jsj_LookupJavaStaticMemberDescriptor(JSContext *cx,
|
||||
JavaClassDescriptor *class_descriptor,
|
||||
jstring member_name); */
|
||||
|
||||
extern JavaMemberDescriptor *
|
||||
jsj_LookupJavaStaticMemberDescriptorById(JSContext *cx, JNIEnv *jEnv,
|
||||
JavaClassDescriptor *class_descriptor,
|
||||
@@ -441,9 +405,6 @@ extern JSBool
|
||||
jsj_ReflectJavaMethodsAndFields(JSContext *cx, JavaClassDescriptor *class_descriptor,
|
||||
JSBool reflect_only_statics);
|
||||
|
||||
extern JSObject *
|
||||
jsj_CreateJavaMember(JSContext *cx, jsval method_val, jsval field_val);
|
||||
|
||||
/************************* Java object reflection **************************/
|
||||
extern JSBool
|
||||
jsj_init_JavaObject(JSContext *, JSObject *);
|
||||
@@ -451,9 +412,6 @@ jsj_init_JavaObject(JSContext *, JSObject *);
|
||||
extern JSObject *
|
||||
jsj_WrapJavaObject(JSContext *cx, JNIEnv *jEnv, jobject java_obj, jclass java_class);
|
||||
|
||||
extern void
|
||||
jsj_DiscardJavaObjReflections(JNIEnv *jEnv);
|
||||
|
||||
extern JSBool
|
||||
JavaObject_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp);
|
||||
|
||||
@@ -463,6 +421,9 @@ JavaObject_finalize(JSContext *cx, JSObject *obj);
|
||||
extern JSBool
|
||||
JavaObject_resolve(JSContext *cx, JSObject *obj, jsval id);
|
||||
|
||||
extern JSBool
|
||||
JavaObject_enumerate(JSContext *cx, JSObject *obj);
|
||||
|
||||
extern JSBool
|
||||
JavaObject_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
|
||||
|
||||
@@ -487,9 +448,6 @@ jsj_SetJavaArrayElement(JSContext *cx, JNIEnv *jEnv, jarray java_array,
|
||||
extern jobject
|
||||
jsj_WrapJSObject(JSContext *cx, JNIEnv *jEnv, JSObject *js_obj);
|
||||
|
||||
extern JSObject *
|
||||
jsj_UnwrapJSObjectWrapper(JNIEnv *jEnv, jobject java_wrapper_obj);
|
||||
|
||||
extern void
|
||||
jsj_ClearPendingJSErrors(JSJavaThreadState *jsj_env);
|
||||
|
||||
@@ -509,11 +467,11 @@ jsj_GetJavaErrorMessage(JNIEnv *env);
|
||||
extern void
|
||||
jsj_LogError(const char *error_msg);
|
||||
|
||||
PR_CALLBACK JSJHashNumber
|
||||
jsj_HashJavaObject(const void *key, void* env);
|
||||
PR_CALLBACK prhashcode
|
||||
jsj_HashJavaObject(const void *key);
|
||||
|
||||
PR_CALLBACK intN
|
||||
jsj_JavaObjectComparator(const void *v1, const void *v2, void *arg);
|
||||
jsj_JavaObjectComparator(const void *v1, const void *v2);
|
||||
|
||||
extern JSJavaThreadState *
|
||||
jsj_MapJavaThreadToJSJavaThreadState(JNIEnv *jEnv, char **errp);
|
||||
@@ -536,9 +494,6 @@ jsj_DupJavaStringUTF(JSContext *cx, JNIEnv *jEnv, jstring jstr);
|
||||
JSJavaThreadState *
|
||||
jsj_MapJSContextToJSJThread(JSContext *cx, JNIEnv **envp);
|
||||
|
||||
JSJavaThreadState *
|
||||
jsj_SetJavaJSJEnv(JSJavaThreadState* java_jsj_env);
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DEBUG_LOG(args) printf args
|
||||
#endif
|
||||
@@ -27,6 +27,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "prprintf.h"
|
||||
#include "prassert.h"
|
||||
|
||||
#include "jsj_private.h" /* LiveConnect internals */
|
||||
#include "jsjava.h" /* External LiveConnect API */
|
||||
|
||||
@@ -35,18 +39,16 @@
|
||||
* This is a hash-table utility routine that computes the hash code of a Java
|
||||
* object by calling java.lang.System.identityHashCode()
|
||||
*/
|
||||
PR_CALLBACK JSJHashNumber
|
||||
jsj_HashJavaObject(const void *key, void* env)
|
||||
PR_CALLBACK prhashcode
|
||||
jsj_HashJavaObject(const void *key)
|
||||
{
|
||||
PRHashNumber hash_code;
|
||||
prhashcode hash_code;
|
||||
jobject java_obj;
|
||||
JNIEnv *jEnv;
|
||||
|
||||
java_obj = (jobject)key;
|
||||
jEnv = (JNIEnv*) env;
|
||||
hash_code = (*jEnv)->CallStaticIntMethod(jEnv, jlSystem,
|
||||
hash_code = (*jENV)->CallStaticIntMethod(jENV, jlSystem,
|
||||
jlSystem_identityHashCode, java_obj);
|
||||
PR_ASSERT(!(*jEnv)->ExceptionOccurred(jEnv));
|
||||
PR_ASSERT(!(*jENV)->ExceptionOccurred(jENV));
|
||||
return hash_code;
|
||||
}
|
||||
|
||||
@@ -58,18 +60,16 @@ jsj_HashJavaObject(const void *key, void* env)
|
||||
* use the JNI routine for comparing the two objects.
|
||||
*/
|
||||
PR_CALLBACK intN
|
||||
jsj_JavaObjectComparator(const void *v1, const void *v2, void *arg)
|
||||
jsj_JavaObjectComparator(const void *v1, const void *v2)
|
||||
{
|
||||
jobject java_obj1, java_obj2;
|
||||
JNIEnv *jEnv;
|
||||
|
||||
jEnv = (JNIEnv*)arg;
|
||||
java_obj1 = (jobject)v1;
|
||||
java_obj2 = (jobject)v2;
|
||||
|
||||
if (java_obj1 == java_obj2)
|
||||
return 1;
|
||||
return (*jEnv)->IsSameObject(jEnv, java_obj1, java_obj2);
|
||||
return (*jENV)->IsSameObject(jENV, java_obj1, java_obj2);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -156,7 +156,7 @@ jsj_GetJavaErrorMessage(JNIEnv *jEnv)
|
||||
jstring java_exception_jstring;
|
||||
|
||||
exception = (*jEnv)->ExceptionOccurred(jEnv);
|
||||
if (exception && jlThrowable_toString) {
|
||||
if (exception) {
|
||||
java_exception_jstring =
|
||||
(*jEnv)->CallObjectMethod(jEnv, exception, jlThrowable_toString);
|
||||
java_error_msg = (*jEnv)->GetStringUTFChars(jEnv, java_exception_jstring, NULL);
|
||||
@@ -240,19 +240,19 @@ vreport_java_error(JSContext *cx, JNIEnv *jEnv, const char *format, va_list ap)
|
||||
PR_ASSERT(0); /* Out-of-memory */
|
||||
return;
|
||||
}
|
||||
} else
|
||||
|
||||
#endif
|
||||
{
|
||||
java_error_msg = jsj_GetJavaErrorMessage(jEnv);
|
||||
if (java_error_msg) {
|
||||
error_msg = PR_smprintf("%s (%s)\n", js_error_msg, java_error_msg);
|
||||
free((char*)java_error_msg);
|
||||
free(js_error_msg);
|
||||
} else {
|
||||
error_msg = js_error_msg;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
java_error_msg = jsj_GetJavaErrorMessage(jEnv);
|
||||
if (java_error_msg) {
|
||||
error_msg = PR_smprintf("%s (%s)\n", js_error_msg, java_error_msg);
|
||||
free((char*)java_error_msg);
|
||||
free(js_error_msg);
|
||||
} else {
|
||||
error_msg = js_error_msg;
|
||||
}
|
||||
#endif
|
||||
|
||||
JS_ReportError(cx, error_msg);
|
||||
|
||||
@@ -285,10 +285,9 @@ jsj_UnexpectedJavaError(JSContext *cx, JNIEnv *env, const char *format, ...)
|
||||
|
||||
va_start(ap, format);
|
||||
format2 = PR_smprintf("internal error: %s", format);
|
||||
if (format2) {
|
||||
if (format2)
|
||||
vreport_java_error(cx, env, format2, ap);
|
||||
free((void*)format2);
|
||||
}
|
||||
free((void*)format2);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
@@ -318,8 +317,6 @@ jsj_GetJavaArrayLength(JSContext *cx, JNIEnv *jEnv, jarray java_array)
|
||||
return array_length;
|
||||
}
|
||||
|
||||
static JSJavaThreadState *the_java_jsj_env = NULL;
|
||||
|
||||
JSJavaThreadState *
|
||||
jsj_MapJSContextToJSJThread(JSContext *cx, JNIEnv **envp)
|
||||
{
|
||||
@@ -328,10 +325,7 @@ jsj_MapJSContextToJSJThread(JSContext *cx, JNIEnv **envp)
|
||||
|
||||
*envp = NULL;
|
||||
err_msg = NULL;
|
||||
|
||||
jsj_env = the_java_jsj_env;
|
||||
if (jsj_env == NULL)
|
||||
jsj_env = JSJ_callbacks->map_js_context_to_jsj_thread(cx, &err_msg);
|
||||
jsj_env = JSJ_callbacks->map_js_context_to_jsj_thread(cx, &err_msg);
|
||||
if (!jsj_env) {
|
||||
if (err_msg) {
|
||||
JS_ReportError(cx, err_msg);
|
||||
@@ -343,19 +337,3 @@ jsj_MapJSContextToJSJThread(JSContext *cx, JNIEnv **envp)
|
||||
*envp = jsj_env->jEnv;
|
||||
return jsj_env;
|
||||
}
|
||||
|
||||
/**
|
||||
* Since only one Java thread is allowed to enter JavaScript, this function is
|
||||
* used to enforce the use of that thread's state. The static global the_java_jsj_env
|
||||
* overrides using JSJ_callbacks->map_js_context_to_jsj_thread, which maps
|
||||
* native threads to JSJavaThreadStates. This isn't appropriate when Java calls
|
||||
* JavaScript, as there can be a many to one mapping from Java threads to native
|
||||
* threads.
|
||||
*/
|
||||
JSJavaThreadState *
|
||||
jsj_SetJavaJSJEnv(JSJavaThreadState* java_jsj_env)
|
||||
{
|
||||
JSJavaThreadState *old_jsj_env = the_java_jsj_env;
|
||||
the_java_jsj_env = java_jsj_env;
|
||||
return old_jsj_env;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
@@ -27,12 +27,6 @@
|
||||
#ifndef _JSJAVA_H
|
||||
#define _JSJAVA_H
|
||||
|
||||
#ifndef prtypes_h___
|
||||
#include "prtypes.h"
|
||||
#endif
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
#include "jni.h" /* Java Native Interface */
|
||||
#include "jsapi.h" /* JavaScript engine API */
|
||||
|
||||
@@ -45,14 +39,6 @@ typedef struct JSJavaVM JSJavaVM;
|
||||
/* LiveConnect and Java state, one per thread */
|
||||
typedef struct JSJavaThreadState JSJavaThreadState;
|
||||
|
||||
/*
|
||||
* An opaque type that represents the connection to the Java VM. In stand-alone
|
||||
* Java environments, this may be a JNI JavaVM object; in the browser environment
|
||||
* it is a reference to a JVM plugin. A set of callbacks in the JSJCallbacks
|
||||
* struct allow it to be manipulated.
|
||||
*/
|
||||
typedef struct SystemJavaVM SystemJavaVM;
|
||||
|
||||
/*
|
||||
* This callback table provides hooks to external functions that implement
|
||||
* functionality specific to the embedding. For example, these callbacks are
|
||||
@@ -74,7 +60,6 @@ typedef struct JSJCallbacks {
|
||||
callback can call JSJ_SetJSContextForJavaThread() to avoid any further
|
||||
callbacks of this type for this Java thread. */
|
||||
JSContext * (*map_jsj_thread_to_js_context)(JSJavaThreadState *jsj_env,
|
||||
JNIEnv *jEnv,
|
||||
char **errp);
|
||||
|
||||
/* This callback is invoked whenever a call is made into Java from
|
||||
@@ -89,12 +74,12 @@ typedef struct JSJCallbacks {
|
||||
returns the JS "Window" object corresponding to the HTML window that an
|
||||
applet is embedded within. More generally, it's a way for Java to get
|
||||
hold of a JS object that has not been explicitly passed to it. */
|
||||
JSObject * (*map_java_object_to_js_object)(JNIEnv *jEnv, void *pJavaObject,
|
||||
JSObject * (*map_java_object_to_js_object)(JNIEnv *jEnv, jobject hint,
|
||||
char **errp);
|
||||
|
||||
/* An interim callback function until the LiveConnect security story is
|
||||
straightened out. This function pointer can be set to NULL. */
|
||||
JSPrincipals * (*get_JSPrincipals_from_java_caller)(JNIEnv *jEnv, JSContext *pJSContext);
|
||||
JSPrincipals * (*get_JSPrincipals_from_java_caller)(JNIEnv *jEnv);
|
||||
|
||||
/* The following two callbacks sandwich any JS evaluation performed
|
||||
from Java. They may be used to implement concurrency constraints, e.g.
|
||||
@@ -102,8 +87,8 @@ typedef struct JSJCallbacks {
|
||||
browser embedding, these are used to maintain the run-to-completion
|
||||
semantics of JavaScript. It is acceptable for either function pointer
|
||||
to be NULL. */
|
||||
JSBool (*enter_js_from_java)(JNIEnv *jEnv, char **errp);
|
||||
void (*exit_js)(JNIEnv *jEnv);
|
||||
JSBool (*enter_js_from_java)(char **errp);
|
||||
void (*exit_js)(void);
|
||||
|
||||
/* Most LiveConnect errors are signaled by calling JS_ReportError(), but in
|
||||
some circumstances, the target JSContext for such errors is not
|
||||
@@ -112,18 +97,6 @@ typedef struct JSJCallbacks {
|
||||
NULL, error messages are sent to stderr. */
|
||||
void (*error_print)(const char *error_msg);
|
||||
|
||||
/* This enables liveconnect to ask the VM for a java wrapper so that VM gets a chance to
|
||||
store a mapping between a jsobject and java wrapper. So the unwrapping can be done on the
|
||||
VM side before calling nsILiveconnect apis. This saves on a round trip request. */
|
||||
jobject (*get_java_wrapper)(JNIEnv *jEnv, jint jsobject);
|
||||
|
||||
/* The following set of methods abstract over the JavaVM object. */
|
||||
PRBool (*create_java_vm)(SystemJavaVM* *jvm, JNIEnv* *initialEnv, void* initargs);
|
||||
PRBool (*destroy_java_vm)(SystemJavaVM* jvm, JNIEnv* initialEnv);
|
||||
JNIEnv* (*attach_current_thread)(SystemJavaVM* jvm);
|
||||
PRBool (*detach_current_thread)(SystemJavaVM* jvm, JNIEnv* env);
|
||||
SystemJavaVM* (*get_java_vm)(JNIEnv* env);
|
||||
|
||||
/* Reserved for future use */
|
||||
void * reserved[10];
|
||||
} JSJCallbacks;
|
||||
@@ -131,9 +104,9 @@ typedef struct JSJCallbacks {
|
||||
/*===========================================================================*/
|
||||
|
||||
/* A flag that denotes that a Java package has no sub-packages other than those
|
||||
explicitly pre-defined at the time of initialization. An access
|
||||
explicitly pre-defined at the time of JSContext initialization. An access
|
||||
to a simple name within such a package, therefore, must either correspond to
|
||||
one of these explicitly pre-defined sub-packages or to a class within this
|
||||
one of these explicitly named sub-packages or to a class within this
|
||||
package. It is reasonable for LiveConnect to signal an error if a simple
|
||||
name does not comply with these criteria. */
|
||||
#define PKG_SYSTEM 1
|
||||
@@ -166,12 +139,12 @@ typedef struct JavaPackageDef {
|
||||
as properties of global_obj. If java_vm is NULL, a new Java VM is
|
||||
created, using the provided classpath in addition to any default classpath.
|
||||
The classpath argument is ignored, however, if java_vm is non-NULL. */
|
||||
PR_IMPLEMENT(JSBool)
|
||||
PR_PUBLIC_API(JSBool)
|
||||
JSJ_SimpleInit(JSContext *cx, JSObject *global_obj,
|
||||
SystemJavaVM *java_vm, const char *classpath);
|
||||
JavaVM *java_vm, const char *classpath);
|
||||
|
||||
/* Free up all resources. Destroy the Java VM if it was created by LiveConnect */
|
||||
PR_IMPLEMENT(void)
|
||||
PR_PUBLIC_API(void)
|
||||
JSJ_SimpleShutdown();
|
||||
|
||||
/*===========================================================================*/
|
||||
@@ -193,16 +166,15 @@ JSJ_SimpleShutdown();
|
||||
*/
|
||||
|
||||
/* Called once for all instances of LiveConnect to set up callbacks */
|
||||
PR_IMPLEMENT(void)
|
||||
PR_PUBLIC_API(void)
|
||||
JSJ_Init(JSJCallbacks *callbacks);
|
||||
|
||||
/* Called once per Java VM, this function initializes the classes, fields, and
|
||||
methods required for Java reflection. If java_vm is NULL, a new Java VM is
|
||||
created according to the create_java_vm callback in the JSJCallbacks,
|
||||
using the provided classpath in addition to any default initargs.
|
||||
The initargs argument is ignored, however, if java_vm is non-NULL. */
|
||||
PR_IMPLEMENT(JSJavaVM *)
|
||||
JSJ_ConnectToJavaVM(SystemJavaVM *java_vm, void* initargs);
|
||||
created, using the provided classpath in addition to any default classpath.
|
||||
The classpath argument is ignored, however, if java_vm is non-NULL. */
|
||||
PR_PUBLIC_API(JSJavaVM *)
|
||||
JSJ_ConnectToJavaVM(JavaVM *java_vm, const char *classpath);
|
||||
|
||||
/* Initialize the provided JSContext by setting up the JS classes necessary for
|
||||
reflection and by defining JavaPackage objects for the default Java packages
|
||||
@@ -211,7 +183,7 @@ JSJ_ConnectToJavaVM(SystemJavaVM *java_vm, void* initargs);
|
||||
initialization time is not necessary, but it will make package lookup faster
|
||||
and, more importantly, will avoid unnecessary network accesses if classes
|
||||
are being loaded over the network.) */
|
||||
PR_IMPLEMENT(JSBool)
|
||||
PR_PUBLIC_API(JSBool)
|
||||
JSJ_InitJSContext(JSContext *cx, JSObject *global_obj,
|
||||
JavaPackageDef *predefined_packages);
|
||||
|
||||
@@ -222,19 +194,19 @@ JSJ_InitJSContext(JSContext *cx, JSObject *global_obj,
|
||||
used for debugging purposes and can be set to NULL. The Java JNI
|
||||
environment associated with this thread is returned through the java_envp
|
||||
argument if java_envp is non-NULL. */
|
||||
PR_IMPLEMENT(JSJavaThreadState *)
|
||||
PR_PUBLIC_API(JSJavaThreadState *)
|
||||
JSJ_AttachCurrentThreadToJava(JSJavaVM *jsjava_vm, const char *thread_name,
|
||||
JNIEnv **java_envp);
|
||||
|
||||
/* Destructor routine for per-thread JSJavaThreadState structure */
|
||||
PR_IMPLEMENT(JSBool)
|
||||
PR_PUBLIC_API(JSBool)
|
||||
JSJ_DetachCurrentThreadFromJava(JSJavaThreadState *jsj_env);
|
||||
|
||||
/* This function is used to specify a particular JSContext as *the* JavaScript
|
||||
execution environment to be used when LiveConnect is accessed from the given
|
||||
Java thread, i.e. when one of the methods of netscape.javascript.JSObject
|
||||
has been called. There can only be one such JS context for any given Java
|
||||
thread at a time. (To multiplex JSContexts among a single thread, this
|
||||
thread at a time. To multiplex JSContexts among a single thread, this
|
||||
function could be called before Java is invoked on that thread.) The return
|
||||
value is the previous JSContext associated with the given Java thread.
|
||||
|
||||
@@ -243,22 +215,20 @@ JSJ_DetachCurrentThreadFromJava(JSJavaThreadState *jsj_env);
|
||||
be invoked to determine the JSContext for the thread. The purpose of the
|
||||
function is to improve performance by avoiding the expense of the callback.
|
||||
*/
|
||||
PR_IMPLEMENT(JSContext *)
|
||||
PR_PUBLIC_API(JSContext *)
|
||||
JSJ_SetDefaultJSContextForJavaThread(JSContext *cx, JSJavaThreadState *jsj_env);
|
||||
|
||||
/* This routine severs the connection to a Java VM, freeing all related resources.
|
||||
It shouldn't be called until the global scope has been cleared in all related
|
||||
JSContexts (so that all LiveConnect objects are finalized) and a JavaScript
|
||||
GC is performed. Otherwise, accessed to free'ed memory could result. */
|
||||
PR_IMPLEMENT(void)
|
||||
PR_PUBLIC_API(void)
|
||||
JSJ_DisconnectFromJavaVM(JSJavaVM *);
|
||||
|
||||
/*
|
||||
* Reflect a Java object into a JS value. The source object, java_obj, must
|
||||
* be of type java.lang.Object or a subclass and may, therefore, be an array.
|
||||
*/
|
||||
PR_IMPLEMENT(JSBool)
|
||||
PR_PUBLIC_API(JSBool)
|
||||
JSJ_ConvertJavaObjectToJSValue(JSContext *cx, jobject java_obj, jsval *vp);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
#endif /* _JSJAVA_H */
|
||||
#endif /* _JSJAVA_H */
|
||||
@@ -1,6 +1,5 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include "jni.h"
|
||||
|
||||
#include <jni.h>
|
||||
/* Header for class netscape_javascript_JSObject */
|
||||
|
||||
#ifndef _Included_netscape_javascript_JSObject
|
||||
@@ -1,31 +0,0 @@
|
||||
# This is a list of local files which get copied to the mozilla:dist directory
|
||||
#
|
||||
|
||||
jsapi.h
|
||||
jspubtd.h
|
||||
jsarray.h
|
||||
jsatom.h
|
||||
jsbool.h
|
||||
jscntxt.h
|
||||
jscompat.h
|
||||
jsconfig.h
|
||||
jsdate.h
|
||||
jsdbgapi.h
|
||||
jsemit.h
|
||||
jsfun.h
|
||||
jsgc.h
|
||||
jsinterp.h
|
||||
jslock.h
|
||||
jsmath.h
|
||||
jsnum.h
|
||||
jsobj.h
|
||||
jsopcode.def
|
||||
jsopcode.h
|
||||
jsparse.h
|
||||
jsprvtd.h
|
||||
jspubtd.h
|
||||
jsregexp.h
|
||||
jsscan.h
|
||||
jsscope.h
|
||||
jsscript.h
|
||||
jsstr.h
|
||||
@@ -1,236 +0,0 @@
|
||||
#! gmake
|
||||
# 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.
|
||||
|
||||
DEPTH = ../..
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
ifdef MOZ_OJI
|
||||
DIRS = liveconnect
|
||||
endif
|
||||
|
||||
LIBRARY_NAME = js
|
||||
|
||||
ifeq ($(subst /,_,$(shell uname -s)),OS2)
|
||||
ifndef XCFLAGS
|
||||
OS2_IMPLIB=1
|
||||
LIBRARY = js$(MOZ_BITS)$(VERSION_NUMBER).$(LIB_SUFFIX)
|
||||
DEF_FILE = jsos2$(VERSION_NUMBER).def
|
||||
EXTRA_LIBS = $(LIBNSPR) $(LIBNSJAVA)
|
||||
else
|
||||
EXTRA_LIBS = $(LIBNSPR) $(LIBNSJAVA) $(OBJDIR)/libjs.lib
|
||||
endif
|
||||
endif
|
||||
|
||||
MODULE = js
|
||||
|
||||
CSRCS = jsapi.c \
|
||||
jsarray.c \
|
||||
jsatom.c \
|
||||
jsbool.c \
|
||||
jscntxt.c \
|
||||
jsdate.c \
|
||||
jsdbgapi.c \
|
||||
jsemit.c \
|
||||
jsfun.c \
|
||||
jsgc.c \
|
||||
jsinterp.c \
|
||||
jsmath.c \
|
||||
jsnum.c \
|
||||
jsobj.c \
|
||||
jsopcode.c \
|
||||
jsparse.c \
|
||||
jsregexp.c \
|
||||
jsscan.c \
|
||||
jsscope.c \
|
||||
jsscript.c \
|
||||
jsstr.c \
|
||||
jslock.c \
|
||||
jsxdrapi.c \
|
||||
prmjtime.c \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = jsapi.h \
|
||||
jsarray.h \
|
||||
jsatom.h \
|
||||
jsbool.h \
|
||||
jscntxt.h \
|
||||
jscompat.h \
|
||||
jsconfig.h \
|
||||
jsdate.h \
|
||||
jsdbgapi.h \
|
||||
jsemit.h \
|
||||
jsfun.h \
|
||||
jsgc.h \
|
||||
jsinterp.h \
|
||||
jslock.h \
|
||||
jsmath.h \
|
||||
jsnum.h \
|
||||
jsobj.h \
|
||||
jsopcode.def \
|
||||
jsopcode.h \
|
||||
jsparse.h \
|
||||
jsprvtd.h \
|
||||
jspubtd.h \
|
||||
jsregexp.h \
|
||||
jsscan.h \
|
||||
jsscope.h \
|
||||
jsscript.h \
|
||||
jsstr.h \
|
||||
jsxdrapi.h \
|
||||
$(NULL)
|
||||
|
||||
# when using gcc the assembly is inlined in the C-file (see jslock.c)
|
||||
ifdef NS_USE_NATIVE
|
||||
ASFILES = $(wildcard *_$(OS_ARCH).s)
|
||||
endif
|
||||
|
||||
JS_SAFE_ARENA = 1
|
||||
|
||||
ifdef JS_SAFE_ARENA
|
||||
DEFINES += -DJS_USE_SAFE_ARENA
|
||||
CSRCS += prarena.c
|
||||
endif
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
|
||||
ifndef BUILD_OPT
|
||||
MOCHAFILE = 1
|
||||
endif
|
||||
|
||||
ifdef JSFILE
|
||||
DEFINES += -DJSFILE
|
||||
endif
|
||||
|
||||
ifdef JS_THREADSAFE
|
||||
DEFINES += -DJS_THREADSAFE
|
||||
endif
|
||||
|
||||
ifdef JS_NO_THIN_LOCKS
|
||||
DEFINES += -DJS_USE_ONLY_NSPR_LOCKS
|
||||
endif
|
||||
|
||||
ifdef JS_VERSION
|
||||
DEFINES += -DJS_VERSION=$(JS_VERSION)
|
||||
endif
|
||||
|
||||
ifeq ($(CPU_ARCH),sparc)
|
||||
|
||||
ifndef JS_NO_ULTRA
|
||||
ULTRA_OPTIONS := -xarch=v8plus,-DULTRA_SPARC
|
||||
ULTRA_OPTIONSCC := -DULTRA_SPARC
|
||||
else
|
||||
ULTRA_OPTIONS := -xarch=v8
|
||||
ULTRA_OPTIONSCC :=
|
||||
endif
|
||||
|
||||
ifeq ($(shell uname -m),sun4u)
|
||||
ASFLAGS += -Wa,$(ULTRA_OPTIONS),-P,-L,-D_ASM,-D__STDC__=0 $(ULTRA_OPTIONSCC)
|
||||
else
|
||||
ASFLAGS += -Wa,-xarch=v8,-P,-L,-D_ASM,-D__STDC__=0
|
||||
endif
|
||||
|
||||
endif # sparc
|
||||
|
||||
INCLUDES += -I.
|
||||
|
||||
ifdef NSPR20
|
||||
INCLUDES += -I$(DIST)/include/nspr20/pr
|
||||
else
|
||||
INCLUDES += -I$(XPDIST)/public/nspr
|
||||
endif
|
||||
|
||||
ifndef NSBUILDROOT
|
||||
JSJAVA_STUBHEADERS = -I$(DEPTH)/sun-java/include/_gen \
|
||||
-I$(DEPTH)/sun-java/netscape/javascript/_jri \
|
||||
-I$(DEPTH)/sun-java/netscape/security/_jri
|
||||
else
|
||||
JSJAVA_STUBHEADERS = -I$(JRI_GEN_DIR) -I$(JDK_GEN_DIR)
|
||||
endif
|
||||
|
||||
JSJAVA_CFLAGS = -I$(DEPTH)/sun-java/md-include \
|
||||
-I$(DEPTH)/sun-java/include \
|
||||
$(JSJAVA_STUBHEADERS)
|
||||
|
||||
# LIBNSPR includes unneeded libmsgc21.a, but abstracts nspr version,
|
||||
# etc. nicely.
|
||||
LDFLAGS = $(LIBNSPR) -lm
|
||||
|
||||
ifeq ($(OS_ARCH), OSF1)
|
||||
LDFLAGS += -lc_r
|
||||
endif
|
||||
ifeq ($(OS_ARCH), SunOS)
|
||||
LDFLAGS += -lposix4 -ldl -lnsl -lsocket
|
||||
endif
|
||||
ifeq ($(OS_ARCH), Linux)
|
||||
LDFLAGS += -ldl
|
||||
endif
|
||||
|
||||
# this requires clobbering and recompiling with XCFLAGS=-DJSFILE
|
||||
js:
|
||||
$(MAKE) clobber
|
||||
$(MAKE) XCFLAGS=-DJSFILE $(OBJDIR)/js$(BIN_SUFFIX)
|
||||
|
||||
.PHONY: js$(BIN_SUFFIX)
|
||||
|
||||
ifneq ($(OS_ARCH),OS2)
|
||||
$(OBJDIR)/js$(BIN_SUFFIX): $(OBJDIR)/js.o $(LIBRARY)
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CC) -o $@ $(OBJDIR)/js.o $(LIBRARY) $(LDFLAGS)
|
||||
else
|
||||
OS_CFLAGS += -tm-
|
||||
$(OBJDIR)/js$(BIN_SUFFIX): $(OBJDIR)/js.o $(LIBRARY)
|
||||
@$(MAKE_OBJDIR)
|
||||
$(LINK_EXE) -OUT:$@ $(OBJDIR)/js.o $(LIBRARIES) $(EXTRA_LIBS)
|
||||
endif
|
||||
|
||||
# hardwire dependencies on jsopcode.def
|
||||
jsopcode.h jsopcode.c: jsopcode.def
|
||||
|
||||
# this section was put in the merged by danda into the
|
||||
# JAVA_*_MERGE section and normally would have
|
||||
# been removed. However it looks like it shouldn't have
|
||||
# been put there in the first place, so we're leaving it
|
||||
# here until danda can confirm (we don't have OS/2 machines
|
||||
# to build on) - hshaw/sudu
|
||||
#
|
||||
ifeq ($(OS_ARCH),OS2)
|
||||
$(OBJDIR)/js.o: js.c
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CC) -Fo$@ -c $(CFLAGS) $(JSJAVA_CFLAGS) js.c
|
||||
endif
|
||||
|
||||
|
||||
refdiff:
|
||||
@for f in `cat commfiles`; do \
|
||||
t=/tmp/refdiff.$$$$; \
|
||||
trap 'rm -f $$t' 0 1 2 15; \
|
||||
sed -f prconv.sed ../ref/$$f > $$t; \
|
||||
cmp -s $$t $$f; \
|
||||
if test $$? -ne 0; then \
|
||||
echo "=== $$f"; \
|
||||
diff $$f $$t; \
|
||||
fi; \
|
||||
rm -f $$t; \
|
||||
done
|
||||
|
||||
refconv:
|
||||
@for f in `cat commfiles`; do \
|
||||
echo "=== $$f"; \
|
||||
sed -f prconv.sed ../ref/$$f > $$f; \
|
||||
done
|
||||
|
||||
.PHONY: refdiff refconv
|
||||
@@ -1,241 +0,0 @@
|
||||
#! gmake
|
||||
# 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.
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
srcdir = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
ifdef MOZ_OJI
|
||||
DIRS = liveconnect
|
||||
endif
|
||||
|
||||
LIBRARY_NAME = js
|
||||
|
||||
ifeq ($(subst /,_,$(shell uname -s)),OS2)
|
||||
ifndef XCFLAGS
|
||||
OS2_IMPLIB=1
|
||||
LIBRARY = js$(MOZ_BITS)$(VERSION_NUMBER).$(LIB_SUFFIX)
|
||||
DEF_FILE = jsos2$(VERSION_NUMBER).def
|
||||
EXTRA_LIBS = $(LIBNSPR) $(LIBNSJAVA)
|
||||
else
|
||||
EXTRA_LIBS = $(LIBNSPR) $(LIBNSJAVA) $(OBJDIR)/libjs.lib
|
||||
endif
|
||||
endif
|
||||
|
||||
MODULE = js
|
||||
|
||||
CSRCS = jsapi.c \
|
||||
jsarray.c \
|
||||
jsatom.c \
|
||||
jsbool.c \
|
||||
jscntxt.c \
|
||||
jsdate.c \
|
||||
jsdbgapi.c \
|
||||
jsemit.c \
|
||||
jsfun.c \
|
||||
jsgc.c \
|
||||
jsinterp.c \
|
||||
jsmath.c \
|
||||
jsnum.c \
|
||||
jsobj.c \
|
||||
jsopcode.c \
|
||||
jsparse.c \
|
||||
jsregexp.c \
|
||||
jsscan.c \
|
||||
jsscope.c \
|
||||
jsscript.c \
|
||||
jsstr.c \
|
||||
jslock.c \
|
||||
jsxdrapi.c \
|
||||
prmjtime.c \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = jsapi.h \
|
||||
jsarray.h \
|
||||
jsatom.h \
|
||||
jsbool.h \
|
||||
jscntxt.h \
|
||||
jscompat.h \
|
||||
jsconfig.h \
|
||||
jsdate.h \
|
||||
jsdbgapi.h \
|
||||
jsemit.h \
|
||||
jsfun.h \
|
||||
jsgc.h \
|
||||
jsinterp.h \
|
||||
jslock.h \
|
||||
jsmath.h \
|
||||
jsnum.h \
|
||||
jsobj.h \
|
||||
jsopcode.def \
|
||||
jsopcode.h \
|
||||
jsparse.h \
|
||||
jsprvtd.h \
|
||||
jspubtd.h \
|
||||
jsregexp.h \
|
||||
jsscan.h \
|
||||
jsscope.h \
|
||||
jsscript.h \
|
||||
jsstr.h \
|
||||
jsxdrapi.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
# when using gcc the assembly is inlined in the C-file (see jslock.c)
|
||||
ifdef NS_USE_NATIVE
|
||||
ASFILES = $(wildcard $(srcdir)/*_$(OS_ARCH).s)
|
||||
endif
|
||||
|
||||
JS_SAFE_ARENA = 1
|
||||
|
||||
ifdef JS_SAFE_ARENA
|
||||
DEFINES += -DJS_USE_SAFE_ARENA
|
||||
CSRCS += prarena.c
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
ifndef BUILD_OPT
|
||||
MOCHAFILE = 1
|
||||
endif
|
||||
|
||||
ifdef JSFILE
|
||||
DEFINES += -DJSFILE
|
||||
endif
|
||||
|
||||
ifdef JS_THREADSAFE
|
||||
DEFINES += -DJS_THREADSAFE
|
||||
endif
|
||||
|
||||
ifdef JS_NO_THIN_LOCKS
|
||||
DEFINES += -DJS_USE_ONLY_NSPR_LOCKS
|
||||
endif
|
||||
|
||||
ifdef JS_VERSION
|
||||
DEFINES += -DJS_VERSION=$(JS_VERSION)
|
||||
endif
|
||||
|
||||
ifeq ($(CPU_ARCH),sparc)
|
||||
|
||||
ifndef JS_NO_ULTRA
|
||||
ULTRA_OPTIONS := -xarch=v8plus,-DULTRA_SPARC
|
||||
ULTRA_OPTIONSCC := -DULTRA_SPARC
|
||||
else
|
||||
ULTRA_OPTIONS := -xarch=v8
|
||||
ULTRA_OPTIONSCC :=
|
||||
endif
|
||||
|
||||
ifeq ($(shell uname -m),sun4u)
|
||||
ASFLAGS += -Wa,$(ULTRA_OPTIONS),-P,-L,-D_ASM,-D__STDC__=0 $(ULTRA_OPTIONSCC)
|
||||
else
|
||||
ASFLAGS += -Wa,-xarch=v8,-P,-L,-D_ASM,-D__STDC__=0
|
||||
endif
|
||||
|
||||
endif # sparc
|
||||
|
||||
INCLUDES += -I$(srcdir)
|
||||
|
||||
ifdef NSPR20
|
||||
INCLUDES += -I$(DIST)/include/nspr20/pr
|
||||
else
|
||||
INCLUDES += -I$(XPDIST)/public/nspr
|
||||
endif
|
||||
|
||||
ifndef NSBUILDROOT
|
||||
JSJAVA_STUBHEADERS = -I$(topsrcdir)/sun-java/include/_gen \
|
||||
-I$(topsrcdir)/sun-java/netscape/javascript/_jri \
|
||||
-I$(topsrcdir)/sun-java/netscape/security/_jri
|
||||
else
|
||||
JSJAVA_STUBHEADERS = -I$(JRI_GEN_DIR) -I$(JDK_GEN_DIR)
|
||||
endif
|
||||
|
||||
JSJAVA_CFLAGS = -I$(topsrcdir)/sun-java/md-include \
|
||||
-I$(topsrcdir)/sun-java/include \
|
||||
$(JSJAVA_STUBHEADERS)
|
||||
|
||||
# LIBNSPR includes unneeded libmsgc21.a, but abstracts nspr version,
|
||||
# etc. nicely.
|
||||
LDFLAGS = $(LIBNSPR) -lm
|
||||
|
||||
ifeq ($(OS_ARCH), OSF1)
|
||||
LDFLAGS += -lc_r
|
||||
endif
|
||||
ifeq ($(OS_ARCH), SunOS)
|
||||
LDFLAGS += -lposix4 -ldl -lnsl -lsocket
|
||||
endif
|
||||
ifeq ($(OS_ARCH), Linux)
|
||||
LDFLAGS += -ldl
|
||||
endif
|
||||
|
||||
# this requires clobbering and recompiling with XCFLAGS=-DJSFILE
|
||||
js:
|
||||
$(MAKE) clobber
|
||||
$(MAKE) XCFLAGS=-DJSFILE $(OBJDIR)/js$(BIN_SUFFIX)
|
||||
|
||||
.PHONY: js$(BIN_SUFFIX)
|
||||
|
||||
ifneq ($(OS_ARCH),OS2)
|
||||
$(OBJDIR)/js$(BIN_SUFFIX): $(OBJDIR)/js.o $(LIBRARY)
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CC) -o $@ $(OBJDIR)/js.o $(LIBRARY) $(LDFLAGS)
|
||||
else
|
||||
OS_CFLAGS += -tm-
|
||||
$(OBJDIR)/js$(BIN_SUFFIX): $(OBJDIR)/js.o $(LIBRARY)
|
||||
@$(MAKE_OBJDIR)
|
||||
$(LINK_EXE) -OUT:$@ $(OBJDIR)/js.o $(LIBRARIES) $(EXTRA_LIBS)
|
||||
endif
|
||||
|
||||
# hardwire dependencies on jsopcode.def
|
||||
jsopcode.h jsopcode.c: jsopcode.def
|
||||
|
||||
# this section was put in the merged by danda into the
|
||||
# JAVA_*_MERGE section and normally would have
|
||||
# been removed. However it looks like it shouldn't have
|
||||
# been put there in the first place, so we're leaving it
|
||||
# here until danda can confirm (we don't have OS/2 machines
|
||||
# to build on) - hshaw/sudu
|
||||
#
|
||||
ifeq ($(OS_ARCH),OS2)
|
||||
$(OBJDIR)/js.o: js.c
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CC) -Fo$@ -c $(CFLAGS) $(JSJAVA_CFLAGS) js.c
|
||||
endif
|
||||
|
||||
|
||||
refdiff:
|
||||
@for f in `cat commfiles`; do \
|
||||
t=/tmp/refdiff.$$$$; \
|
||||
trap 'rm -f $$t' 0 1 2 15; \
|
||||
sed -f prconv.sed ../ref/$$f > $$t; \
|
||||
cmp -s $$t $$f; \
|
||||
if test $$? -ne 0; then \
|
||||
echo "=== $$f"; \
|
||||
diff $$f $$t; \
|
||||
fi; \
|
||||
rm -f $$t; \
|
||||
done
|
||||
|
||||
refconv:
|
||||
@for f in `cat commfiles`; do \
|
||||
echo "=== $$f"; \
|
||||
sed -f prconv.sed ../ref/$$f > $$f; \
|
||||
done
|
||||
|
||||
.PHONY: refdiff refconv
|
||||
@@ -1,316 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
@@ -1,17 +0,0 @@
|
||||
The js/ref directory contains standalone ANSI-C source for the Netscape
|
||||
JavaScript Reference implementation, JSRef, which was licensed to over 180
|
||||
companies as part of Netscape ONE, starting in fall 1996. Now, JSRef is
|
||||
available under NPL from http://www.mozilla.org.
|
||||
|
||||
The js/src directory contains source files listed in the file "commfiles",
|
||||
that are derived via prconv.sed from counterparts in the js/ref directory.
|
||||
It also contains files such as jscompat.h that are not needed in js/ref.
|
||||
The Makefile in js/src has refconv and refdiff targets to help keep js/ref
|
||||
and js/src in synch.
|
||||
|
||||
If you think you need to change a file listed in commfiles here, please
|
||||
make the change in js/ref first and then use prconv.sed or gmake refconv to
|
||||
get it into js/src. If you have trouble, please let us know by mailing the
|
||||
JS owner and peers listed in http://www.mozilla.org/owners.html#JavaScript.
|
||||
|
||||
Brendan Eich (brendan@mozilla.org), 15-May-98
|
||||
@@ -1,100 +0,0 @@
|
||||
#! gmake
|
||||
|
||||
#
|
||||
# Since everyone seems to need to have their own build configuration
|
||||
# system these days, this is yet another makefile to build JavaScript.
|
||||
# This makefile conforms to the NSPR20 build rules. If you have built
|
||||
# NSPR20 this will build JS and stick the lib and bin files over in
|
||||
# the dist area created by NSPR (which is different from the dist
|
||||
# expected by the client and also the dist expected by LiveWire, but
|
||||
# don't get me started).
|
||||
#
|
||||
# I don't currently know enough about what sort of JS-engine the Actra
|
||||
# projects are going to expect so I don't know if we need to add
|
||||
# to CFLAGS for -DJS_THREADSAFE or -DJSFILE
|
||||
#
|
||||
|
||||
MOD_DEPTH = ../../nspr20
|
||||
|
||||
include $(MOD_DEPTH)/config/config.mk
|
||||
|
||||
INCLUDES = -I$(DIST)/include
|
||||
CFLAGS += -DNSPR20
|
||||
|
||||
CSRCS = prmjtime.c \
|
||||
jsapi.c \
|
||||
jsarray.c \
|
||||
jsatom.c \
|
||||
jsbool.c \
|
||||
jscntxt.c \
|
||||
jsdate.c \
|
||||
jsdbgapi.c \
|
||||
jsemit.c \
|
||||
jsfun.c \
|
||||
jsgc.c \
|
||||
jsinterp.c \
|
||||
jsmath.c \
|
||||
jsnum.c \
|
||||
jsobj.c \
|
||||
jsopcode.c \
|
||||
jsparse.c \
|
||||
jsregexp.c \
|
||||
jsscan.c \
|
||||
jsscope.c \
|
||||
jsscript.c \
|
||||
jsstr.c \
|
||||
jslock.c \
|
||||
$(NULL)
|
||||
|
||||
HEADERS = jsapi.h \
|
||||
jsarray.h \
|
||||
jsatom.h \
|
||||
jsbool.h \
|
||||
jscntxt.h \
|
||||
jscompat.h \
|
||||
jsconfig.h \
|
||||
jsdate.h \
|
||||
jsdbgapi.h \
|
||||
jsemit.h \
|
||||
jsfun.h \
|
||||
jsgc.h \
|
||||
jsinterp.h \
|
||||
jslock.h \
|
||||
jsmath.h \
|
||||
jsnum.h \
|
||||
jsobj.h \
|
||||
jsopcode.def \
|
||||
jsopcode.h \
|
||||
jsparse.h \
|
||||
jsprvtd.h \
|
||||
jspubtd.h \
|
||||
jsregexp.h \
|
||||
jsscan.h \
|
||||
jsscope.h \
|
||||
jsscript.h \
|
||||
jsstr.h \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(OS_ARCH), WINNT)
|
||||
EXTRA_LIBS += $(DIST)/lib/libnspr$(MOD_VERSION).lib
|
||||
EXTRA_LIBS += $(DIST)/lib/libplds$(MOD_VERSION).lib
|
||||
else
|
||||
EXTRA_LIBS += -L$(DIST)/lib -lnspr$(MOD_VERSION) -lnplds$(MOD_VERSION)
|
||||
endif
|
||||
|
||||
LIBRARY_NAME = js
|
||||
LIBRARY_VERSION = $(MOD_VERSION)
|
||||
|
||||
RELEASE_HEADERS = $(HEADERS)
|
||||
RELEASE_HEADERS_DEST = $(RELEASE_INCLUDE_DIR)
|
||||
RELEASE_LIBS = $(TARGETS)
|
||||
|
||||
include $(MOD_DEPTH)/config/rules.mk
|
||||
|
||||
export:: $(TARGETS)
|
||||
$(INSTALL) -m 444 $(HEADERS) $(MOD_DEPTH)/../dist/public/$(LIBRARY_NAME)
|
||||
$(INSTALL) -m 444 $(TARGETS) $(DIST)/lib
|
||||
$(INSTALL) -m 444 $(SHARED_LIBRARY) $(DIST)/bin
|
||||
|
||||
install:: export
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
js.c
|
||||
jsapi.c
|
||||
jsapi.h
|
||||
jsarray.c
|
||||
jsarray.h
|
||||
jsatom.c
|
||||
jsatom.h
|
||||
jsbool.c
|
||||
jsbool.h
|
||||
jscntxt.c
|
||||
jscntxt.h
|
||||
jsconfig.h
|
||||
jsdate.c
|
||||
jsdate.h
|
||||
jsdbgapi.c
|
||||
jsdbgapi.h
|
||||
jsemit.c
|
||||
jsemit.h
|
||||
jsfun.c
|
||||
jsfun.h
|
||||
jsgc.c
|
||||
jsgc.h
|
||||
jsinterp.c
|
||||
jsinterp.h
|
||||
jslock.h
|
||||
jslock.c
|
||||
jsmath.c
|
||||
jsmath.h
|
||||
jsnum.c
|
||||
jsnum.h
|
||||
jsobj.c
|
||||
jsobj.h
|
||||
jsopcode.c
|
||||
jsopcode.def
|
||||
jsopcode.h
|
||||
jsparse.c
|
||||
jsparse.h
|
||||
jsprvtd.h
|
||||
jspubtd.h
|
||||
jsregexp.c
|
||||
jsregexp.h
|
||||
jsscan.c
|
||||
jsscan.h
|
||||
jsscope.c
|
||||
jsscope.h
|
||||
jsscript.c
|
||||
jsscript.h
|
||||
jsstr.c
|
||||
jsstr.h
|
||||
jsxdrapi.h
|
||||
jsxdrapi.c
|
||||
@@ -1,37 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
@@ -1,48 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
@@ -1,58 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
@@ -1,22 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
@@ -1,22 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
@@ -1,22 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
@@ -1,22 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
@@ -1,47 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
@@ -1,79 +0,0 @@
|
||||
#
|
||||
# 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 =
|
||||
@@ -1,66 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
@@ -1,67 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
@@ -1,71 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
@@ -1,62 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
@@ -1,46 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
@@ -1,42 +0,0 @@
|
||||
#
|
||||
# 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
|
||||
@@ -1,30 +0,0 @@
|
||||
# This is a list of local files which get copied to the mozilla:dist directory
|
||||
#
|
||||
|
||||
jsapi.h
|
||||
jsarray.h
|
||||
jsatom.h
|
||||
jsbool.h
|
||||
jscntxt.h
|
||||
jscompat.h
|
||||
jsconfig.h
|
||||
jsdate.h
|
||||
jsdbgapi.h
|
||||
jsemit.h
|
||||
jsfun.h
|
||||
jsgc.h
|
||||
jsinterp.h
|
||||
jslock.h
|
||||
jsmath.h
|
||||
jsnum.h
|
||||
jsobj.h
|
||||
jsopcode.def
|
||||
jsopcode.h
|
||||
jsparse.h
|
||||
jsprvtd.h
|
||||
jspubtd.h
|
||||
jsregexp.h
|
||||
jsscan.h
|
||||
jsscope.h
|
||||
jsscript.h
|
||||
jsstr.h
|
||||
1545
mozilla/js/src/js.c
1545
mozilla/js/src/js.c
File diff suppressed because it is too large
Load Diff
@@ -1,184 +0,0 @@
|
||||
# Microsoft Developer Studio Project File - Name="jsshell" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 5.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=jsshell - Win32 Release
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "js.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "js.mak" CFG="jsshell - Win32 Release"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "jsshell - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "jsshell - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "jsshell - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir ".\jsshell_"
|
||||
# PROP BASE Intermediate_Dir ".\jsshell_"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir ".\Release"
|
||||
# PROP Intermediate_Dir ".\Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /YX /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "mininspr" /D "NDEBUG" /D "_CONSOLE" /D "_WIN32" /D "WIN32" /D "XP_PC" /D "_WINDOWS" /D "JSFILE" /D "MINI_NSPR" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:".\Release\jsshell.exe"
|
||||
|
||||
!ELSEIF "$(CFG)" == "jsshell - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir ".\jsshell0"
|
||||
# PROP BASE Intermediate_Dir ".\jsshell0"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir ".\Debug"
|
||||
# PROP Intermediate_Dir ".\Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /YX /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "mininspr" /D "_DEBUG" /D "DEBUG" /D "_CONSOLE" /D "_WIN32" /D "WIN32" /D "XP_PC" /D "_WINDOWS" /D "JSFILE" /D "MINI_NSPR" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:".\Debug\jsshell.exe"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "jsshell - Win32 Release"
|
||||
# Name "jsshell - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\js.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsapi.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsatom.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jscntxt.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsdbgapi.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsemit.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsfun.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsgc.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsinterp.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jslock.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsobj.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsopcode.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsparse.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsprvtd.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jspubtd.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsregexp.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsscan.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsscope.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsscript.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsstddef.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsstr.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\prarena.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -1,194 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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")
|
||||
@@ -1,130 +0,0 @@
|
||||
; 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.
|
||||
LIBRARY JS1640.DLL
|
||||
EXETYPE WINDOWS
|
||||
PROTMODE
|
||||
|
||||
DESCRIPTION 'Netscape 16-bit JavaScript Library'
|
||||
|
||||
CODE LOADONCALL MOVEABLE DISCARDABLE
|
||||
DATA PRELOAD MOVEABLE SINGLE
|
||||
|
||||
HEAPSIZE 8192
|
||||
|
||||
EXPORTS
|
||||
WEP @1 RESIDENTNAME NONAME
|
||||
_JS_Init = _JS_Init @2
|
||||
_JS_Finish = _JS_Finish @3
|
||||
_JS_GetNaNValue
|
||||
_JS_GetNegativeInfinityValue
|
||||
_JS_GetPositiveInfinityValue
|
||||
_JS_GetEmptyStringValue
|
||||
_JS_ConvertValue
|
||||
_JS_ValueToObject
|
||||
_JS_ValueToFunction
|
||||
_JS_ValueToString
|
||||
_JS_ValueToNumber
|
||||
_JS_ValueToBoolean
|
||||
_JS_TypeOfValue
|
||||
_JS_GetTypeName
|
||||
_JS_Lock
|
||||
_JS_Unlock
|
||||
_JS_NewContext
|
||||
_JS_DestroyContext
|
||||
_JS_ContextIterator
|
||||
_JS_GetGlobalObject
|
||||
_JS_SetGlobalObject
|
||||
_JS_InitStandardClasses
|
||||
; _JS_GetStaticLink
|
||||
_JS_malloc
|
||||
_JS_realloc
|
||||
_JS_free
|
||||
_JS_strdup
|
||||
_JS_NewDouble
|
||||
_JS_NewDoubleValue
|
||||
_JS_AddRoot
|
||||
_JS_RemoveRoot
|
||||
_JS_LockGCThing
|
||||
_JS_UnlockGCThing
|
||||
_JS_GC
|
||||
_JS_PropertyStub
|
||||
_JS_EnumerateStub
|
||||
_JS_ResolveStub
|
||||
_JS_ConvertStub
|
||||
_JS_FinalizeStub
|
||||
_JS_InitClass
|
||||
_JS_GetClass
|
||||
_JS_InstanceOf
|
||||
_JS_GetPrivate
|
||||
_JS_SetPrivate
|
||||
_JS_GetInstancePrivate
|
||||
_JS_GetPrototype
|
||||
_JS_GetParent
|
||||
_JS_SetParent
|
||||
_JS_GetConstructor
|
||||
_JS_NewObject
|
||||
_JS_DefineObject
|
||||
_JS_DefineConstDoubles
|
||||
_JS_DefineProperties
|
||||
_JS_DefineProperty
|
||||
_JS_DefinePropertyWithTinyId
|
||||
_JS_AliasProperty
|
||||
_JS_LookupProperty
|
||||
_JS_GetProperty
|
||||
_JS_SetProperty
|
||||
_JS_DeleteProperty
|
||||
_JS_NewArrayObject
|
||||
_JS_DefineElement
|
||||
_JS_AliasElement
|
||||
_JS_LookupElement
|
||||
_JS_GetElement
|
||||
_JS_SetElement
|
||||
_JS_DeleteElement
|
||||
_JS_ClearScope
|
||||
_JS_NewFunction
|
||||
_JS_GetFunctionObject
|
||||
_JS_GetFunctionName
|
||||
_JS_DefineFunctions
|
||||
_JS_DefineFunction
|
||||
_JS_CompileScript
|
||||
_JS_DestroyScript
|
||||
_JS_CompileFunction
|
||||
_JS_DecompileScript
|
||||
_JS_DecompileFunction
|
||||
_JS_DecompileFunctionBody
|
||||
_JS_ExecuteScript
|
||||
_JS_EvaluateScript
|
||||
_JS_CallFunction
|
||||
_JS_CallFunctionName
|
||||
_JS_CallFunctionValue
|
||||
_JS_SetBranchCallback
|
||||
_JS_IsRunning
|
||||
_JS_NewString
|
||||
_JS_NewStringCopyN
|
||||
_JS_NewStringCopyZ
|
||||
_JS_InternString
|
||||
_JS_GetStringBytes
|
||||
_JS_GetStringLength
|
||||
_JS_CompareStrings
|
||||
_JS_ReportError
|
||||
_JS_ReportOutOfMemory
|
||||
_JS_SetErrorReporter
|
||||
_JS_NewRegExpObject
|
||||
_JS_SetRegExpInput
|
||||
_JS_ClearRegExpStatics
|
||||
|
||||
IMPORTS
|
||||
_printf = nspr21.11
|
||||
_strftime = nspr21.13
|
||||
@@ -1,137 +0,0 @@
|
||||
LIBRARY JS1640.DLL
|
||||
EXETYPE WINDOWS
|
||||
PROTMODE
|
||||
|
||||
DESCRIPTION 'Netscape 16-bit JavaScript Library'
|
||||
|
||||
CODE LOADONCALL MOVEABLE DISCARDABLE
|
||||
DATA PRELOAD MOVEABLE SINGLE
|
||||
|
||||
HEAPSIZE 8192
|
||||
|
||||
EXPORTS
|
||||
WEP @1 RESIDENTNAME NONAME
|
||||
_JS_Init = _JS_Init @2
|
||||
_JS_Finish = _JS_Finish @3
|
||||
_JS_GetNaNValue
|
||||
_JS_GetNegativeInfinityValue
|
||||
_JS_GetPositiveInfinityValue
|
||||
_JS_GetEmptyStringValue
|
||||
_JS_ConvertValue
|
||||
_JS_ValueToObject
|
||||
_JS_ValueToFunction
|
||||
_JS_ValueToString
|
||||
_JS_ValueToNumber
|
||||
_JS_ValueToBoolean
|
||||
_JS_TypeOfValue
|
||||
_JS_GetTypeName
|
||||
_JS_Lock
|
||||
_JS_Unlock
|
||||
_JS_NewContext
|
||||
_JS_DestroyContext
|
||||
_JS_ContextIterator
|
||||
_JS_GetGlobalObject
|
||||
_JS_SetGlobalObject
|
||||
_JS_InitStandardClasses
|
||||
; _JS_GetStaticLink
|
||||
_JS_malloc
|
||||
_JS_realloc
|
||||
_JS_free
|
||||
_JS_strdup
|
||||
_JS_NewDouble
|
||||
_JS_NewDoubleValue
|
||||
_JS_AddRoot
|
||||
_JS_RemoveRoot
|
||||
_JS_LockGCThing
|
||||
_JS_UnlockGCThing
|
||||
_JS_GC
|
||||
_JS_PropertyStub
|
||||
_JS_EnumerateStub
|
||||
_JS_ResolveStub
|
||||
_JS_ConvertStub
|
||||
_JS_FinalizeStub
|
||||
_JS_InitClass
|
||||
_JS_GetClass
|
||||
_JS_InstanceOf
|
||||
_JS_GetPrivate
|
||||
_JS_SetPrivate
|
||||
_JS_GetInstancePrivate
|
||||
_JS_GetPrototype
|
||||
_JS_GetParent
|
||||
_JS_SetParent
|
||||
_JS_GetConstructor
|
||||
_JS_NewObject
|
||||
_JS_DefineObject
|
||||
_JS_DefineConstDoubles
|
||||
_JS_DefineProperties
|
||||
_JS_DefineProperty
|
||||
_JS_DefinePropertyWithTinyId
|
||||
_JS_AliasProperty
|
||||
_JS_LookupProperty
|
||||
_JS_GetProperty
|
||||
_JS_SetProperty
|
||||
_JS_DeleteProperty
|
||||
_JS_NewArrayObject
|
||||
_JS_DefineElement
|
||||
_JS_AliasElement
|
||||
_JS_LookupElement
|
||||
_JS_GetElement
|
||||
_JS_SetElement
|
||||
_JS_DeleteElement
|
||||
_JS_ClearScope
|
||||
_JS_NewFunction
|
||||
_JS_GetFunctionObject
|
||||
_JS_GetFunctionName
|
||||
_JS_DefineFunctions
|
||||
_JS_DefineFunction
|
||||
_JS_CompileScript
|
||||
_JS_DestroyScript
|
||||
_JS_CompileFunction
|
||||
_JS_DecompileScript
|
||||
_JS_DecompileFunction
|
||||
_JS_DecompileFunctionBody
|
||||
_JS_ExecuteScript
|
||||
_JS_EvaluateScript
|
||||
_JS_CallFunction
|
||||
_JS_CallFunctionName
|
||||
_JS_CallFunctionValue
|
||||
_JS_SetBranchCallback
|
||||
_JS_IsRunning
|
||||
_JS_NewString
|
||||
_JS_NewStringCopyN
|
||||
_JS_NewStringCopyZ
|
||||
_JS_InternString
|
||||
_JS_GetStringBytes
|
||||
_JS_GetStringLength
|
||||
_JS_CompareStrings
|
||||
_JS_ReportError
|
||||
_JS_ReportOutOfMemory
|
||||
_JS_SetErrorReporter
|
||||
_JS_NewRegExpObject
|
||||
_JS_SetRegExpInput
|
||||
_JS_ClearRegExpStatics
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Version stamp for this .DLL
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <ver.h>
|
||||
|
||||
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
|
||||
FILEVERSION 4 // major, minor, release (alpha 1), build #
|
||||
|
||||
PRODUCTVERSION 4
|
||||
|
||||
FILEFLAGSMASK 0
|
||||
|
||||
FILEFLAGS 0 // final version
|
||||
|
||||
FILEOS VOS_DOS_WINDOWS16
|
||||
|
||||
FILETYPE VFT_DLL
|
||||
|
||||
FILESUBTYPE 0 // not used
|
||||
|
||||
BEGIN
|
||||
|
||||
BLOCK "StringFileInfo"
|
||||
|
||||
BEGIN
|
||||
|
||||
BLOCK "040904E4" // Lang=US English, CharSet=Windows Multilingual
|
||||
|
||||
BEGIN
|
||||
|
||||
VALUE "CompanyName", "Netscape Communications Corporation\0"
|
||||
|
||||
VALUE "FileDescription", "Netscape 16-bit JavaScript Module\0"
|
||||
|
||||
VALUE "FileVersion", "4.0\0"
|
||||
|
||||
VALUE "InternalName", "JS1640\0"
|
||||
|
||||
VALUE "LegalCopyright", "Copyright Netscape Communications. 1994-96\0"
|
||||
|
||||
VALUE "LegalTrademarks", "Netscape, Mozilla\0"
|
||||
|
||||
VALUE "OriginalFilename","JS1640.DLL\0"
|
||||
|
||||
VALUE "ProductName", "NETSCAPE\0"
|
||||
|
||||
VALUE "ProductVersion", "4.0\0"
|
||||
|
||||
END
|
||||
|
||||
END
|
||||
|
||||
END
|
||||
|
||||
@@ -1,318 +0,0 @@
|
||||
# Microsoft Developer Studio Project File - Name="js32" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 5.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=js32 - Win32 Release
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "js32.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "js32.mak" CFG="js32 - Win32 Release"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "js32 - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "js32 - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "js32 - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir ".\js32\Release"
|
||||
# PROP BASE Intermediate_Dir ".\js32\Release"
|
||||
# PROP BASE Target_Dir ".\js32"
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir ".\Release"
|
||||
# PROP Intermediate_Dir ".\Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ".\js32"
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "mininspr" /D "NDEBUG" /D "_WINDOWS" /D "_WIN32" /D "WIN32" /D "XP_PC" /D "JSFILE" /D "EXPORT_JS_API" /D "MINI_NSPR" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
|
||||
# ADD LINK32 H:\ns\dist\WINNT4.0_OPT.OBJ\lib\libnspr21_s.lib H:\ns\dist\WINNT4.0_OPT.OBJ\lib\libplds21_s.lib winmm.lib mswsock.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
|
||||
|
||||
!ELSEIF "$(CFG)" == "js32 - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir ".\js32\Debug"
|
||||
# PROP BASE Intermediate_Dir ".\js32\Debug"
|
||||
# PROP BASE Target_Dir ".\js32"
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir ".\Debug"
|
||||
# PROP Intermediate_Dir ".\Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ".\js32"
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "mininspr" /D "_DEBUG" /D "DEBUG" /D "_WINDOWS" /D "_WIN32" /D "WIN32" /D "XP_PC" /D "JSFILE" /D "EXPORT_JS_API" /D "MINI_NSPR" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386
|
||||
# ADD LINK32 H:\ns\dist\WINNT4.0_DBG.OBJ\lib\libnspr21_s.lib H:\ns\dist\WINNT4.0_DBG.OBJ\lib\libplds21_s.lib winmm.lib mswsock.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "js32 - Win32 Release"
|
||||
# Name "js32 - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsapi.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsarray.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsatom.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsbool.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jscntxt.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsdate.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsdbgapi.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsemit.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsfun.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsgc.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsinterp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jslock.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsmath.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsnum.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsobj.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsopcode.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsparse.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsregexp.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsscan.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsscope.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsscript.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsstr.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsxdrapi.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\prarena.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\prmjtime.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsapi.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsarray.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsatom.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsbool.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jscntxt.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsconfig.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsdate.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsdbgapi.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsemit.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsfun.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsgc.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsinterp.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jslock.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsmath.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsnum.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsobj.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsopcode.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsparse.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsprvtd.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jspubtd.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsregexp.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsscan.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsscope.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsscript.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsstddef.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsstr.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\jsxdrapi.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\prarena.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\prdtoa.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
@@ -1,79 +0,0 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "winver.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 4,0,0,0
|
||||
PRODUCTVERSION 4,0,0,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x10004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904e4"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Netscape Communications Corporation\0"
|
||||
VALUE "FileDescription", "Netscape 32-bit JavaScript Module\0"
|
||||
VALUE "FileVersion", "4.0\0"
|
||||
VALUE "InternalName", "JS3240\0"
|
||||
VALUE "LegalCopyright", "Copyright Netscape Communications. 1994-96\0"
|
||||
VALUE "LegalTrademarks", "Netscape, Mozilla\0"
|
||||
VALUE "OriginalFilename", "js3240.dll\0"
|
||||
VALUE "ProductName", "NETSCAPE\0"
|
||||
VALUE "ProductVersion", "4.0\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1252
|
||||
END
|
||||
END
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""winver.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@@ -1,623 +0,0 @@
|
||||
; 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.
|
||||
|
||||
LIBRARY JS3240 INITINSTANCE TERMINSTANCE
|
||||
PROTMODE
|
||||
|
||||
DESCRIPTION 'Netscape OS/2 JavaScript Library'
|
||||
|
||||
|
||||
CODE LOADONCALL MOVEABLE DISCARDABLE
|
||||
DATA PRELOAD MOVEABLE MULTIPLE NONSHARED
|
||||
|
||||
|
||||
EXPORTS
|
||||
;====================== win16 exports these at least... ===========
|
||||
; JS_Init = JS_Init @2
|
||||
; JS_Finish = JS_Finish @3
|
||||
; JS_GetNaNValue
|
||||
; JS_GetNegativeInfinityValue
|
||||
; JS_GetPositiveInfinityValue
|
||||
; JS_GetEmptyStringValue
|
||||
; JS_ConvertValue
|
||||
; JS_ValueToObject
|
||||
; JS_ValueToFunction
|
||||
; JS_ValueToString
|
||||
; JS_ValueToNumber
|
||||
; JS_ValueToBoolean
|
||||
; JS_TypeOfValue
|
||||
; JS_GetTypeName
|
||||
; JS_Lock
|
||||
; JS_Unlock
|
||||
; JS_NewContext
|
||||
; JS_DestroyContext
|
||||
; JS_ContextIterator
|
||||
; JS_GetGlobalObject
|
||||
; JS_SetGlobalObject
|
||||
; JS_InitStandardClasses
|
||||
;; JS_GetStaticLink
|
||||
; JS_malloc
|
||||
; JS_realloc
|
||||
; JS_free
|
||||
; JS_strdup
|
||||
; JS_NewDouble
|
||||
; JS_NewDoubleValue
|
||||
; JS_AddRoot
|
||||
; JS_RemoveRoot
|
||||
; JS_LockGCThing
|
||||
; JS_UnlockGCThing
|
||||
; JS_GC
|
||||
; JS_PropertyStub
|
||||
; JS_EnumerateStub
|
||||
; JS_ResolveStub
|
||||
; JS_ConvertStub
|
||||
; JS_FinalizeStub
|
||||
; JS_InitClass
|
||||
; JS_GetClass
|
||||
; JS_InstanceOf
|
||||
; JS_GetPrivate
|
||||
; JS_SetPrivate
|
||||
; JS_GetInstancePrivate
|
||||
; JS_GetPrototype
|
||||
; JS_GetParent
|
||||
; JS_SetParent
|
||||
; JS_GetConstructor
|
||||
; JS_NewObject
|
||||
; JS_DefineObject
|
||||
; JS_DefineConstDoubles
|
||||
; JS_DefineProperties
|
||||
; JS_DefineProperty
|
||||
; JS_DefinePropertyWithTinyId
|
||||
; JS_AliasProperty
|
||||
; JS_LookupProperty
|
||||
; JS_GetProperty
|
||||
; JS_SetProperty
|
||||
; JS_DeleteProperty
|
||||
; JS_NewArrayObject
|
||||
; JS_DefineElement
|
||||
; JS_AliasElement
|
||||
; JS_LookupElement
|
||||
; JS_GetElement
|
||||
; JS_SetElement
|
||||
; JS_DeleteElement
|
||||
; JS_ClearScope
|
||||
; JS_NewFunction
|
||||
; JS_GetFunctionObject
|
||||
; JS_GetFunctionName
|
||||
; JS_DefineFunctions
|
||||
; JS_DefineFunction
|
||||
; JS_CompileScript
|
||||
; JS_DestroyScript
|
||||
; JS_CompileFunction
|
||||
; JS_DecompileScript
|
||||
; JS_DecompileFunction
|
||||
; JS_DecompileFunctionBody
|
||||
; JS_ExecuteScript
|
||||
; JS_EvaluateScript
|
||||
; JS_CallFunction
|
||||
; JS_CallFunctionName
|
||||
; JS_CallFunctionValue
|
||||
; JS_SetBranchCallback
|
||||
; JS_IsRunning
|
||||
; JS_NewString
|
||||
; JS_NewStringCopyN
|
||||
; JS_NewStringCopyZ
|
||||
; JS_InternString
|
||||
; JS_GetStringBytes
|
||||
; JS_GetStringLength
|
||||
; JS_CompareStrings
|
||||
; JS_ReportError
|
||||
; JS_ReportOutOfMemory
|
||||
; JS_SetErrorReporter
|
||||
; JS_NewRegExpObject
|
||||
; JS_SetRegExpInput
|
||||
; JS_ClearRegExpStatics
|
||||
;=================================================
|
||||
|
||||
|
||||
;00001:jsstr (OFFSET:0x00002e17, SIZE:0x0000ae17):
|
||||
; - Public Definitions:
|
||||
; js_EmptySubString
|
||||
; js_CompareStrings
|
||||
; js_HashString
|
||||
; js_ValueToString
|
||||
; js_StringToObject
|
||||
; js_FinalizeString
|
||||
; js_NewStringCopyZ
|
||||
; js_NewString
|
||||
; js_InitStringClass
|
||||
; js_NewStringCopyN
|
||||
; js_BoyerMooreHorspool
|
||||
;
|
||||
;
|
||||
;00002:jsscript (OFFSET:0x0000dc2e, SIZE:0x00003abb):
|
||||
; - Public Definitions:
|
||||
; js_LineNumberToPC
|
||||
; js_PCToLineNumber
|
||||
; js_GetSrcNote
|
||||
; js_DestroyScript
|
||||
; js_NewScript
|
||||
;
|
||||
;
|
||||
;00003:jsscope (OFFSET:0x000116e9, SIZE:0x00004f82):
|
||||
; - Public Definitions:
|
||||
; js_hash_scope_ops
|
||||
; js_list_scope_ops
|
||||
; js_DestroyProperty
|
||||
; js_NewProperty
|
||||
; js_IdToValue
|
||||
; js_HashValue
|
||||
; js_DestroyScope
|
||||
; js_MutateScope
|
||||
; js_DropScope
|
||||
; js_HoldScope
|
||||
; js_NewScope
|
||||
; js_GetMutableScope
|
||||
; js_HoldProperty
|
||||
; js_DropProperty
|
||||
;
|
||||
;
|
||||
;00004:jsscan (OFFSET:0x0001666b, SIZE:0x00008890):
|
||||
; - Public Definitions:
|
||||
; js_MatchToken
|
||||
; js_FlushNewlines
|
||||
; js_PeekTokenSameLine
|
||||
; js_UngetToken
|
||||
; js_GetToken
|
||||
; js_PeekToken
|
||||
; js_ReportCompileError
|
||||
js_CloseTokenStream
|
||||
js_NewBufferTokenStream
|
||||
; js_NewTokenStream
|
||||
; js_InitScanner
|
||||
;
|
||||
;
|
||||
;00005:jsregexp (OFFSET:0x0001eefb, SIZE:0x0000eee4):
|
||||
; - Public Definitions:
|
||||
; js_RegExpClass
|
||||
; reopsize
|
||||
; js_NewRegExpObject
|
||||
; js_InitRegExpClass
|
||||
; js_FreeRegExpStatics
|
||||
; js_InitRegExpStatics
|
||||
; js_ExecuteRegExp
|
||||
; js_NewRegExpOpt
|
||||
; js_DestroyRegExp
|
||||
; js_NewRegExp
|
||||
;
|
||||
;
|
||||
;00006:jsparse (OFFSET:0x0002dddf, SIZE:0x00010b71):
|
||||
; - Public Definitions:
|
||||
; js_ParseFunctionBody
|
||||
js_Parse
|
||||
;
|
||||
;
|
||||
;00007:jsopcode (OFFSET:0x0003e950, SIZE:0x0000d362):
|
||||
; - Public Definitions:
|
||||
; js_EscapeMap
|
||||
; js_NumCodeSpecs
|
||||
; js_CodeSpec
|
||||
; js_incop_str
|
||||
; js_true_str
|
||||
; js_false_str
|
||||
; js_this_str
|
||||
; js_null_str
|
||||
; js_void_str
|
||||
; js_typeof_str
|
||||
; js_delete_str
|
||||
; js_new_str
|
||||
; js_ValueToSource
|
||||
; js_DecompileScript
|
||||
; js_DecompileCode
|
||||
; js_DecompileFunction
|
||||
; js_puts
|
||||
; js_printf
|
||||
; js_GetPrinterOutput
|
||||
; js_DestroyPrinter
|
||||
; js_NewPrinter
|
||||
; js_EscapeString
|
||||
; js_Disassemble1
|
||||
; js_Disassemble
|
||||
;
|
||||
;00008:jsobj (OFFSET:0x0004bcb2, SIZE:0x000090a4):
|
||||
; - Public Definitions:
|
||||
; js_WithClass
|
||||
; js_ObjectClass
|
||||
; js_TryValueOf
|
||||
; js_ValueToNonNullObject
|
||||
; js_TryMethod
|
||||
; js_ObjectToString
|
||||
; js_SetClassPrototype
|
||||
; js_DeleteProperty2
|
||||
; js_DeleteProperty
|
||||
; js_SetProperty
|
||||
; js_GetProperty
|
||||
; js_FindVariableScope
|
||||
; js_FindVariable
|
||||
; js_FindProperty
|
||||
; js_LookupProperty
|
||||
; js_DefineProperty
|
||||
; js_FreeSlot
|
||||
; js_AllocSlot
|
||||
; js_FinalizeObject
|
||||
; js_GetClassPrototype
|
||||
; js_NewObject
|
||||
; js_InitObjectClass
|
||||
; js_ValueToObject
|
||||
; js_obj_toString
|
||||
; js_SetSlot
|
||||
; js_GetSlot
|
||||
;
|
||||
;
|
||||
;00009:jsnum (OFFSET:0x00054d56, SIZE:0x00004f29):
|
||||
; - Public Definitions:
|
||||
; js_ValueToInt32
|
||||
; js_NumberToObject
|
||||
; js_FinalizeDouble
|
||||
; js_InitNumberClass
|
||||
; js_NumberToString
|
||||
; js_NewDoubleValue
|
||||
; js_NewDouble
|
||||
; js_ValueToNumber
|
||||
;
|
||||
;
|
||||
;00010:jsmath (OFFSET:0x00059c7f, SIZE:0x000054b6):
|
||||
; - Public Definitions:
|
||||
; js_InitMathClass
|
||||
;
|
||||
;
|
||||
;00011:jsjava (OFFSET:0x0005f135, SIZE:0x00022aad):
|
||||
; - Public Definitions:
|
||||
; js_Hooks
|
||||
; MojaSrcLog
|
||||
; finalizeTask
|
||||
JSJ_FindCurrentJSContext
|
||||
; JSJ_GetPrincipals
|
||||
JSJ_IsSafeMethod
|
||||
JSJ_InitContext
|
||||
JSJ_Init
|
||||
js_JSErrorToJException
|
||||
js_JavaErrorReporter
|
||||
js_RemoveReflection
|
||||
js_ReflectJObjectToJSObject
|
||||
js_convertJObjectToJSValue
|
||||
js_convertJSValueToJObject
|
||||
js_ReflectJSObjectToJObject
|
||||
; js_ReflectJClassToJSObject
|
||||
JSJ_ExitJS
|
||||
JSJ_EnterJS
|
||||
JSJ_CurrentContext
|
||||
JSJ_IsEnabled
|
||||
;added in GA code - DSR70297
|
||||
JSJ_Finish
|
||||
JSJ_IsCalledFromJava
|
||||
js_GetJSPrincipalsFromJavaCaller
|
||||
|
||||
;
|
||||
;
|
||||
;00012:jsinterp (OFFSET:0x00081be2, SIZE:0x00012274):
|
||||
; - Public Definitions:
|
||||
; js_Call
|
||||
; js_Interpret
|
||||
; js_SetLocalVariable
|
||||
; js_GetLocalVariable
|
||||
; js_SetArgument
|
||||
; js_GetArgument
|
||||
; js_FlushPropertyCacheByProp
|
||||
; js_FlushPropertyCache
|
||||
;
|
||||
;
|
||||
;00013:jsgc (OFFSET:0x00093e56, SIZE:0x00004f8d):
|
||||
; - Public Definitions:
|
||||
; js_ForceGC
|
||||
; js_UnlockGCThing
|
||||
; js_LockGCThing
|
||||
; js_GC
|
||||
; js_AllocGCThing
|
||||
; js_RemoveRoot
|
||||
; js_AddRoot
|
||||
; js_FinishGC
|
||||
; js_InitGC
|
||||
;
|
||||
;
|
||||
;00014:jsfun (OFFSET:0x00098de3, SIZE:0x0000977c):
|
||||
; - Public Definitions:
|
||||
; js_FunctionClass
|
||||
; js_ClosureClass
|
||||
; js_CallClass
|
||||
; js_DefineFunction
|
||||
; js_NewFunction
|
||||
; js_InitCallAndClosureClasses
|
||||
; js_InitFunctionClass
|
||||
; js_ValueToFunction
|
||||
; js_SetCallVariable
|
||||
; js_GetCallVariable
|
||||
; js_PutCallObject
|
||||
; js_GetCallObject
|
||||
;
|
||||
;
|
||||
;00015:jsemit (OFFSET:0x000a255f, SIZE:0x000077be):
|
||||
; - Public Definitions:
|
||||
; js_SrcNoteName
|
||||
; js_SrcNoteArity
|
||||
js_FinishTakingSrcNotes
|
||||
; js_MoveSrcNotes
|
||||
; js_GetSrcNoteOffset
|
||||
; js_BumpSrcNoteDelta
|
||||
; js_NewSrcNote3
|
||||
; js_NewSrcNote2
|
||||
; js_PopStatement
|
||||
; js_EmitContinue
|
||||
; js_EmitBreak
|
||||
; js_SetSrcNoteOffset
|
||||
; js_NewSrcNote
|
||||
; js_PushStatement
|
||||
; js_MoveCode
|
||||
; js_SetJumpOffset
|
||||
; js_Emit3
|
||||
; js_Emit2
|
||||
; js_Emit1
|
||||
; js_UpdateDepth
|
||||
; js_SrcNoteLength
|
||||
; js_CancelLastOpcode
|
||||
js_InitCodeGenerator
|
||||
;
|
||||
;
|
||||
;00016:jsdbgapi (OFFSET:0x000a9d1d, SIZE:0x000057db):
|
||||
; - Public Definitions:
|
||||
; js_watchpoint_list
|
||||
; js_trap_list
|
||||
; JS_SetAnnotationInFrame
|
||||
; JS_GetAnnotationFromFrame
|
||||
; JS_GetJSPrincipalArrayFromFrame
|
||||
; JS_NextJSFrame
|
||||
; JS_InitJSFrameIterator
|
||||
JS_LineNumberToPC
|
||||
JS_PCToLineNumber
|
||||
JS_ClearAllWatchPoints
|
||||
JS_ClearWatchPoint
|
||||
JS_SetWatchPoint
|
||||
JS_HandleTrap
|
||||
JS_ClearAllTraps
|
||||
JS_ClearScriptTraps
|
||||
JS_ClearTrap
|
||||
JS_GetTrapOpcode
|
||||
JS_SetTrap
|
||||
;DSR070297 - added in GA code
|
||||
JS_FrameIterator
|
||||
JS_GetFrameAnnotation
|
||||
JS_GetFramePrincipalArray
|
||||
JS_GetFrameScript
|
||||
JS_GetScriptFilename
|
||||
JS_SetFrameAnnotation
|
||||
JS_GetFramePC
|
||||
JS_GetFunctionScript
|
||||
|
||||
;
|
||||
;
|
||||
;00017:jsdate (OFFSET:0x000af4f8, SIZE:0x00009a8e):
|
||||
; - Public Definitions:
|
||||
js_DateGetSeconds
|
||||
js_DateGetMinutes
|
||||
js_DateGetHours
|
||||
js_DateGetDate
|
||||
js_DateGetMonth
|
||||
js_DateGetYear
|
||||
js_NewDateObject
|
||||
; js_InitDateClass
|
||||
;
|
||||
;
|
||||
;00018:jscntxt (OFFSET:0x000b8f86, SIZE:0x00003732):
|
||||
; - Public Definitions:
|
||||
; js_InterpreterHooks
|
||||
; js_ReportIsNotDefined
|
||||
; js_ReportErrorAgain
|
||||
; js_ReportErrorVA
|
||||
; js_ContextIterator
|
||||
; js_DestroyContext
|
||||
; js_NewContext
|
||||
; js_SetInterpreterHooks
|
||||
;
|
||||
;
|
||||
;00019:jsbool (OFFSET:0x000bc6b8, SIZE:0x00003375):
|
||||
; - Public Definitions:
|
||||
; js_BooleanToString
|
||||
; js_BooleanToObject
|
||||
; js_InitBooleanClass
|
||||
; js_ValueToBoolean
|
||||
;
|
||||
;
|
||||
;00020:jsatom (OFFSET:0x000bfa2d, SIZE:0x000058d0):
|
||||
; - Public Definitions:
|
||||
; js_valueOf_str
|
||||
; js_toString_str
|
||||
; js_length_str
|
||||
; js_eval_str
|
||||
; js_constructor_str
|
||||
; js_class_prototype_str
|
||||
; js_assign_str
|
||||
; js_anonymous_str
|
||||
; js_Object_str
|
||||
; js_Array_str
|
||||
; js_type_str
|
||||
; js_DropUnmappedAtoms
|
||||
js_FreeAtomMap
|
||||
js_InitAtomMap
|
||||
; js_GetAtom
|
||||
; js_DropAtom
|
||||
; js_IndexAtom
|
||||
; js_ValueToStringAtom
|
||||
; js_AtomizeString
|
||||
; js_AtomizeDouble
|
||||
; js_AtomizeInt
|
||||
; js_AtomizeBoolean
|
||||
; js_AtomizeObject
|
||||
; js_HoldAtom
|
||||
; js_MarkAtomState
|
||||
; js_FreeAtomState
|
||||
; js_Atomize
|
||||
; js_InitAtomState
|
||||
;
|
||||
;
|
||||
;00021:jsarray (OFFSET:0x000c52fd, SIZE:0x00007c86):
|
||||
; - Public Definitions:
|
||||
; js_ArrayClass
|
||||
; js_SetArrayLength
|
||||
; js_GetArrayLength
|
||||
; js_InitArrayClass
|
||||
; js_NewArrayObject
|
||||
; PR_qsort
|
||||
;
|
||||
;
|
||||
;00022:jsapi (OFFSET:0x000ccf83, SIZE:0x0000de8c):
|
||||
; - Public Definitions:
|
||||
JS_ClearRegExpStatics
|
||||
JS_SetRegExpInput
|
||||
JS_NewRegExpObject
|
||||
JS_SetErrorReporter
|
||||
JS_CompareStrings
|
||||
JS_GetStringLength
|
||||
JS_GetStringBytes
|
||||
JS_InternString
|
||||
JS_NewStringCopyZ
|
||||
JS_NewStringCopyN
|
||||
JS_NewString
|
||||
JS_IsRunning
|
||||
JS_SetBranchCallback
|
||||
JS_CallFunctionValue
|
||||
JS_CallFunctionName
|
||||
JS_CallFunction
|
||||
JS_EvaluateScriptForPrincipals
|
||||
JS_EvaluateScript
|
||||
JS_ExecuteScript
|
||||
JS_DecompileFunctionBody
|
||||
JS_DecompileFunction
|
||||
JS_DecompileScript
|
||||
JS_CompileFunctionForPrincipals
|
||||
JS_CompileFunction
|
||||
JS_DestroyScript
|
||||
JS_CompileScriptForPrincipals
|
||||
JS_CompileScript
|
||||
JS_DefineFunction
|
||||
JS_GetFunctionName
|
||||
JS_GetFunctionObject
|
||||
JS_NewFunction
|
||||
JS_ClearScope
|
||||
JS_DeleteElement
|
||||
JS_SetElement
|
||||
JS_GetElement
|
||||
JS_LookupElement
|
||||
JS_AliasElement
|
||||
JS_DefineElement
|
||||
JS_SetArrayLength
|
||||
JS_GetArrayLength
|
||||
JS_NewArrayObject
|
||||
JS_DeleteProperty
|
||||
JS_SetProperty
|
||||
JS_GetProperty
|
||||
JS_LookupProperty
|
||||
JS_AliasProperty
|
||||
JS_DefinePropertyWithTinyId
|
||||
JS_DefineProperty
|
||||
JS_DefineConstDoubles
|
||||
JS_DefineObject
|
||||
JS_NewObject
|
||||
JS_GetConstructor
|
||||
JS_SetParent
|
||||
JS_GetParent
|
||||
JS_SetPrototype
|
||||
JS_GetPrototype
|
||||
JS_GetInstancePrivate
|
||||
JS_SetPrivate
|
||||
JS_GetPrivate
|
||||
JS_InstanceOf
|
||||
JS_GetClass
|
||||
JS_DefineFunctions
|
||||
JS_DefineProperties
|
||||
JS_InitClass
|
||||
JS_FinalizeStub
|
||||
JS_ConvertStub
|
||||
JS_ResolveStub
|
||||
JS_EnumerateStub
|
||||
JS_PropertyStub
|
||||
JS_GC
|
||||
JS_UnlockGCThing
|
||||
JS_LockGCThing
|
||||
JS_RemoveRoot
|
||||
JS_AddRoot
|
||||
JS_NewDoubleValue
|
||||
JS_NewDouble
|
||||
JS_strdup
|
||||
JS_free
|
||||
JS_realloc
|
||||
JS_ReportOutOfMemory
|
||||
JS_malloc
|
||||
JS_GetScopeChain
|
||||
JS_InitStandardClasses
|
||||
JS_SetGlobalObject
|
||||
JS_GetGlobalObject
|
||||
JS_SetVersion
|
||||
JS_GetVersion
|
||||
JS_ContextIterator
|
||||
JS_GetTaskState
|
||||
JS_DestroyContext
|
||||
JS_NewContext
|
||||
JS_Unlock
|
||||
JS_Lock
|
||||
JS_Finish
|
||||
JS_Init
|
||||
JS_GetTypeName
|
||||
JS_TypeOfValue
|
||||
JS_ValueToBoolean
|
||||
JS_ValueToInt32
|
||||
JS_ValueToNumber
|
||||
JS_ValueToString
|
||||
JS_ValueToFunction
|
||||
JS_ValueToObject
|
||||
JS_ReportError
|
||||
JS_ConvertValue
|
||||
JS_GetEmptyStringValue
|
||||
JS_GetPositiveInfinityValue
|
||||
JS_GetNegativeInfinityValue
|
||||
JS_GetNaNValue
|
||||
;DSR062897 - added for GA code
|
||||
JS_MaybeGC
|
||||
JS_GetScriptPrincipals
|
||||
JS_IsAssigning
|
||||
JS_SetCharSetInfo
|
||||
;
|
||||
;
|
||||
;00023:prmjtime (OFFSET:0x000dae0f, SIZE:0x00008986):
|
||||
; - Public Definitions:
|
||||
PRMJ_FormatTimeUSEnglish
|
||||
PRMJ_gmtime
|
||||
PRMJ_FormatTime
|
||||
PRMJ_mktime
|
||||
PRMJ_ComputeTime
|
||||
PRMJ_localtime
|
||||
PRMJ_ExplodeTime
|
||||
PRMJ_ToLocal
|
||||
PRMJ_ToGMT
|
||||
PRMJ_NowLocal
|
||||
PRMJ_DSTOffset
|
||||
PRMJ_NowS
|
||||
PRMJ_NowMS
|
||||
PRMJ_Now
|
||||
PRMJ_ToExtendedTime
|
||||
PRMJ_ToBaseTime
|
||||
PRMJ_setDST
|
||||
PRMJ_LocalGMTDifference
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8 -*-
|
||||
* Copyright © 1996 Netscape Communications Corporation, All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "jsinterp.h"
|
||||
|
||||
/* These functions are needed to get the addresses of certain functions
|
||||
* in the JS module. On WIN32 especially, these symbols have a different
|
||||
* address from the actual address of these functions in the JS module.
|
||||
* This is because on WIN32, import function address fixups are done only
|
||||
* at load time and function calls are made by indirection - that is by
|
||||
* using a couple extra instructions to lookup the actual function address
|
||||
* in the importing module's import address table.
|
||||
*/
|
||||
|
||||
IMPLEMENT(JSPropertyOp)
|
||||
js_GetArgumentAddress()
|
||||
{
|
||||
return ((void *)js_GetArgument);
|
||||
}
|
||||
|
||||
IMPLEMENT(JSPropertyOp)
|
||||
js_SetArgumentAddress()
|
||||
{
|
||||
return ((void *)js_SetArgument);
|
||||
}
|
||||
|
||||
IMPLEMENT(JSPropertyOp)
|
||||
js_GetLocalVariableAddress()
|
||||
{
|
||||
return ((void *)js_GetLocalVariable);
|
||||
}
|
||||
|
||||
IMPLEMENT(JSPropertyOp)
|
||||
js_SetLocalVariableAddress()
|
||||
{
|
||||
return ((void *)js_SetLocalVariable);
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8 -*-
|
||||
* Copyright © 1996 Netscape Communications Corporation, All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef jsaddr_h___
|
||||
#define jsaddr_h___
|
||||
|
||||
EXTERN(JSPropertyOp)
|
||||
js_GetArgumentAddress();
|
||||
|
||||
EXTERN(JSPropertyOp)
|
||||
js_SetArgumentAddress();
|
||||
|
||||
EXTERN(JSPropertyOp)
|
||||
js_GetLocalVariableAddress();
|
||||
|
||||
EXTERN(JSPropertyOp)
|
||||
js_SetLocalVariableAddress();
|
||||
|
||||
#endif /* jsaddr_h___ */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,343 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Lifetime-based fast allocation, inspired by much prior art, including
|
||||
* "Fast Allocation and Deallocation of Memory Based on Object Lifetimes"
|
||||
* David R. Hanson, Software -- Practice and Experience, Vol. 20(1).
|
||||
*/
|
||||
#include "jsstddef.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "jstypes.h"
|
||||
#include "jsbit.h"
|
||||
#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(jsword *, jsword, jsword);
|
||||
#endif
|
||||
|
||||
static JSArena *arena_freelist;
|
||||
|
||||
#ifdef JS_ARENAMETER
|
||||
static JSArenaStats *arena_stats_list;
|
||||
|
||||
#define COUNT(pool,what) (pool)->stats.what++
|
||||
#else
|
||||
#define COUNT(pool,what) /* nothing */
|
||||
#endif
|
||||
|
||||
#define JS_ARENA_DEFAULT_ALIGN sizeof(double)
|
||||
|
||||
IMPLEMENT(void)
|
||||
JS_InitArenaPool(JSArenaPool *pool, const char *name, JSUint32 size, JSUint32 align)
|
||||
{
|
||||
if (align == 0)
|
||||
align = JS_ARENA_DEFAULT_ALIGN;
|
||||
pool->mask = JS_BITMASK(JS_CeilingLog2(align));
|
||||
pool->first.next = NULL;
|
||||
pool->first.base = pool->first.avail = pool->first.limit =
|
||||
(jsuword)JS_ARENA_ALIGN(pool, &pool->first + 1);
|
||||
pool->current = &pool->first;
|
||||
pool->arenasize = size;
|
||||
#ifdef JS_ARENAMETER
|
||||
memset(&pool->stats, 0, sizeof pool->stats);
|
||||
pool->stats.name = strdup(name);
|
||||
pool->stats.next = arena_stats_list;
|
||||
arena_stats_list = &pool->stats;
|
||||
#endif
|
||||
}
|
||||
|
||||
IMPLEMENT(void *)
|
||||
JS_ArenaAllocate(JSArenaPool *pool, JSUint32 nb)
|
||||
{
|
||||
JSArena **ap, *a, *b;
|
||||
#ifdef JS_THREADSAFE
|
||||
JSArena *c;
|
||||
#endif
|
||||
JSUint32 sz;
|
||||
void *p;
|
||||
|
||||
JS_ASSERT((nb & pool->mask) == 0);
|
||||
#if defined(XP_PC) && !defined(_WIN32)
|
||||
if (nb >= 60000U)
|
||||
return 0;
|
||||
#endif /* WIN16 */
|
||||
ap = &arena_freelist;
|
||||
for (a = pool->current; a->avail + nb > a->limit; pool->current = a) {
|
||||
if (a->next) { /* move to next arena */
|
||||
a = a->next;
|
||||
continue;
|
||||
}
|
||||
while ((b = *ap) != NULL) { /* reclaim a free arena */
|
||||
if (b->limit - b->base == pool->arenasize) {
|
||||
#ifdef JS_THREADSAFE
|
||||
do {
|
||||
b = *ap;
|
||||
c = b->next;
|
||||
} while (!js_CompareAndSwap((jsword *)ap,(jsword)b,(jsword)c));
|
||||
#else
|
||||
*ap = b->next;
|
||||
#endif
|
||||
b->next = NULL;
|
||||
a = a->next = b;
|
||||
COUNT(pool, nreclaims);
|
||||
goto claim;
|
||||
}
|
||||
ap = &b->next;
|
||||
}
|
||||
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 = (jsuword)a + sz;
|
||||
JS_COUNT_ARENA(pool,++);
|
||||
COUNT(pool, nmallocs);
|
||||
claim:
|
||||
a->base = a->avail = (jsuword)JS_ARENA_ALIGN(pool, a + 1);
|
||||
}
|
||||
p = (void *)a->avail;
|
||||
a->avail += nb;
|
||||
return p;
|
||||
}
|
||||
|
||||
IMPLEMENT(void *)
|
||||
JS_ArenaGrow(JSArenaPool *pool, void *p, JSUint32 size, JSUint32 incr)
|
||||
{
|
||||
void *newp;
|
||||
|
||||
JS_ARENA_ALLOCATE(newp, pool, size + incr);
|
||||
memcpy(newp, p, size);
|
||||
return newp;
|
||||
}
|
||||
|
||||
/*
|
||||
* Free tail arenas linked after head, which may not be the true list head.
|
||||
* Reset pool->current to point to head in case it pointed at a tail arena.
|
||||
*/
|
||||
static void
|
||||
FreeArenaList(JSArenaPool *pool, JSArena *head, JSBool reallyFree)
|
||||
{
|
||||
JSArena **ap, *a;
|
||||
#ifdef JS_THREADSAFE
|
||||
JSArena *b;
|
||||
#endif
|
||||
|
||||
ap = &head->next;
|
||||
a = *ap;
|
||||
if (!a)
|
||||
return;
|
||||
|
||||
#ifdef DEBUG
|
||||
do {
|
||||
JS_ASSERT(a->base <= a->avail && a->avail <= a->limit);
|
||||
a->avail = a->base;
|
||||
JS_CLEAR_UNUSED(a);
|
||||
} while ((a = a->next) != NULL);
|
||||
a = *ap;
|
||||
#endif
|
||||
|
||||
if (reallyFree) {
|
||||
do {
|
||||
*ap = a->next;
|
||||
JS_CLEAR_ARENA(a);
|
||||
JS_COUNT_ARENA(pool,--);
|
||||
free(a);
|
||||
} while ((a = *ap) != NULL);
|
||||
} else {
|
||||
/* Insert the whole arena chain at the front of the freelist. */
|
||||
do {
|
||||
ap = &(*ap)->next;
|
||||
} while (*ap);
|
||||
#ifdef JS_THREADSAFE
|
||||
do {
|
||||
*ap = b = arena_freelist;
|
||||
} while (!js_CompareAndSwap((jsword*)&arena_freelist,(jsword)b,(jsword)a));
|
||||
#else
|
||||
*ap = arena_freelist;
|
||||
arena_freelist = a;
|
||||
#endif
|
||||
head->next = NULL;
|
||||
}
|
||||
|
||||
pool->current = head;
|
||||
}
|
||||
|
||||
IMPLEMENT(void)
|
||||
JS_ArenaRelease(JSArenaPool *pool, char *mark)
|
||||
{
|
||||
JSArena *a;
|
||||
|
||||
for (a = pool->first.next; a; a = a->next) {
|
||||
if (JS_UPTRDIFF(mark, a) < JS_UPTRDIFF(a->avail, a)) {
|
||||
a->avail = (jsuword)JS_ARENA_ALIGN(pool, mark);
|
||||
FreeArenaList(pool, a, JS_TRUE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IMPLEMENT(void)
|
||||
JS_FreeArenaPool(JSArenaPool *pool)
|
||||
{
|
||||
FreeArenaList(pool, &pool->first, JS_FALSE);
|
||||
COUNT(pool, ndeallocs);
|
||||
}
|
||||
|
||||
IMPLEMENT(void)
|
||||
JS_FinishArenaPool(JSArenaPool *pool)
|
||||
{
|
||||
FreeArenaList(pool, &pool->first, JS_TRUE);
|
||||
#ifdef JS_ARENAMETER
|
||||
{
|
||||
JSArenaStats *stats, **statsp;
|
||||
|
||||
if (pool->stats.name)
|
||||
free(pool->stats.name);
|
||||
for (statsp = &arena_stats_list; (stats = *statsp) != 0;
|
||||
statsp = &stats->next) {
|
||||
if (stats == &pool->stats) {
|
||||
*statsp = stats->next;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
IMPLEMENT(void)
|
||||
JS_CompactArenaPool(JSArenaPool *pool)
|
||||
{
|
||||
#if 0 /* XP_MAC */
|
||||
JSArena *a = pool->first.next;
|
||||
|
||||
while (a) {
|
||||
reallocSmaller(a, a->avail - (jsuword)a);
|
||||
a->limit = a->avail;
|
||||
a = a->next;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
IMPLEMENT(void)
|
||||
JS_ArenaFinish()
|
||||
{
|
||||
JSArena *a, *next;
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
while (arena_freelist) {
|
||||
a = arena_freelist;
|
||||
next = a->next;
|
||||
if (js_CompareAndSwap((jsword*)&arena_freelist,(jsword)a,(jsword)next))
|
||||
free(a);
|
||||
}
|
||||
#else
|
||||
for (a = arena_freelist; a; a = next) {
|
||||
next = a->next;
|
||||
free(a);
|
||||
}
|
||||
arena_freelist = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef JS_ARENAMETER
|
||||
IMPLEMENT(void)
|
||||
JS_ArenaCountAllocation(JSArenaPool *pool, JSUint32 nb)
|
||||
{
|
||||
pool->stats.nallocs++;
|
||||
pool->stats.nbytes += nb;
|
||||
if (nb > pool->stats.maxalloc)
|
||||
pool->stats.maxalloc = nb;
|
||||
pool->stats.variance += nb * nb;
|
||||
}
|
||||
|
||||
IMPLEMENT(void)
|
||||
JS_ArenaCountInplaceGrowth(JSArenaPool *pool, JSUint32 size, JSUint32 incr)
|
||||
{
|
||||
pool->stats.ninplace++;
|
||||
}
|
||||
|
||||
IMPLEMENT(void)
|
||||
JS_ArenaCountGrowth(JSArenaPool *pool, JSUint32 size, JSUint32 incr)
|
||||
{
|
||||
pool->stats.ngrows++;
|
||||
pool->stats.nbytes += incr;
|
||||
pool->stats.variance -= size * size;
|
||||
size += incr;
|
||||
if (size > pool->stats.maxalloc)
|
||||
pool->stats.maxalloc = size;
|
||||
pool->stats.variance += size * size;
|
||||
}
|
||||
|
||||
IMPLEMENT(void)
|
||||
JS_ArenaCountRelease(JSArenaPool *pool, char *mark)
|
||||
{
|
||||
pool->stats.nreleases++;
|
||||
}
|
||||
|
||||
IMPLEMENT(void)
|
||||
JS_ArenaCountRetract(JSArenaPool *pool, char *mark)
|
||||
{
|
||||
pool->stats.nfastrels++;
|
||||
}
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
IMPLEMENT(void)
|
||||
JS_DumpArenaStats(FILE *fp)
|
||||
{
|
||||
JSArenaStats *stats;
|
||||
double mean, variance;
|
||||
|
||||
for (stats = arena_stats_list; stats; stats = stats->next) {
|
||||
if (stats->nallocs != 0) {
|
||||
mean = (double)stats->nbytes / stats->nallocs;
|
||||
variance = fabs(stats->variance / stats->nallocs - mean * mean);
|
||||
} else {
|
||||
mean = variance = 0;
|
||||
}
|
||||
|
||||
fprintf(fp, "\n%s allocation statistics:\n", stats->name);
|
||||
fprintf(fp, " number of arenas: %u\n", stats->narenas);
|
||||
fprintf(fp, " number of allocations: %u\n", stats->nallocs);
|
||||
fprintf(fp, " number of free arena reclaims: %u\n", stats->nreclaims);
|
||||
fprintf(fp, " number of malloc calls: %u\n", stats->nmallocs);
|
||||
fprintf(fp, " number of deallocations: %u\n", stats->ndeallocs);
|
||||
fprintf(fp, " number of allocation growths: %u\n", stats->ngrows);
|
||||
fprintf(fp, " number of in-place growths: %u\n", stats->ninplace);
|
||||
fprintf(fp, "number of released allocations: %u\n", stats->nreleases);
|
||||
fprintf(fp, " number of fast releases: %u\n", stats->nfastrels);
|
||||
fprintf(fp, " total bytes allocated: %u\n", stats->nbytes);
|
||||
fprintf(fp, " mean allocation size: %g\n", mean);
|
||||
fprintf(fp, " standard deviation: %g\n", sqrt(variance));
|
||||
fprintf(fp, " maximum allocation size: %u\n", stats->maxalloc);
|
||||
}
|
||||
}
|
||||
#endif /* JS_ARENAMETER */
|
||||
@@ -1,246 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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___ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,56 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 jsarray_h___
|
||||
#define jsarray_h___
|
||||
/*
|
||||
* JS Array interface.
|
||||
*/
|
||||
#include "jsprvtd.h"
|
||||
#include "jspubtd.h"
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
extern JSClass js_ArrayClass;
|
||||
|
||||
extern JSObject *
|
||||
js_InitArrayClass(JSContext *cx, JSObject *obj);
|
||||
|
||||
extern JSObject *
|
||||
js_NewArrayObject(JSContext *cx, jsuint length, jsval *vector);
|
||||
|
||||
extern JSBool
|
||||
js_GetLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
|
||||
|
||||
extern JSBool
|
||||
js_SetLengthProperty(JSContext *cx, JSObject *obj, jsuint length);
|
||||
|
||||
extern JSBool
|
||||
js_HasLengthProperty(JSContext *cx, JSObject *obj, jsuint *lengthp);
|
||||
|
||||
/*
|
||||
* JS-specific qsort function.
|
||||
*/
|
||||
typedef int (*JSComparator)(const void *a, const void *b, void *arg);
|
||||
|
||||
extern JSBool
|
||||
js_qsort(void *vec, size_t nel, size_t elsize, JSComparator cmp, void *arg);
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsarray_h___ */
|
||||
@@ -1,672 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 atom table.
|
||||
*/
|
||||
#include "jsstddef.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "jstypes.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
|
||||
#include "jsprf.h"
|
||||
#include "jsapi.h"
|
||||
#include "jsatom.h"
|
||||
#include "jscntxt.h"
|
||||
#include "jsgc.h"
|
||||
#include "jslock.h"
|
||||
#include "jsnum.h"
|
||||
#include "jsopcode.h"
|
||||
#include "jsstr.h"
|
||||
|
||||
/*
|
||||
* Keep this in sync with jspubtd.h -- an assertion below will insist that
|
||||
* its length match the JSType enum's JSTYPE_LIMIT limit value.
|
||||
*/
|
||||
char *js_type_str[] = {
|
||||
"undefined",
|
||||
"object",
|
||||
"function",
|
||||
"string",
|
||||
"number",
|
||||
"boolean",
|
||||
};
|
||||
|
||||
char *js_boolean_str[] = {
|
||||
js_false_str,
|
||||
js_true_str
|
||||
};
|
||||
|
||||
char js_Array_str[] = "Array";
|
||||
char js_Math_str[] = "Math";
|
||||
char js_Object_str[] = "Object";
|
||||
char js_anonymous_str[] = "anonymous";
|
||||
char js_arguments_str[] = "arguments";
|
||||
char js_arity_str[] = "arity";
|
||||
char js_assign_str[] = "assign";
|
||||
char js_callee_str[] = "callee";
|
||||
char js_caller_str[] = "caller";
|
||||
char js_class_prototype_str[] = "prototype";
|
||||
char js_constructor_str[] = "constructor";
|
||||
char js_count_str[] = "__count__";
|
||||
char js_eval_str[] = "eval";
|
||||
char js_index_str[] = "index";
|
||||
char js_input_str[] = "input";
|
||||
char js_length_str[] = "length";
|
||||
char js_name_str[] = "name";
|
||||
char js_parent_str[] = "__parent__";
|
||||
char js_proto_str[] = "__proto__";
|
||||
char js_toSource_str[] = "toSource";
|
||||
char js_toString_str[] = "toString";
|
||||
char js_valueOf_str[] = "valueOf";
|
||||
|
||||
#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))
|
||||
|
||||
STATIC_DLL_CALLBACK(JSHashNumber)
|
||||
js_hash_atom_key(const void *key)
|
||||
{
|
||||
jsval v;
|
||||
jsdouble *dp;
|
||||
|
||||
/* Order JSVAL_IS_* tests by likelihood of success. */
|
||||
v = (jsval)key;
|
||||
if (JSVAL_IS_STRING(v))
|
||||
return js_HashString(JSVAL_TO_STRING(v));
|
||||
if (JSVAL_IS_INT(v))
|
||||
return HASH_INT(JSVAL_TO_INT(v));
|
||||
if (JSVAL_IS_DOUBLE(v)) {
|
||||
dp = JSVAL_TO_DOUBLE(v);
|
||||
return HASH_DOUBLE(dp);
|
||||
}
|
||||
if (JSVAL_IS_OBJECT(v))
|
||||
return HASH_OBJECT(JSVAL_TO_OBJECT(v));
|
||||
if (JSVAL_IS_BOOLEAN(v))
|
||||
return HASH_BOOLEAN(JSVAL_TO_BOOLEAN(v));
|
||||
return (JSHashNumber)v;
|
||||
}
|
||||
|
||||
STATIC_DLL_CALLBACK(intN)
|
||||
js_compare_atom_keys(const void *k1, const void *k2)
|
||||
{
|
||||
jsval v1, v2;
|
||||
|
||||
v1 = (jsval)k1, v2 = (jsval)k2;
|
||||
if (JSVAL_IS_STRING(v1) && JSVAL_IS_STRING(v2))
|
||||
return !js_CompareStrings(JSVAL_TO_STRING(v1), JSVAL_TO_STRING(v2));
|
||||
if (JSVAL_IS_DOUBLE(v1) && JSVAL_IS_DOUBLE(v2)) {
|
||||
double d1 = *JSVAL_TO_DOUBLE(v1);
|
||||
double d2 = *JSVAL_TO_DOUBLE(v2);
|
||||
if (JSDOUBLE_IS_NaN(d1))
|
||||
return JSDOUBLE_IS_NaN(d2);
|
||||
#ifdef XP_PC
|
||||
/* XXX MSVC miscompiles such that (NaN == 0) */
|
||||
if (JSDOUBLE_IS_NaN(d2))
|
||||
return JS_FALSE;
|
||||
#endif
|
||||
return d1 == d2;
|
||||
}
|
||||
return v1 == v2;
|
||||
}
|
||||
|
||||
STATIC_DLL_CALLBACK(int)
|
||||
js_compare_stub(const void *v1, const void *v2)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
STATIC_DLL_CALLBACK(void *)
|
||||
js_alloc_atom_space(void *priv, size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
STATIC_DLL_CALLBACK(void)
|
||||
js_free_atom_space(void *priv, void *item)
|
||||
{
|
||||
free(item);
|
||||
}
|
||||
|
||||
STATIC_DLL_CALLBACK(JSHashEntry *)
|
||||
js_alloc_atom(void *priv, const void *key)
|
||||
{
|
||||
JSAtomState *state = priv;
|
||||
JSAtom *atom;
|
||||
|
||||
atom = malloc(sizeof(JSAtom));
|
||||
if (!atom)
|
||||
return NULL;
|
||||
#ifdef JS_THREADSAFE
|
||||
state->tablegen++;
|
||||
#endif
|
||||
atom->entry.key = key;
|
||||
atom->entry.value = NULL;
|
||||
atom->flags = 0;
|
||||
atom->kwindex = -1;
|
||||
atom->number = state->number++;
|
||||
return &atom->entry;
|
||||
}
|
||||
|
||||
STATIC_DLL_CALLBACK(void)
|
||||
js_free_atom(void *priv, JSHashEntry *he, uintN flag)
|
||||
{
|
||||
if (flag != HT_FREE_ENTRY)
|
||||
return;
|
||||
#ifdef JS_THREADSAFE
|
||||
((JSAtomState *)priv)->tablegen++;
|
||||
#endif
|
||||
free(he);
|
||||
}
|
||||
|
||||
static JSHashAllocOps atom_alloc_ops = {
|
||||
js_alloc_atom_space, js_free_atom_space,
|
||||
js_alloc_atom, js_free_atom
|
||||
};
|
||||
|
||||
#define JS_ATOM_HASH_SIZE 1024
|
||||
|
||||
JSBool
|
||||
js_InitAtomState(JSContext *cx, JSAtomState *state)
|
||||
{
|
||||
uintN i;
|
||||
|
||||
state->runtime = cx->runtime;
|
||||
state->number = 0;
|
||||
state->table = JS_NewHashTable(JS_ATOM_HASH_SIZE, js_hash_atom_key,
|
||||
js_compare_atom_keys, js_compare_stub,
|
||||
&atom_alloc_ops, state);
|
||||
if (!state->table) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return JS_FALSE;
|
||||
}
|
||||
#ifdef JS_THREADSAFE
|
||||
js_NewLock(&state->lock);
|
||||
state->tablegen = 0;
|
||||
#endif
|
||||
|
||||
#define FROB(lval,str) { \
|
||||
if (!(state->lval = js_Atomize(cx, str, strlen(str), ATOM_PINNED))) { \
|
||||
js_FreeAtomState(cx, state); \
|
||||
return JS_FALSE; \
|
||||
} \
|
||||
}
|
||||
|
||||
JS_ASSERT(sizeof js_type_str / sizeof js_type_str[0] == JSTYPE_LIMIT);
|
||||
for (i = 0; i < JSTYPE_LIMIT; i++)
|
||||
FROB(typeAtoms[i], js_type_str[i]);
|
||||
|
||||
FROB(booleanAtoms[0], js_false_str);
|
||||
FROB(booleanAtoms[1], js_true_str);
|
||||
FROB(nullAtom, js_null_str);
|
||||
|
||||
FROB(ArrayAtom, js_Array_str);
|
||||
FROB(MathAtom, js_Math_str);
|
||||
FROB(ObjectAtom, js_Object_str);
|
||||
FROB(anonymousAtom, js_anonymous_str);
|
||||
FROB(argumentsAtom, js_arguments_str);
|
||||
FROB(arityAtom, js_arity_str);
|
||||
FROB(assignAtom, js_assign_str);
|
||||
FROB(calleeAtom, js_callee_str);
|
||||
FROB(callerAtom, js_caller_str);
|
||||
FROB(classPrototypeAtom, js_class_prototype_str);
|
||||
FROB(constructorAtom, js_constructor_str);
|
||||
FROB(countAtom, js_count_str);
|
||||
FROB(indexAtom, js_index_str);
|
||||
FROB(inputAtom, js_input_str);
|
||||
FROB(lengthAtom, js_length_str);
|
||||
FROB(nameAtom, js_name_str);
|
||||
FROB(parentAtom, js_parent_str);
|
||||
FROB(protoAtom, js_proto_str);
|
||||
FROB(toSourceAtom, js_toSource_str);
|
||||
FROB(toStringAtom, js_toString_str);
|
||||
FROB(valueOfAtom, js_valueOf_str);
|
||||
|
||||
#undef FROB
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
js_FreeAtomState(JSContext *cx, JSAtomState *state)
|
||||
{
|
||||
state->runtime = NULL;
|
||||
JS_HashTableDestroy(state->table);
|
||||
state->table = NULL;
|
||||
state->number = 0;
|
||||
#ifdef JS_THREADSAFE
|
||||
js_DestroyLock(&state->lock);
|
||||
#endif
|
||||
}
|
||||
|
||||
typedef struct MarkArgs {
|
||||
JSRuntime *runtime;
|
||||
JSGCThingMarker mark;
|
||||
} MarkArgs;
|
||||
|
||||
STATIC_DLL_CALLBACK(intN)
|
||||
js_atom_marker(JSHashEntry *he, intN i, void *arg)
|
||||
{
|
||||
JSAtom *atom;
|
||||
jsval key;
|
||||
MarkArgs *args;
|
||||
|
||||
atom = (JSAtom *)he;
|
||||
if (atom->flags & ATOM_PINNED) {
|
||||
atom->flags |= ATOM_MARK;
|
||||
key = ATOM_KEY(atom);
|
||||
if (JSVAL_IS_GCTHING(key)) {
|
||||
args = arg;
|
||||
args->mark(args->runtime, JSVAL_TO_GCTHING(key));
|
||||
}
|
||||
}
|
||||
return HT_ENUMERATE_NEXT;
|
||||
}
|
||||
|
||||
void
|
||||
js_MarkAtomState(JSAtomState *state, JSGCThingMarker mark)
|
||||
{
|
||||
MarkArgs args;
|
||||
|
||||
args.runtime = state->runtime;
|
||||
args.mark = mark;
|
||||
JS_HashTableEnumerateEntries(state->table, js_atom_marker, &args);
|
||||
}
|
||||
|
||||
STATIC_DLL_CALLBACK(intN)
|
||||
js_atom_sweeper(JSHashEntry *he, intN i, void *arg)
|
||||
{
|
||||
JSAtom *atom;
|
||||
|
||||
atom = (JSAtom *)he;
|
||||
if (atom->flags & ATOM_MARK) {
|
||||
atom->flags &= ~ATOM_MARK;
|
||||
return HT_ENUMERATE_NEXT;
|
||||
}
|
||||
JS_ASSERT((atom->flags & ATOM_PINNED) == 0);
|
||||
atom->entry.key = NULL;
|
||||
atom->flags = 0;
|
||||
return HT_ENUMERATE_REMOVE;
|
||||
}
|
||||
|
||||
void
|
||||
js_SweepAtomState(JSAtomState *state)
|
||||
{
|
||||
JS_HashTableEnumerateEntries(state->table, js_atom_sweeper, NULL);
|
||||
}
|
||||
|
||||
STATIC_DLL_CALLBACK(intN)
|
||||
js_atom_unpinner(JSHashEntry *he, intN i, void *arg)
|
||||
{
|
||||
JSAtom *atom;
|
||||
|
||||
atom = (JSAtom *)he;
|
||||
atom->flags &= ~ATOM_PINNED;
|
||||
return HT_ENUMERATE_NEXT;
|
||||
}
|
||||
|
||||
void
|
||||
js_UnpinPinnedAtoms(JSAtomState *state)
|
||||
{
|
||||
JS_HashTableEnumerateEntries(state->table, js_atom_unpinner, NULL);
|
||||
}
|
||||
|
||||
static JSAtom *
|
||||
js_AtomizeHashedKey(JSContext *cx, jsval key, JSHashNumber keyHash, uintN flags)
|
||||
{
|
||||
JSAtomState *state;
|
||||
JSHashTable *table;
|
||||
JSHashEntry *he, **hep;
|
||||
JSAtom *atom;
|
||||
|
||||
state = &cx->runtime->atomState;
|
||||
JS_LOCK(&state->lock,cx);
|
||||
table = state->table;
|
||||
hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
|
||||
if ((he = *hep) == NULL) {
|
||||
he = JS_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL);
|
||||
if (!he) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
atom = NULL;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
atom = (JSAtom *)he;
|
||||
atom->flags |= flags;
|
||||
out:
|
||||
JS_UNLOCK(&state->lock,cx);
|
||||
return atom;
|
||||
}
|
||||
|
||||
JSAtom *
|
||||
js_AtomizeObject(JSContext *cx, JSObject *obj, uintN flags)
|
||||
{
|
||||
jsval key;
|
||||
JSHashNumber keyHash;
|
||||
|
||||
/* XXX must be set in the following order or MSVC1.52 will crash */
|
||||
keyHash = HASH_OBJECT(obj);
|
||||
key = OBJECT_TO_JSVAL(obj);
|
||||
return js_AtomizeHashedKey(cx, key, keyHash, flags);
|
||||
}
|
||||
|
||||
JSAtom *
|
||||
js_AtomizeBoolean(JSContext *cx, JSBool b, uintN flags)
|
||||
{
|
||||
jsval key;
|
||||
JSHashNumber keyHash;
|
||||
|
||||
key = BOOLEAN_TO_JSVAL(b);
|
||||
keyHash = HASH_BOOLEAN(b);
|
||||
return js_AtomizeHashedKey(cx, key, keyHash, flags);
|
||||
}
|
||||
|
||||
JSAtom *
|
||||
js_AtomizeInt(JSContext *cx, jsint i, uintN flags)
|
||||
{
|
||||
jsval key;
|
||||
JSHashNumber keyHash;
|
||||
|
||||
key = INT_TO_JSVAL(i);
|
||||
keyHash = HASH_INT(i);
|
||||
return js_AtomizeHashedKey(cx, key, keyHash, flags);
|
||||
}
|
||||
|
||||
JSAtom *
|
||||
js_AtomizeDouble(JSContext *cx, jsdouble d, uintN flags)
|
||||
{
|
||||
jsdouble *dp;
|
||||
JSHashNumber keyHash;
|
||||
jsval key;
|
||||
JSAtomState *state;
|
||||
JSHashTable *table;
|
||||
JSHashEntry *he, **hep;
|
||||
JSAtom *atom;
|
||||
|
||||
#if JS_ALIGN_OF_DOUBLE == 8
|
||||
dp = &d;
|
||||
#else
|
||||
char alignbuf[16];
|
||||
|
||||
dp = (jsdouble *)&alignbuf[8 - ((jsuword)&alignbuf & 7)];
|
||||
*dp = d;
|
||||
#endif
|
||||
|
||||
keyHash = HASH_DOUBLE(dp);
|
||||
key = DOUBLE_TO_JSVAL(dp);
|
||||
state = &cx->runtime->atomState;
|
||||
JS_LOCK(&state->lock,cx);
|
||||
table = state->table;
|
||||
hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
|
||||
if ((he = *hep) == NULL) {
|
||||
#ifdef JS_THREADSAFE
|
||||
uint32 gen = state->tablegen;
|
||||
#endif
|
||||
JS_UNLOCK(&state->lock,cx);
|
||||
if (!js_NewDoubleValue(cx, d, &key))
|
||||
return NULL;
|
||||
JS_LOCK(&state->lock,cx);
|
||||
#ifdef JS_THREADSAFE
|
||||
if (state->tablegen != gen) {
|
||||
hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
|
||||
if ((he = *hep) != NULL) {
|
||||
atom = (JSAtom *)he;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
he = JS_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL);
|
||||
if (!he) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
atom = NULL;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
atom = (JSAtom *)he;
|
||||
atom->flags |= flags;
|
||||
out:
|
||||
JS_UNLOCK(&state->lock,cx);
|
||||
return atom;
|
||||
}
|
||||
|
||||
JSAtom *
|
||||
js_AtomizeString(JSContext *cx, JSString *str, uintN flags)
|
||||
{
|
||||
JSHashNumber keyHash;
|
||||
jsval key;
|
||||
JSAtomState *state;
|
||||
JSHashTable *table;
|
||||
JSHashEntry *he, **hep;
|
||||
JSAtom *atom;
|
||||
|
||||
keyHash = js_HashString(str);
|
||||
key = STRING_TO_JSVAL(str);
|
||||
state = &cx->runtime->atomState;
|
||||
JS_LOCK(&state->lock,cx);
|
||||
table = state->table;
|
||||
hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
|
||||
if ((he = *hep) == NULL) {
|
||||
if (flags & ATOM_TMPSTR) {
|
||||
#ifdef JS_THREADSAFE
|
||||
uint32 gen = state->tablegen;
|
||||
#endif
|
||||
JS_UNLOCK(&state->lock,cx);
|
||||
flags &= ~ATOM_TMPSTR;
|
||||
if (flags & ATOM_NOCOPY) {
|
||||
flags &= ~ATOM_NOCOPY;
|
||||
str = js_NewString(cx, str->chars, str->length, 0);
|
||||
} else {
|
||||
str = js_NewStringCopyN(cx, str->chars, str->length, 0);
|
||||
}
|
||||
if (!str)
|
||||
return NULL;
|
||||
key = STRING_TO_JSVAL(str);
|
||||
JS_LOCK(&state->lock,cx);
|
||||
#ifdef JS_THREADSAFE
|
||||
if (state->tablegen != gen) {
|
||||
hep = JS_HashTableRawLookup(table, keyHash, (void *)key);
|
||||
if ((he = *hep) != NULL) {
|
||||
atom = (JSAtom *)he;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
he = JS_HashTableRawAdd(table, hep, keyHash, (void *)key, NULL);
|
||||
if (!he) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
atom = NULL;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
atom = (JSAtom *)he;
|
||||
atom->flags |= flags;
|
||||
out:
|
||||
JS_UNLOCK(&state->lock,cx);
|
||||
return atom;
|
||||
}
|
||||
|
||||
JS_FRIEND_API(JSAtom *)
|
||||
js_Atomize(JSContext *cx, const char *bytes, size_t length, uintN flags)
|
||||
{
|
||||
jschar *chars;
|
||||
JSString *str;
|
||||
JSAtom *atom;
|
||||
#if JS_ALIGN_OF_DOUBLE == 8
|
||||
union { jsdouble d; JSString s; } u;
|
||||
|
||||
str = &u.s;
|
||||
#else
|
||||
char alignbuf[16];
|
||||
|
||||
str = (JSString *)&alignbuf[8 - ((jsuword)&alignbuf & 7)];
|
||||
#endif
|
||||
|
||||
chars = js_InflateString(cx, bytes, length);
|
||||
if (!chars)
|
||||
return NULL;
|
||||
str->chars = chars;
|
||||
str->length = length;
|
||||
atom = js_AtomizeString(cx, str, ATOM_TMPSTR | ATOM_NOCOPY | flags);
|
||||
if (!atom || ATOM_TO_STRING(atom)->chars != chars)
|
||||
JS_free(cx, chars);
|
||||
return atom;
|
||||
}
|
||||
|
||||
JS_FRIEND_API(JSAtom *)
|
||||
js_AtomizeChars(JSContext *cx, const jschar *chars, size_t length, uintN flags)
|
||||
{
|
||||
JSString *str;
|
||||
#if JS_ALIGN_OF_DOUBLE == 8
|
||||
union { jsdouble d; JSString s; } u;
|
||||
|
||||
str = &u.s;
|
||||
#else
|
||||
char alignbuf[16];
|
||||
|
||||
str = (JSString *)&alignbuf[8 - ((jsuword)&alignbuf & 7)];
|
||||
#endif
|
||||
|
||||
str->chars = (jschar *)chars;
|
||||
str->length = length;
|
||||
return js_AtomizeString(cx, str, ATOM_TMPSTR | flags);
|
||||
}
|
||||
|
||||
JSAtom *
|
||||
js_AtomizeValue(JSContext *cx, jsval value, uintN flags)
|
||||
{
|
||||
if (JSVAL_IS_STRING(value))
|
||||
return js_AtomizeString(cx, JSVAL_TO_STRING(value), flags);
|
||||
if (JSVAL_IS_INT(value))
|
||||
return js_AtomizeInt(cx, JSVAL_TO_INT(value), flags);
|
||||
if (JSVAL_IS_DOUBLE(value))
|
||||
return js_AtomizeDouble(cx, *JSVAL_TO_DOUBLE(value), flags);
|
||||
if (JSVAL_IS_OBJECT(value))
|
||||
return js_AtomizeObject(cx, JSVAL_TO_OBJECT(value), flags);
|
||||
if (JSVAL_IS_BOOLEAN(value))
|
||||
return js_AtomizeBoolean(cx, JSVAL_TO_BOOLEAN(value), flags);
|
||||
return js_AtomizeHashedKey(cx, value, (JSHashNumber)value, flags);
|
||||
}
|
||||
|
||||
JSAtom *
|
||||
js_ValueToStringAtom(JSContext *cx, jsval v)
|
||||
{
|
||||
JSString *str;
|
||||
|
||||
str = js_ValueToString(cx, v);
|
||||
if (!str)
|
||||
return NULL;
|
||||
return js_AtomizeString(cx, str, 0);
|
||||
}
|
||||
|
||||
JSAtomListElement *
|
||||
js_IndexAtom(JSContext *cx, JSAtom *atom, JSAtomList *al)
|
||||
{
|
||||
JSAtomListElement *ale;
|
||||
|
||||
ATOM_LIST_SEARCH(ale, al, atom);
|
||||
if (!ale) {
|
||||
JS_ARENA_ALLOCATE(ale, &cx->tempPool, sizeof(JSAtomListElement));
|
||||
if (!ale) {
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return NULL;
|
||||
}
|
||||
ale->atom = atom;
|
||||
ale->index = (jsatomid) al->count++;
|
||||
ale->next = al->list;
|
||||
al->list = ale;
|
||||
}
|
||||
return ale;
|
||||
}
|
||||
|
||||
JS_FRIEND_API(JSAtom *)
|
||||
js_GetAtom(JSContext *cx, JSAtomMap *map, jsatomid i)
|
||||
{
|
||||
JSAtom *atom;
|
||||
|
||||
JS_ASSERT(map->vector && i < map->length);
|
||||
if (!map->vector || i >= map->length) {
|
||||
char numBuf[12];
|
||||
JS_snprintf(numBuf, sizeof numBuf, "%lu", (unsigned long)i);
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_BAD_ATOMIC_NUMBER, numBuf);
|
||||
return NULL;
|
||||
}
|
||||
atom = map->vector[i];
|
||||
JS_ASSERT(atom);
|
||||
return atom;
|
||||
}
|
||||
|
||||
JS_FRIEND_API(JSBool)
|
||||
js_InitAtomMap(JSContext *cx, JSAtomMap *map, JSAtomList *al)
|
||||
{
|
||||
JSAtom **vector;
|
||||
JSAtomListElement *ale, *next;
|
||||
uint32 count;
|
||||
|
||||
ale = al->list;
|
||||
if (!ale) {
|
||||
map->vector = NULL;
|
||||
map->length = 0;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
count = al->count;
|
||||
if (count >= ATOM_INDEX_LIMIT) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
|
||||
JSMSG_TOO_MANY_LITERALS);
|
||||
return JS_FALSE;
|
||||
}
|
||||
vector = JS_malloc(cx, (size_t) count * sizeof *vector);
|
||||
if (!vector)
|
||||
return JS_FALSE;
|
||||
|
||||
do {
|
||||
vector[ale->index] = ale->atom;
|
||||
next = ale->next;
|
||||
ale->next = NULL;
|
||||
} while ((ale = next) != NULL);
|
||||
al->list = NULL;
|
||||
al->count = 0;
|
||||
|
||||
map->vector = vector;
|
||||
map->length = (jsatomid)count;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_FRIEND_API(void)
|
||||
js_FreeAtomMap(JSContext *cx, JSAtomMap *map)
|
||||
{
|
||||
if (map->vector) {
|
||||
free(map->vector);
|
||||
map->vector = NULL;
|
||||
}
|
||||
map->length = 0;
|
||||
}
|
||||
@@ -1,278 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 jsatom_h___
|
||||
#define jsatom_h___
|
||||
/*
|
||||
* JS atom table.
|
||||
*/
|
||||
#include <stddef.h>
|
||||
#include "jstypes.h"
|
||||
#ifndef NSPR20
|
||||
#include "jshash.h"
|
||||
#else
|
||||
/* Removed by JSIFY: #include "JShash.h"
|
||||
*/
|
||||
#include "jshash.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "jsapi.h"
|
||||
#include "jsprvtd.h"
|
||||
#include "jspubtd.h"
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
#include "jslock.h"
|
||||
#endif
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
#define ATOM_NOCOPY 0x01 /* don't copy atom string bytes */
|
||||
#define ATOM_TMPSTR 0x02 /* internal, to avoid extra string */
|
||||
#define ATOM_MARK 0x04 /* atom is reachable via GC */
|
||||
#define ATOM_PINNED 0x08 /* atom is pinned against GC */
|
||||
|
||||
struct JSAtom {
|
||||
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 */
|
||||
};
|
||||
|
||||
#define ATOM_KEY(atom) ((jsval)(atom)->entry.key)
|
||||
#define ATOM_IS_OBJECT(atom) JSVAL_IS_OBJECT(ATOM_KEY(atom))
|
||||
#define ATOM_TO_OBJECT(atom) JSVAL_TO_OBJECT(ATOM_KEY(atom))
|
||||
#define ATOM_IS_INT(atom) JSVAL_IS_INT(ATOM_KEY(atom))
|
||||
#define ATOM_TO_INT(atom) JSVAL_TO_INT(ATOM_KEY(atom))
|
||||
#define ATOM_IS_DOUBLE(atom) JSVAL_IS_DOUBLE(ATOM_KEY(atom))
|
||||
#define ATOM_TO_DOUBLE(atom) JSVAL_TO_DOUBLE(ATOM_KEY(atom))
|
||||
#define ATOM_IS_STRING(atom) JSVAL_IS_STRING(ATOM_KEY(atom))
|
||||
#define ATOM_TO_STRING(atom) JSVAL_TO_STRING(ATOM_KEY(atom))
|
||||
#define ATOM_IS_BOOLEAN(atom) JSVAL_IS_BOOLEAN(ATOM_KEY(atom))
|
||||
#define ATOM_TO_BOOLEAN(atom) JSVAL_TO_BOOLEAN(ATOM_KEY(atom))
|
||||
#define ATOM_BYTES(atom) JS_GetStringBytes(ATOM_TO_STRING(atom))
|
||||
|
||||
struct JSAtomListElement {
|
||||
JSAtomListElement *next;
|
||||
jsatomid index; /* index in script-specific atom map */
|
||||
JSAtom *atom;
|
||||
};
|
||||
|
||||
struct JSAtomList {
|
||||
JSAtomListElement *list; /* literals indexed for mapping */
|
||||
jsuint count; /* count of indexed literals */
|
||||
};
|
||||
|
||||
#define ATOM_LIST_INIT(al) ((al)->list = NULL, (al)->count = 0)
|
||||
|
||||
#define ATOM_LIST_SEARCH(_ale,_al,_atom) \
|
||||
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 */
|
||||
jsatomid length; /* count of (to-be-)indexed atoms */
|
||||
};
|
||||
|
||||
struct JSAtomState {
|
||||
JSRuntime *runtime; /* runtime that owns us */
|
||||
JSHashTable *table; /* hash table containing all atoms */
|
||||
jsatomid number; /* one beyond greatest atom number */
|
||||
|
||||
/* Type names and value literals. */
|
||||
JSAtom *typeAtoms[JSTYPE_LIMIT];
|
||||
JSAtom *booleanAtoms[2];
|
||||
JSAtom *nullAtom;
|
||||
|
||||
/* Various built-in or commonly-used atoms. */
|
||||
JSAtom *ArrayAtom;
|
||||
JSAtom *MathAtom;
|
||||
JSAtom *ObjectAtom;
|
||||
JSAtom *anonymousAtom;
|
||||
JSAtom *argumentsAtom;
|
||||
JSAtom *arityAtom;
|
||||
JSAtom *assignAtom;
|
||||
JSAtom *calleeAtom;
|
||||
JSAtom *callerAtom;
|
||||
JSAtom *classPrototypeAtom;
|
||||
JSAtom *constructorAtom;
|
||||
JSAtom *countAtom;
|
||||
JSAtom *indexAtom;
|
||||
JSAtom *inputAtom;
|
||||
JSAtom *lengthAtom;
|
||||
JSAtom *nameAtom;
|
||||
JSAtom *parentAtom;
|
||||
JSAtom *protoAtom;
|
||||
JSAtom *toSourceAtom;
|
||||
JSAtom *toStringAtom;
|
||||
JSAtom *valueOfAtom;
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
JSThinLock lock;
|
||||
volatile uint32 tablegen;
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Well-known predefined strings and their atoms. */
|
||||
extern char *js_type_str[];
|
||||
extern char *js_boolean_str[];
|
||||
|
||||
extern char js_Array_str[];
|
||||
extern char js_Math_str[];
|
||||
extern char js_Object_str[];
|
||||
extern char js_anonymous_str[];
|
||||
extern char js_arguments_str[];
|
||||
extern char js_arity_str[];
|
||||
extern char js_assign_str[];
|
||||
extern char js_callee_str[];
|
||||
extern char js_caller_str[];
|
||||
extern char js_class_prototype_str[];
|
||||
extern char js_constructor_str[];
|
||||
extern char js_count_str[];
|
||||
extern char js_eval_str[];
|
||||
extern char js_index_str[];
|
||||
extern char js_input_str[];
|
||||
extern char js_length_str[];
|
||||
extern char js_name_str[];
|
||||
extern char js_parent_str[];
|
||||
extern char js_proto_str[];
|
||||
extern char js_toSource_str[];
|
||||
extern char js_toString_str[];
|
||||
extern char js_valueOf_str[];
|
||||
|
||||
/*
|
||||
* Initialize atom state. Return true on success, false with an out of
|
||||
* memory error report on failure.
|
||||
*/
|
||||
extern JSBool
|
||||
js_InitAtomState(JSContext *cx, JSAtomState *state);
|
||||
|
||||
/*
|
||||
* Free and clear atom state.
|
||||
*/
|
||||
extern void
|
||||
js_FreeAtomState(JSContext *cx, JSAtomState *state);
|
||||
|
||||
/*
|
||||
* Atom garbage collection hooks.
|
||||
*/
|
||||
typedef void
|
||||
(*JSGCThingMarker)(JSRuntime *rt, void *thing);
|
||||
|
||||
extern void
|
||||
js_MarkAtomState(JSAtomState *state, JSGCThingMarker mark);
|
||||
|
||||
extern void
|
||||
js_SweepAtomState(JSAtomState *state);
|
||||
|
||||
extern void
|
||||
js_UnpinPinnedAtoms(JSAtomState *state);
|
||||
|
||||
/*
|
||||
* Find or create the atom for an object. If we create a new atom, give it the
|
||||
* type indicated in flags. Return 0 on failure to allocate memory.
|
||||
*/
|
||||
extern JSAtom *
|
||||
js_AtomizeObject(JSContext *cx, JSObject *obj, uintN flags);
|
||||
|
||||
/*
|
||||
* Find or create the atom for a Boolean value. If we create a new atom, give
|
||||
* it the type indicated in flags. Return 0 on failure to allocate memory.
|
||||
*/
|
||||
extern JSAtom *
|
||||
js_AtomizeBoolean(JSContext *cx, JSBool b, uintN flags);
|
||||
|
||||
/*
|
||||
* Find or create the atom for an integer value. If we create a new atom, give
|
||||
* it the type indicated in flags. Return 0 on failure to allocate memory.
|
||||
*/
|
||||
extern JSAtom *
|
||||
js_AtomizeInt(JSContext *cx, jsint i, uintN flags);
|
||||
|
||||
/*
|
||||
* Find or create the atom for a double value. If we create a new atom, give
|
||||
* it the type indicated in flags. Return 0 on failure to allocate memory.
|
||||
*/
|
||||
extern JSAtom *
|
||||
js_AtomizeDouble(JSContext *cx, jsdouble d, uintN flags);
|
||||
|
||||
/*
|
||||
* Find or create the atom for a string. If we create a new atom, give it the
|
||||
* type indicated in flags. Return 0 on failure to allocate memory.
|
||||
*/
|
||||
extern JSAtom *
|
||||
js_AtomizeString(JSContext *cx, JSString *str, uintN flags);
|
||||
|
||||
extern JS_FRIEND_API(JSAtom *)
|
||||
js_Atomize(JSContext *cx, const char *bytes, size_t length, uintN flags);
|
||||
|
||||
extern JS_FRIEND_API(JSAtom *)
|
||||
js_AtomizeChars(JSContext *cx, const jschar *chars, size_t length, uintN flags);
|
||||
|
||||
/*
|
||||
* This variant handles all value tag types.
|
||||
*/
|
||||
extern JSAtom *
|
||||
js_AtomizeValue(JSContext *cx, jsval value, uintN flags);
|
||||
|
||||
/*
|
||||
* Convert v to an atomized string.
|
||||
*/
|
||||
extern JSAtom *
|
||||
js_ValueToStringAtom(JSContext *cx, jsval v);
|
||||
|
||||
/*
|
||||
* Assign atom an index and insert it on al.
|
||||
*/
|
||||
extern JSAtomListElement *
|
||||
js_IndexAtom(JSContext *cx, JSAtom *atom, JSAtomList *al);
|
||||
|
||||
/*
|
||||
* Get the atom with index i from map.
|
||||
*/
|
||||
extern JS_FRIEND_API(JSAtom *)
|
||||
js_GetAtom(JSContext *cx, JSAtomMap *map, jsatomid i);
|
||||
|
||||
/*
|
||||
* For all unmapped atoms recorded in al, add a mapping from the atom's index
|
||||
* to its address. The GC must not run until all indexed atoms in atomLists
|
||||
* have been mapped by scripts connected to live objects (Function and Script
|
||||
* class objects have scripts as/in their private data -- the GC knows about
|
||||
* these two classes).
|
||||
*/
|
||||
extern JS_FRIEND_API(JSBool)
|
||||
js_InitAtomMap(JSContext *cx, JSAtomMap *map, JSAtomList *al);
|
||||
|
||||
/*
|
||||
* Free map->vector and clear map.
|
||||
*/
|
||||
extern JS_FRIEND_API(void)
|
||||
js_FreeAtomMap(JSContext *cx, JSAtomMap *map);
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsatom_h___ */
|
||||
@@ -1,92 +0,0 @@
|
||||
/* -*- 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 jsbit_h___
|
||||
#define jsbit_h___
|
||||
|
||||
#include "jstypes.h"
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
** A jsbitmap_t is a long integer that can be used for bitmaps
|
||||
*/
|
||||
typedef unsigned long jsbitmap_t;
|
||||
|
||||
#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
|
||||
*/
|
||||
EXTERN(JSIntn) JS_CeilingLog2(JSUint32 i);
|
||||
|
||||
/*
|
||||
** Compute the log of the greatest power of 2 less than or equal to n
|
||||
*/
|
||||
EXTERN(JSIntn) JS_FloorLog2(JSUint32 i);
|
||||
|
||||
/*
|
||||
** Macro version of JS_CeilingLog2: Compute the log of the least power of
|
||||
** 2 greater than or equal to _n. The result is returned in _log2.
|
||||
*/
|
||||
#define JS_CEILING_LOG2(_log2,_n) \
|
||||
JS_BEGIN_MACRO \
|
||||
JSUint32 j_ = (JSUint32)(_n); \
|
||||
(_log2) = 0; \
|
||||
if ((j_) & ((j_)-1)) \
|
||||
(_log2) += 1; \
|
||||
if ((j_) >> 16) \
|
||||
(_log2) += 16, (j_) >>= 16; \
|
||||
if ((j_) >> 8) \
|
||||
(_log2) += 8, (j_) >>= 8; \
|
||||
if ((j_) >> 4) \
|
||||
(_log2) += 4, (j_) >>= 4; \
|
||||
if ((j_) >> 2) \
|
||||
(_log2) += 2, (j_) >>= 2; \
|
||||
if ((j_) >> 1) \
|
||||
(_log2) += 1; \
|
||||
JS_END_MACRO
|
||||
|
||||
/*
|
||||
** Macro version of JS_FloorLog2: Compute the log of the greatest power of
|
||||
** 2 less than or equal to _n. The result is returned in _log2.
|
||||
**
|
||||
** This is equivalent to finding the highest set bit in the word.
|
||||
*/
|
||||
#define JS_FLOOR_LOG2(_log2,_n) \
|
||||
JS_BEGIN_MACRO \
|
||||
JSUint32 j_ = (JSUint32)(_n); \
|
||||
(_log2) = 0; \
|
||||
if ((j_) >> 16) \
|
||||
(_log2) += 16, (j_) >>= 16; \
|
||||
if ((j_) >> 8) \
|
||||
(_log2) += 8, (j_) >>= 8; \
|
||||
if ((j_) >> 4) \
|
||||
(_log2) += 4, (j_) >>= 4; \
|
||||
if ((j_) >> 2) \
|
||||
(_log2) += 2, (j_) >>= 2; \
|
||||
if ((j_) >> 1) \
|
||||
(_log2) += 1; \
|
||||
JS_END_MACRO
|
||||
|
||||
JS_END_EXTERN_C
|
||||
#endif /* jsbit_h___ */
|
||||
@@ -1,211 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 boolean implementation.
|
||||
*/
|
||||
#include "jsstddef.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"
|
||||
#include "jscntxt.h"
|
||||
#include "jsconfig.h"
|
||||
#include "jsinterp.h"
|
||||
#include "jslock.h"
|
||||
#include "jsnum.h"
|
||||
#include "jsobj.h"
|
||||
#include "jsstr.h"
|
||||
|
||||
static JSClass boolean_class = {
|
||||
"Boolean",
|
||||
JSCLASS_HAS_PRIVATE,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
|
||||
};
|
||||
|
||||
#if JS_HAS_TOSOURCE
|
||||
#include "jsprf.h"
|
||||
|
||||
static JSBool
|
||||
bool_toSource(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *rval)
|
||||
{
|
||||
jsval v;
|
||||
char buf[32];
|
||||
JSString *str;
|
||||
|
||||
if (!JS_InstanceOf(cx, obj, &boolean_class, argv))
|
||||
return JS_FALSE;
|
||||
v = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
|
||||
if (!JSVAL_IS_BOOLEAN(v))
|
||||
return js_obj_toSource(cx, obj, argc, argv, rval);
|
||||
JS_snprintf(buf, sizeof buf, "(new %s(%s))",
|
||||
boolean_class.name,
|
||||
js_boolean_str[JSVAL_TO_BOOLEAN(v) ? 1 : 0]);
|
||||
str = JS_NewStringCopyZ(cx, buf);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
return JS_TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static JSBool
|
||||
bool_toString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
|
||||
jsval *rval)
|
||||
{
|
||||
jsval v;
|
||||
JSAtom *atom;
|
||||
JSString *str;
|
||||
|
||||
if (!JS_InstanceOf(cx, obj, &boolean_class, argv))
|
||||
return JS_FALSE;
|
||||
v = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
|
||||
if (!JSVAL_IS_BOOLEAN(v))
|
||||
return js_obj_toString(cx, obj, argc, argv, rval);
|
||||
atom = cx->runtime->atomState.booleanAtoms[JSVAL_TO_BOOLEAN(v) ? 1 : 0];
|
||||
str = ATOM_TO_STRING(atom);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
*rval = STRING_TO_JSVAL(str);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
bool_valueOf(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
if (!JS_InstanceOf(cx, obj, &boolean_class, argv))
|
||||
return JS_FALSE;
|
||||
*rval = OBJ_GET_SLOT(cx, obj, JSSLOT_PRIVATE);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
static JSFunctionSpec boolean_methods[] = {
|
||||
#if JS_HAS_TOSOURCE
|
||||
{js_toSource_str, bool_toSource, 0},
|
||||
#endif
|
||||
{js_toString_str, bool_toString, 0},
|
||||
{js_valueOf_str, bool_valueOf, 0},
|
||||
{0}
|
||||
};
|
||||
|
||||
#ifdef XP_MAC
|
||||
#undef Boolean
|
||||
#define Boolean js_Boolean
|
||||
#endif
|
||||
|
||||
static JSBool
|
||||
Boolean(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
JSBool b;
|
||||
jsval bval;
|
||||
|
||||
if (argc != 0) {
|
||||
if (!js_ValueToBoolean(cx, argv[0], &b))
|
||||
return JS_FALSE;
|
||||
bval = BOOLEAN_TO_JSVAL(b);
|
||||
} else {
|
||||
bval = JSVAL_FALSE;
|
||||
}
|
||||
if (!cx->fp->constructing) {
|
||||
*rval = bval;
|
||||
return JS_TRUE;
|
||||
}
|
||||
OBJ_SET_SLOT(cx, obj, JSSLOT_PRIVATE, bval);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSObject *
|
||||
js_InitBooleanClass(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
JSObject *proto;
|
||||
|
||||
proto = JS_InitClass(cx, obj, NULL, &boolean_class, Boolean, 1,
|
||||
NULL, boolean_methods, NULL, NULL);
|
||||
if (!proto)
|
||||
return NULL;
|
||||
OBJ_SET_SLOT(cx, proto, JSSLOT_PRIVATE, JSVAL_FALSE);
|
||||
return proto;
|
||||
}
|
||||
|
||||
JSObject *
|
||||
js_BooleanToObject(JSContext *cx, JSBool b)
|
||||
{
|
||||
JSObject *obj;
|
||||
|
||||
obj = js_NewObject(cx, &boolean_class, NULL, NULL);
|
||||
if (!obj)
|
||||
return NULL;
|
||||
OBJ_SET_SLOT(cx, obj, JSSLOT_PRIVATE, BOOLEAN_TO_JSVAL(b));
|
||||
return obj;
|
||||
}
|
||||
|
||||
JSString *
|
||||
js_BooleanToString(JSContext *cx, JSBool b)
|
||||
{
|
||||
return ATOM_TO_STRING(cx->runtime->atomState.booleanAtoms[b ? 1 : 0]);
|
||||
}
|
||||
|
||||
JSBool
|
||||
js_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp)
|
||||
{
|
||||
JSBool b;
|
||||
jsdouble d;
|
||||
|
||||
#if defined XP_PC && defined _MSC_VER &&_MSC_VER <= 800
|
||||
/* MSVC1.5 coredumps */
|
||||
if (!bp)
|
||||
return JS_TRUE;
|
||||
#endif
|
||||
|
||||
/* XXX this should be an if-else chain, but MSVC1.5 crashes if it is. */
|
||||
if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) {
|
||||
/* Must return early to avoid falling thru to JSVAL_IS_OBJECT case. */
|
||||
*bp = JS_FALSE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
if (JSVAL_IS_OBJECT(v)) {
|
||||
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))
|
||||
v = JSVAL_TRUE; /* non-null object is true */
|
||||
b = JSVAL_TO_BOOLEAN(v);
|
||||
} else {
|
||||
b = JS_TRUE;
|
||||
}
|
||||
}
|
||||
if (JSVAL_IS_STRING(v)) {
|
||||
b = JSVAL_TO_STRING(v)->length ? JS_TRUE : JS_FALSE;
|
||||
}
|
||||
if (JSVAL_IS_INT(v)) {
|
||||
b = JSVAL_TO_INT(v) ? JS_TRUE : JS_FALSE;
|
||||
}
|
||||
if (JSVAL_IS_DOUBLE(v)) {
|
||||
d = *JSVAL_TO_DOUBLE(v);
|
||||
b = (!JSDOUBLE_IS_NaN(d) && d != 0) ? JS_TRUE : JS_FALSE;
|
||||
}
|
||||
if (JSVAL_IS_BOOLEAN(v)) {
|
||||
b = JSVAL_TO_BOOLEAN(v);
|
||||
}
|
||||
*bp = b;
|
||||
return JS_TRUE;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 jsbool_h___
|
||||
#define jsbool_h___
|
||||
/*
|
||||
* JS boolean interface.
|
||||
*/
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
extern JSObject *
|
||||
js_InitBooleanClass(JSContext *cx, JSObject *obj);
|
||||
|
||||
extern JSObject *
|
||||
js_BooleanToObject(JSContext *cx, JSBool b);
|
||||
|
||||
extern JSString *
|
||||
js_BooleanToString(JSContext *cx, JSBool b);
|
||||
|
||||
extern JSBool
|
||||
js_ValueToBoolean(JSContext *cx, jsval v, JSBool *bp);
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsbool_h___ */
|
||||
@@ -1,121 +0,0 @@
|
||||
/* -*- 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 jsclist_h___
|
||||
#define jsclist_h___
|
||||
|
||||
#include "jstypes.h"
|
||||
|
||||
typedef struct JSCListStr JSCList;
|
||||
|
||||
/*
|
||||
** Circular linked list
|
||||
*/
|
||||
struct JSCListStr {
|
||||
JSCList *next;
|
||||
JSCList *prev;
|
||||
};
|
||||
|
||||
/*
|
||||
** Insert element "_e" into the list, before "_l".
|
||||
*/
|
||||
#define JS_INSERT_BEFORE(_e,_l) \
|
||||
JS_BEGIN_MACRO \
|
||||
(_e)->next = (_l); \
|
||||
(_e)->prev = (_l)->prev; \
|
||||
(_l)->prev->next = (_e); \
|
||||
(_l)->prev = (_e); \
|
||||
JS_END_MACRO
|
||||
|
||||
/*
|
||||
** Insert element "_e" into the list, after "_l".
|
||||
*/
|
||||
#define JS_INSERT_AFTER(_e,_l) \
|
||||
JS_BEGIN_MACRO \
|
||||
(_e)->next = (_l)->next; \
|
||||
(_e)->prev = (_l); \
|
||||
(_l)->next->prev = (_e); \
|
||||
(_l)->next = (_e); \
|
||||
JS_END_MACRO
|
||||
|
||||
/*
|
||||
** Return the element following element "_e"
|
||||
*/
|
||||
#define JS_NEXT_LINK(_e) \
|
||||
((_e)->next)
|
||||
/*
|
||||
** Return the element preceding element "_e"
|
||||
*/
|
||||
#define JS_PREV_LINK(_e) \
|
||||
((_e)->prev)
|
||||
|
||||
/*
|
||||
** Append an element "_e" to the end of the list "_l"
|
||||
*/
|
||||
#define JS_APPEND_LINK(_e,_l) JS_INSERT_BEFORE(_e,_l)
|
||||
|
||||
/*
|
||||
** Insert an element "_e" at the head of the list "_l"
|
||||
*/
|
||||
#define JS_INSERT_LINK(_e,_l) JS_INSERT_AFTER(_e,_l)
|
||||
|
||||
/* Return the head/tail of the list */
|
||||
#define JS_LIST_HEAD(_l) (_l)->next
|
||||
#define JS_LIST_TAIL(_l) (_l)->prev
|
||||
|
||||
/*
|
||||
** Remove the element "_e" from it's circular list.
|
||||
*/
|
||||
#define JS_REMOVE_LINK(_e) \
|
||||
JS_BEGIN_MACRO \
|
||||
(_e)->prev->next = (_e)->next; \
|
||||
(_e)->next->prev = (_e)->prev; \
|
||||
JS_END_MACRO
|
||||
|
||||
/*
|
||||
** Remove the element "_e" from it's circular list. Also initializes the
|
||||
** linkage.
|
||||
*/
|
||||
#define JS_REMOVE_AND_INIT_LINK(_e) \
|
||||
JS_BEGIN_MACRO \
|
||||
(_e)->prev->next = (_e)->next; \
|
||||
(_e)->next->prev = (_e)->prev; \
|
||||
(_e)->next = (_e); \
|
||||
(_e)->prev = (_e); \
|
||||
JS_END_MACRO
|
||||
|
||||
/*
|
||||
** Return non-zero if the given circular list "_l" is empty, zero if the
|
||||
** circular list is not empty
|
||||
*/
|
||||
#define JS_CLIST_IS_EMPTY(_l) \
|
||||
((_l)->next == (_l))
|
||||
|
||||
/*
|
||||
** Initialize a circular list
|
||||
*/
|
||||
#define JS_INIT_CLIST(_l) \
|
||||
JS_BEGIN_MACRO \
|
||||
(_l)->next = (_l); \
|
||||
(_l)->prev = (_l); \
|
||||
JS_END_MACRO
|
||||
|
||||
#define JS_INIT_STATIC_CLIST(_l) \
|
||||
{(_l), (_l)}
|
||||
|
||||
#endif /* jsclist_h___ */
|
||||
@@ -1,400 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 execution context.
|
||||
*/
|
||||
#include "jsstddef.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "jstypes.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 */
|
||||
#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"
|
||||
#include "jsopcode.h"
|
||||
#include "jsscan.h"
|
||||
#include "jsscript.h"
|
||||
|
||||
JSContext *
|
||||
js_NewContext(JSRuntime *rt, size_t stacksize)
|
||||
{
|
||||
JSContext *cx;
|
||||
|
||||
cx = malloc(sizeof *cx);
|
||||
if (!cx)
|
||||
return NULL;
|
||||
memset(cx, 0, sizeof *cx);
|
||||
|
||||
cx->runtime = rt;
|
||||
#ifdef JS_THREADSAFE
|
||||
js_InitContextForLocking(cx);
|
||||
#endif
|
||||
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)) {
|
||||
free(cx);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
/* Atomicly append cx to rt's context list. */
|
||||
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;
|
||||
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)) {
|
||||
js_DestroyContext(cx);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
return cx;
|
||||
}
|
||||
|
||||
void
|
||||
js_DestroyContext(JSContext *cx)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
JSBool rtempty;
|
||||
|
||||
rt = cx->runtime;
|
||||
|
||||
/* Remove cx from context list first. */
|
||||
JS_LOCK_RUNTIME(rt);
|
||||
JS_REMOVE_LINK(&cx->links);
|
||||
rtempty = (rt->contextList.next == (JSCList *)&rt->contextList);
|
||||
JS_UNLOCK_RUNTIME(rt);
|
||||
|
||||
if (rtempty) {
|
||||
/* Unpin all pinned atoms before final GC. */
|
||||
js_UnpinPinnedAtoms(&rt->atomState);
|
||||
|
||||
/* Unlock GC things held by runtime pointers. */
|
||||
js_UnlockGCThing(cx, rt->jsNaN);
|
||||
js_UnlockGCThing(cx, rt->jsNegativeInfinity);
|
||||
js_UnlockGCThing(cx, rt->jsPositiveInfinity);
|
||||
js_UnlockGCThing(cx, rt->emptyString);
|
||||
|
||||
/*
|
||||
* Clear these so they get recreated if the standard classes are
|
||||
* initialized again.
|
||||
*/
|
||||
rt->jsNaN = NULL;
|
||||
rt->jsNegativeInfinity = NULL;
|
||||
rt->jsPositiveInfinity = NULL;
|
||||
rt->emptyString = NULL;
|
||||
|
||||
/* Clear debugging state to remove GC roots. */
|
||||
JS_ClearAllTraps(cx);
|
||||
JS_ClearAllWatchPoints(cx);
|
||||
}
|
||||
|
||||
/* Remove more GC roots in regExpStatics, then collect garbage. */
|
||||
#if JS_HAS_REGEXPS
|
||||
js_FreeRegExpStatics(cx, &cx->regExpStatics);
|
||||
#endif
|
||||
js_ForceGC(cx);
|
||||
|
||||
if (rtempty) {
|
||||
/* Free atom state now that we've run the GC. */
|
||||
js_FreeAtomState(cx, &rt->atomState);
|
||||
}
|
||||
|
||||
/* Free the stuff hanging off of cx. */
|
||||
JS_FinishArenaPool(&cx->stackPool);
|
||||
JS_FinishArenaPool(&cx->codePool);
|
||||
JS_FinishArenaPool(&cx->tempPool);
|
||||
if (cx->lastMessage)
|
||||
free(cx->lastMessage);
|
||||
free(cx);
|
||||
}
|
||||
|
||||
JSContext *
|
||||
js_ContextIterator(JSRuntime *rt, JSContext **iterp)
|
||||
{
|
||||
JSContext *cx = *iterp;
|
||||
|
||||
JS_LOCK_RUNTIME(rt);
|
||||
if (!cx)
|
||||
cx = (JSContext *)rt->contextList.next;
|
||||
if ((void *)cx == &rt->contextList)
|
||||
cx = NULL;
|
||||
else
|
||||
*iterp = (JSContext *)cx->links.next;
|
||||
JS_UNLOCK_RUNTIME(rt);
|
||||
return cx;
|
||||
}
|
||||
|
||||
void
|
||||
js_ReportErrorVA(JSContext *cx, uintN flags, const char *format, va_list ap)
|
||||
{
|
||||
JSStackFrame *fp;
|
||||
JSErrorReport report, *reportp;
|
||||
char *last;
|
||||
|
||||
fp = cx->fp;
|
||||
if (fp && fp->script && fp->pc) {
|
||||
report.filename = fp->script->filename;
|
||||
report.lineno = js_PCToLineNumber(fp->script, fp->pc);
|
||||
/* 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 = JS_vsmprintf(format, ap);
|
||||
if (!last)
|
||||
return;
|
||||
|
||||
js_ReportErrorAgain(cx, last, reportp);
|
||||
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)
|
||||
{
|
||||
JSErrorReporter onError;
|
||||
|
||||
if (!message)
|
||||
return;
|
||||
if (cx->lastMessage)
|
||||
free(cx->lastMessage);
|
||||
cx->lastMessage = JS_strdup(cx, message);
|
||||
if (!cx->lastMessage)
|
||||
return;
|
||||
onError = cx->errorReporter;
|
||||
if (onError)
|
||||
(*onError)(cx, cx->lastMessage, reportp);
|
||||
}
|
||||
|
||||
void
|
||||
js_ReportIsNotDefined(JSContext *cx, const char *name)
|
||||
{
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_NOT_DEFINED, name);
|
||||
}
|
||||
|
||||
#if defined DEBUG && defined XP_UNIX
|
||||
/* For gdb usage. */
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,230 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 jscntxt_h___
|
||||
#define jscntxt_h___
|
||||
/*
|
||||
* JS execution context.
|
||||
*/
|
||||
#ifndef NSPR20
|
||||
#include "jsarena.h"
|
||||
#else
|
||||
/* Removed by JSIFY: #include "plarena.h"
|
||||
*/
|
||||
#include "jsarena.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "jsclist.h"
|
||||
#include "jslong.h"
|
||||
#include "jsatom.h"
|
||||
#include "jsgc.h"
|
||||
#include "jsinterp.h"
|
||||
#include "jsobj.h"
|
||||
#include "jsprvtd.h"
|
||||
#include "jspubtd.h"
|
||||
#include "jsregexp.h"
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
struct JSRuntime {
|
||||
/* Garbage collector state, used by jsgc.c. */
|
||||
JSArenaPool gcArenaPool;
|
||||
JSArenaPool gcFlagsPool;
|
||||
JSHashTable *gcRootsHash;
|
||||
JSGCThing *gcFreeList;
|
||||
uint32 gcBytes;
|
||||
uint32 gcLastBytes;
|
||||
uint32 gcMaxBytes;
|
||||
uint32 gcLevel;
|
||||
uint32 gcNumber;
|
||||
JSBool gcPoke;
|
||||
JSGCCallback gcCallback;
|
||||
#ifdef JS_GCMETER
|
||||
JSGCStats gcStats;
|
||||
#endif
|
||||
|
||||
/* Literal table maintained by jsatom.c functions. */
|
||||
JSAtomState atomState;
|
||||
|
||||
/* Random number generator state, used by jsmath.c. */
|
||||
JSBool rngInitialized;
|
||||
int64 rngMultiplier;
|
||||
int64 rngAddend;
|
||||
int64 rngMask;
|
||||
int64 rngSeed;
|
||||
jsdouble rngDscale;
|
||||
|
||||
/* Well-known numbers held for use by this runtime's contexts. */
|
||||
jsdouble *jsNaN;
|
||||
jsdouble *jsNegativeInfinity;
|
||||
jsdouble *jsPositiveInfinity;
|
||||
|
||||
/* Empty string held for use by this runtime's contexts. */
|
||||
JSString *emptyString;
|
||||
|
||||
/* List of active contexts sharing this runtime. */
|
||||
JSCList contextList;
|
||||
|
||||
/* These are used for debugging -- see jsprvtd.h and jsdbgapi.h. */
|
||||
JSTrapHandler interruptHandler;
|
||||
void *interruptHandlerData;
|
||||
JSNewScriptHook newScriptHook;
|
||||
void *newScriptHookData;
|
||||
JSDestroyScriptHook destroyScriptHook;
|
||||
void *destroyScriptHookData;
|
||||
JSTrapHandler debuggerHandler;
|
||||
void *debuggerHandlerData;
|
||||
JSSourceHandler sourceHandler;
|
||||
void *sourceHandlerData;
|
||||
JSInterpreterHook executeHook;
|
||||
void *executeHookData;
|
||||
JSInterpreterHook callHook;
|
||||
void *callHookData;
|
||||
|
||||
/* More debugging state, see jsdbgapi.c. */
|
||||
JSCList trapList;
|
||||
JSCList watchPointList;
|
||||
|
||||
/* Weak links to properties, indexed by quickened get/set opcodes. */
|
||||
/* XXX must come after JSCLists or MSVC alignment bug bites empty lists */
|
||||
JSPropertyCache propertyCache;
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
/* These combine to interlock the GC and new requests. */
|
||||
PRLock *gcLock;
|
||||
PRCondVar *gcDone;
|
||||
PRCondVar *requestDone;
|
||||
uint32 requestCount;
|
||||
|
||||
/* Lock and owning thread pointer for JS_LOCK_RUNTIME. */
|
||||
JSThinLock rtLock;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct JSContext {
|
||||
JSCList links;
|
||||
|
||||
/* Interpreter activation count. */
|
||||
uintN interpLevel;
|
||||
|
||||
/* Runtime version control identifier and equality operators. */
|
||||
JSVersion version;
|
||||
jsbytecode jsop_eq;
|
||||
jsbytecode jsop_ne;
|
||||
|
||||
/* Data shared by threads in an address space. */
|
||||
JSRuntime *runtime;
|
||||
|
||||
/* Stack arena pool and frame pointer register. */
|
||||
JSArenaPool stackPool;
|
||||
JSStackFrame *fp;
|
||||
|
||||
/* Temporary arena pools used while compiling and decompiling. */
|
||||
JSArenaPool codePool;
|
||||
JSArenaPool tempPool;
|
||||
|
||||
/* Top-level object and pointer to top stack frame's scope chain. */
|
||||
JSObject *globalObject;
|
||||
|
||||
/* Most recently created things by type, members of the GC's root set. */
|
||||
JSGCThing *newborn[GCX_NTYPES];
|
||||
|
||||
/* Regular expression class statics (XXX not shared globally). */
|
||||
JSRegExpStatics regExpStatics;
|
||||
|
||||
/* State for object and array toSource conversion. */
|
||||
JSSharpObjectMap sharpObjectMap;
|
||||
|
||||
/* Last message string and trace file for debugging. */
|
||||
char *lastMessage;
|
||||
#ifdef DEBUG
|
||||
void *tracefp;
|
||||
#endif
|
||||
|
||||
/* Per-context optional user callbacks. */
|
||||
JSBranchCallback branchCallback;
|
||||
JSErrorReporter errorReporter;
|
||||
|
||||
/* Client opaque pointer */
|
||||
void *data;
|
||||
|
||||
/* GC and thread-safe state. */
|
||||
JSStackFrame *dormantFrameChain; /* dormant stack frame to scan */
|
||||
uint32 gcDisabled; /* XXX for pre-ECMAv2 switch */
|
||||
#ifdef JS_THREADSAFE
|
||||
jsword thread;
|
||||
jsrefcount requestDepth;
|
||||
JSPackedBool gcActive;
|
||||
#endif
|
||||
|
||||
/* Exception state (NB: throwing is packed with gcActive above). */
|
||||
JSPackedBool throwing; /* is there a pending exception? */
|
||||
jsval exception; /* most-recently-thrown exceptin */
|
||||
};
|
||||
|
||||
extern JSContext *
|
||||
js_NewContext(JSRuntime *rt, size_t stacksize);
|
||||
|
||||
extern void
|
||||
js_DestroyContext(JSContext *cx);
|
||||
|
||||
extern JSContext *
|
||||
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, 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
|
||||
|
||||
/*
|
||||
* Report an exception using a previously composed JSErrorReport.
|
||||
*/
|
||||
extern JS_FRIEND_API(void)
|
||||
js_ReportErrorAgain(JSContext *cx, const char *message, JSErrorReport *report);
|
||||
|
||||
extern void
|
||||
js_ReportIsNotDefined(JSContext *cx, const char *name);
|
||||
|
||||
extern JSErrorFormatString js_ErrorFormatString[JSErr_Limit];
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jscntxt_h___ */
|
||||
@@ -1,20 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8 -*-
|
||||
* Copyright © 1996 Netscape Communications Corporation, All Rights Reserved.
|
||||
*/
|
||||
#ifndef jscompat_h___
|
||||
#define jscompat_h___
|
||||
/*
|
||||
* Compatibility glue for various NSPR versions. We must always define int8,
|
||||
* int16, jsword, and so on to minimize differences with js/ref, no matter what
|
||||
* the NSPR typedef names may be.
|
||||
*/
|
||||
#include "jstypes.h"
|
||||
#include "jslong.h"
|
||||
|
||||
typedef JSIntn intN;
|
||||
typedef JSUintn uintN;
|
||||
typedef JSUword jsuword;
|
||||
typedef JSWord jsword;
|
||||
typedef float float32;
|
||||
#define allocPriv allocPool
|
||||
#endif /* jscompat_h___ */
|
||||
@@ -1,267 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 configuration macros.
|
||||
*/
|
||||
#ifndef JS_VERSION
|
||||
#define JS_VERSION 140
|
||||
#endif
|
||||
|
||||
#if JS_VERSION == 100
|
||||
|
||||
#define JS_BUG_AUTO_INDEX_PROPS 1 /* new object o: o.p = v sets o[0] */
|
||||
#define JS_BUG_NULL_INDEX_PROPS 1 /* o[0] defaults to null, not void */
|
||||
#define JS_BUG_EMPTY_INDEX_ZERO 1 /* o[""] is equivalent to o[0] */
|
||||
#define JS_BUG_SHORT_CIRCUIT 1 /* 1 && 1 => true, 1 && 0 => 0 bug */
|
||||
#define JS_BUG_EAGER_TOSTRING 1 /* o.toString() trumps o.valueOf() */
|
||||
#define JS_BUG_VOID_TOSTRING 0 /* void 0 + 0 == "undefined0" */
|
||||
#define JS_BUG_EVAL_THIS_FUN 0 /* eval('this') in function f is f */
|
||||
#define JS_BUG_EVAL_THIS_SCOPE 0 /* Math.eval('sin(x)') vs. local x */
|
||||
#define JS_BUG_FALLIBLE_EQOPS 1 /* fallible/intransitive equality ops */
|
||||
#define JS_BUG_FALLIBLE_TONUM 1 /* fallible ValueToNumber primitive */
|
||||
#define JS_BUG_WITH_CLOSURE 0 /* with(o)function f(){} sets o.f */
|
||||
#define JS_BUG_SET_ENUMERATE 1 /* o.p=q flags o.p JSPROP_ENUMERATE */
|
||||
|
||||
#define JS_HAS_PROP_DELETE 0 /* delete o.p removes p from o */
|
||||
#define JS_HAS_CALL_OBJECT 0 /* fun.caller is stack frame obj */
|
||||
#define JS_HAS_LABEL_STATEMENT 0 /* has break/continue to label: */
|
||||
#define JS_HAS_DO_WHILE_LOOP 0 /* has do {...} while (b) */
|
||||
#define JS_HAS_SWITCH_STATEMENT 0 /* has switch (v) {case c: ...} */
|
||||
#define JS_HAS_SOME_PERL_FUN 0 /* has array.join/reverse/sort */
|
||||
#define JS_HAS_MORE_PERL_FUN 0 /* has array.push, str.substr, etc */
|
||||
#define JS_HAS_VALUEOF_HINT 0 /* valueOf(hint) where hint is typeof */
|
||||
#define JS_HAS_LEXICAL_CLOSURE 0 /* nested functions, lexically closed */
|
||||
#define JS_HAS_APPLY_FUNCTION 0 /* has fun.apply(obj, argArray) */
|
||||
#define JS_HAS_CALL_FUNCTION 0 /* has fun.call(obj, arg1, ... argN) */
|
||||
#define JS_HAS_OBJ_PROTO_PROP 0 /* has o.__proto__ etc. */
|
||||
#define JS_HAS_REGEXPS 0 /* has perl r.e.s via RegExp, /pat/ */
|
||||
#define JS_HAS_SEQUENCE_OPS 0 /* has array.slice, string.concat */
|
||||
#define JS_HAS_INITIALIZERS 0 /* has var o = {'foo': 42, 'bar':3} */
|
||||
#define JS_HAS_OBJ_WATCHPOINT 0 /* has o.watch and o.unwatch */
|
||||
#define JS_HAS_EXPORT_IMPORT 0 /* has export fun; import obj.fun */
|
||||
#define JS_HAS_EVAL_THIS_SCOPE 0 /* Math.eval is same as with (Math) */
|
||||
#define JS_HAS_TRIPLE_EQOPS 0 /* has === and !== identity eqops */
|
||||
#define JS_HAS_SHARP_VARS 0 /* has #n=, #n# for object literals */
|
||||
#define JS_HAS_REPLACE_LAMBDA 0 /* has string.replace(re, lambda) */
|
||||
#define JS_HAS_SCRIPT_OBJECT 0 /* has (new Script("x++")).exec() */
|
||||
#define JS_HAS_XDR 0 /* has XDR API and object methods */
|
||||
#define JS_HAS_EXCEPTIONS 0 /* has exception handling */
|
||||
#define JS_HAS_UNDEFINED 0 /* has global "undefined" property */
|
||||
#define JS_HAS_TOSOURCE 0 /* has Object/Array toSource method */
|
||||
#define JS_HAS_IN_OPERATOR 0 /* has in operator ('p' in {p:1}) */
|
||||
#define JS_HAS_INSTANCEOF 0 /* has {p:1} instanceof Object */
|
||||
#define JS_HAS_ARGS_OBJECT 0 /* has minimal ECMA arguments object */
|
||||
#define JS_HAS_DEBUGGER_KEYWORD 0 /* has hook for debugger keyword */
|
||||
#define JS_HAS_ERROR_EXCEPTIONS 0 /* has error object hierarchy */
|
||||
|
||||
#elif JS_VERSION == 110
|
||||
|
||||
#define JS_BUG_AUTO_INDEX_PROPS 0 /* new object o: o.p = v sets o[0] */
|
||||
#define JS_BUG_NULL_INDEX_PROPS 1 /* o[0] defaults to null, not void */
|
||||
#define JS_BUG_EMPTY_INDEX_ZERO 1 /* o[""] is equivalent to o[0] */
|
||||
#define JS_BUG_SHORT_CIRCUIT 1 /* 1 && 1 => true, 1 && 0 => 0 bug */
|
||||
#define JS_BUG_EAGER_TOSTRING 1 /* o.toString() trumps o.valueOf() */
|
||||
#define JS_BUG_VOID_TOSTRING 0 /* void 0 + 0 == "undefined0" */
|
||||
#define JS_BUG_EVAL_THIS_FUN 1 /* eval('this') in function f is f */
|
||||
#define JS_BUG_EVAL_THIS_SCOPE 1 /* Math.eval('sin(x)') vs. local x */
|
||||
#define JS_BUG_FALLIBLE_EQOPS 1 /* fallible/intransitive equality ops */
|
||||
#define JS_BUG_FALLIBLE_TONUM 1 /* fallible ValueToNumber primitive */
|
||||
#define JS_BUG_WITH_CLOSURE 0 /* with(o)function f(){} sets o.f */
|
||||
#define JS_BUG_SET_ENUMERATE 1 /* o.p=q flags o.p JSPROP_ENUMERATE */
|
||||
|
||||
#define JS_HAS_PROP_DELETE 0 /* delete o.p removes p from o */
|
||||
#define JS_HAS_CALL_OBJECT 0 /* fun.caller is stack frame obj */
|
||||
#define JS_HAS_LABEL_STATEMENT 0 /* has break/continue to label: */
|
||||
#define JS_HAS_DO_WHILE_LOOP 0 /* has do {...} while (b) */
|
||||
#define JS_HAS_SWITCH_STATEMENT 0 /* has switch (v) {case c: ...} */
|
||||
#define JS_HAS_SOME_PERL_FUN 1 /* has array.join/reverse/sort */
|
||||
#define JS_HAS_MORE_PERL_FUN 0 /* has array.push, str.substr, etc */
|
||||
#define JS_HAS_VALUEOF_HINT 0 /* valueOf(hint) where hint is typeof */
|
||||
#define JS_HAS_LEXICAL_CLOSURE 0 /* nested functions, lexically closed */
|
||||
#define JS_HAS_APPLY_FUNCTION 0 /* has apply(fun, arg1, ... argN) */
|
||||
#define JS_HAS_CALL_FUNCTION 0 /* has fun.call(obj, arg1, ... argN) */
|
||||
#define JS_HAS_OBJ_PROTO_PROP 0 /* has o.__proto__ etc. */
|
||||
#define JS_HAS_REGEXPS 0 /* has perl r.e.s via RegExp, /pat/ */
|
||||
#define JS_HAS_SEQUENCE_OPS 0 /* has array.slice, string.concat */
|
||||
#define JS_HAS_INITIALIZERS 0 /* has var o = {'foo': 42, 'bar':3} */
|
||||
#define JS_HAS_OBJ_WATCHPOINT 0 /* has o.watch and o.unwatch */
|
||||
#define JS_HAS_EXPORT_IMPORT 0 /* has export fun; import obj.fun */
|
||||
#define JS_HAS_EVAL_THIS_SCOPE 0 /* Math.eval is same as with (Math) */
|
||||
#define JS_HAS_TRIPLE_EQOPS 0 /* has === and !== identity eqops */
|
||||
#define JS_HAS_SHARP_VARS 0 /* has #n=, #n# for object literals */
|
||||
#define JS_HAS_REPLACE_LAMBDA 0 /* has string.replace(re, lambda) */
|
||||
#define JS_HAS_SCRIPT_OBJECT 0 /* has (new Script("x++")).exec() */
|
||||
#define JS_HAS_XDR 0 /* has XDR API and object methods */
|
||||
#define JS_HAS_EXCEPTIONS 0 /* has exception handling */
|
||||
#define JS_HAS_UNDEFINED 0 /* has global "undefined" property */
|
||||
#define JS_HAS_TOSOURCE 0 /* has Object/Array toSource method */
|
||||
#define JS_HAS_IN_OPERATOR 0 /* has in operator ('p' in {p:1}) */
|
||||
#define JS_HAS_INSTANCEOF 0 /* has {p:1} instanceof Object */
|
||||
#define JS_HAS_ARGS_OBJECT 0 /* has minimal ECMA arguments object */
|
||||
#define JS_HAS_DEBUGGER_KEYWORD 0 /* has hook for debugger keyword */
|
||||
#define JS_HAS_ERROR_EXCEPTIONS 0 /* has error object hierarchy */
|
||||
|
||||
#elif JS_VERSION == 120
|
||||
|
||||
#define JS_BUG_AUTO_INDEX_PROPS 0 /* new object o: o.p = v sets o[0] */
|
||||
#define JS_BUG_NULL_INDEX_PROPS 0 /* o[0] defaults to null, not void */
|
||||
#define JS_BUG_EMPTY_INDEX_ZERO 0 /* o[""] is equivalent to o[0] */
|
||||
#define JS_BUG_SHORT_CIRCUIT 0 /* 1 && 1 => true, 1 && 0 => 0 bug */
|
||||
#define JS_BUG_EAGER_TOSTRING 0 /* o.toString() trumps o.valueOf() */
|
||||
#define JS_BUG_VOID_TOSTRING 1 /* void 0 + 0 == "undefined0" */
|
||||
#define JS_BUG_EVAL_THIS_FUN 0 /* eval('this') in function f is f */
|
||||
#define JS_BUG_EVAL_THIS_SCOPE 0 /* Math.eval('sin(x)') vs. local x */
|
||||
#define JS_BUG_FALLIBLE_EQOPS 0 /* fallible/intransitive equality ops */
|
||||
#define JS_BUG_FALLIBLE_TONUM 0 /* fallible ValueToNumber primitive */
|
||||
#define JS_BUG_WITH_CLOSURE 1 /* with(o)function f(){} sets o.f */
|
||||
#define JS_BUG_SET_ENUMERATE 1 /* o.p=q flags o.p JSPROP_ENUMERATE */
|
||||
|
||||
#define JS_HAS_PROP_DELETE 1 /* delete o.p removes p from o */
|
||||
#define JS_HAS_CALL_OBJECT 1 /* fun.caller is stack frame obj */
|
||||
#define JS_HAS_LABEL_STATEMENT 1 /* has break/continue to label: */
|
||||
#define JS_HAS_DO_WHILE_LOOP 1 /* has do {...} while (b) */
|
||||
#define JS_HAS_SWITCH_STATEMENT 1 /* has switch (v) {case c: ...} */
|
||||
#define JS_HAS_SOME_PERL_FUN 1 /* has array.join/reverse/sort */
|
||||
#define JS_HAS_MORE_PERL_FUN 1 /* has array.push, str.substr, etc */
|
||||
#define JS_HAS_VALUEOF_HINT 1 /* valueOf(hint) where hint is typeof */
|
||||
#define JS_HAS_LEXICAL_CLOSURE 1 /* nested functions, lexically closed */
|
||||
#define JS_HAS_APPLY_FUNCTION 1 /* has apply(fun, arg1, ... argN) */
|
||||
#define JS_HAS_CALL_FUNCTION 0 /* has fun.call(obj, arg1, ... argN) */
|
||||
#define JS_HAS_OBJ_PROTO_PROP 1 /* has o.__proto__ etc. */
|
||||
#define JS_HAS_REGEXPS 1 /* has perl r.e.s via RegExp, /pat/ */
|
||||
#define JS_HAS_SEQUENCE_OPS 1 /* has array.slice, string.concat */
|
||||
#define JS_HAS_INITIALIZERS 1 /* has var o = {'foo': 42, 'bar':3} */
|
||||
#define JS_HAS_OBJ_WATCHPOINT 1 /* has o.watch and o.unwatch */
|
||||
#define JS_HAS_EXPORT_IMPORT 1 /* has export fun; import obj.fun */
|
||||
#define JS_HAS_EVAL_THIS_SCOPE 1 /* Math.eval is same as with (Math) */
|
||||
#define JS_HAS_TRIPLE_EQOPS 0 /* has === and !== identity eqops */
|
||||
#define JS_HAS_SHARP_VARS 0 /* has #n=, #n# for object literals */
|
||||
#define JS_HAS_REPLACE_LAMBDA 0 /* has string.replace(re, lambda) */
|
||||
#define JS_HAS_SCRIPT_OBJECT 0 /* has (new Script("x++")).exec() */
|
||||
#define JS_HAS_XDR 0 /* has XDR API and object methods */
|
||||
#define JS_HAS_EXCEPTIONS 0 /* has exception handling */
|
||||
#define JS_HAS_UNDEFINED 0 /* has global "undefined" property */
|
||||
#define JS_HAS_TOSOURCE 0 /* has Object/Array toSource method */
|
||||
#define JS_HAS_IN_OPERATOR 0 /* has in operator ('p' in {p:1}) */
|
||||
#define JS_HAS_INSTANCEOF 0 /* has {p:1} instanceof Object */
|
||||
#define JS_HAS_ARGS_OBJECT 0 /* has minimal ECMA arguments object */
|
||||
#define JS_HAS_DEBUGGER_KEYWORD 0 /* has hook for debugger keyword */
|
||||
#define JS_HAS_ERROR_EXCEPTIONS 0 /* has error object hierarchy */
|
||||
|
||||
#elif JS_VERSION == 130
|
||||
|
||||
#define JS_BUG_AUTO_INDEX_PROPS 0 /* new object o: o.p = v sets o[0] */
|
||||
#define JS_BUG_NULL_INDEX_PROPS 0 /* o[0] defaults to null, not void */
|
||||
#define JS_BUG_EMPTY_INDEX_ZERO 0 /* o[""] is equivalent to o[0] */
|
||||
#define JS_BUG_SHORT_CIRCUIT 0 /* 1 && 1 => true, 1 && 0 => 0 bug */
|
||||
#define JS_BUG_EAGER_TOSTRING 0 /* o.toString() trumps o.valueOf() */
|
||||
#define JS_BUG_VOID_TOSTRING 0 /* void 0 + 0 == "undefined0" */
|
||||
#define JS_BUG_EVAL_THIS_FUN 0 /* eval('this') in function f is f */
|
||||
#define JS_BUG_EVAL_THIS_SCOPE 0 /* Math.eval('sin(x)') vs. local x */
|
||||
#define JS_BUG_FALLIBLE_EQOPS 0 /* fallible/intransitive equality ops */
|
||||
#define JS_BUG_FALLIBLE_TONUM 0 /* fallible ValueToNumber primitive */
|
||||
#define JS_BUG_WITH_CLOSURE 1 /* with(o)function f(){} sets o.f */
|
||||
#define JS_BUG_SET_ENUMERATE 0 /* o.p=q flags o.p JSPROP_ENUMERATE */
|
||||
|
||||
#define JS_HAS_PROP_DELETE 1 /* delete o.p removes p from o */
|
||||
#define JS_HAS_CALL_OBJECT 1 /* fun.caller is stack frame obj */
|
||||
#define JS_HAS_LABEL_STATEMENT 1 /* has break/continue to label: */
|
||||
#define JS_HAS_DO_WHILE_LOOP 1 /* has do {...} while (b) */
|
||||
#define JS_HAS_SWITCH_STATEMENT 1 /* has switch (v) {case c: ...} */
|
||||
#define JS_HAS_SOME_PERL_FUN 1 /* has array.join/reverse/sort */
|
||||
#define JS_HAS_MORE_PERL_FUN 1 /* has array.push, str.substr, etc */
|
||||
#define JS_HAS_VALUEOF_HINT 1 /* valueOf(hint) where hint is typeof */
|
||||
#define JS_HAS_LEXICAL_CLOSURE 1 /* nested functions, lexically closed */
|
||||
#define JS_HAS_APPLY_FUNCTION 1 /* has apply(fun, arg1, ... argN) */
|
||||
#define JS_HAS_CALL_FUNCTION 1 /* has fun.call(obj, arg1, ... argN) */
|
||||
#define JS_HAS_OBJ_PROTO_PROP 1 /* has o.__proto__ etc. */
|
||||
#define JS_HAS_REGEXPS 1 /* has perl r.e.s via RegExp, /pat/ */
|
||||
#define JS_HAS_SEQUENCE_OPS 1 /* has array.slice, string.concat */
|
||||
#define JS_HAS_INITIALIZERS 1 /* has var o = {'foo': 42, 'bar':3} */
|
||||
#define JS_HAS_OBJ_WATCHPOINT 1 /* has o.watch and o.unwatch */
|
||||
#define JS_HAS_EXPORT_IMPORT 1 /* has export fun; import obj.fun */
|
||||
#define JS_HAS_EVAL_THIS_SCOPE 1 /* Math.eval is same as with (Math) */
|
||||
#define JS_HAS_TRIPLE_EQOPS 1 /* has === and !== identity eqops */
|
||||
#define JS_HAS_SHARP_VARS 1 /* has #n=, #n# for object literals */
|
||||
#define JS_HAS_REPLACE_LAMBDA 1 /* has string.replace(re, lambda) */
|
||||
#define JS_HAS_SCRIPT_OBJECT 1 /* has (new Script("x++")).exec() */
|
||||
#define JS_HAS_XDR 1 /* has XDR API and object methods */
|
||||
#define JS_HAS_EXCEPTIONS 0 /* has exception handling */
|
||||
#define JS_HAS_UNDEFINED 1 /* has global "undefined" property */
|
||||
#define JS_HAS_TOSOURCE 1 /* has Object/Array toSource method */
|
||||
#define JS_HAS_IN_OPERATOR 0 /* has in operator ('p' in {p:1}) */
|
||||
#define JS_HAS_INSTANCEOF 0 /* has {p:1} instanceof Object */
|
||||
#define JS_HAS_ARGS_OBJECT 1 /* has minimal ECMA arguments object */
|
||||
#define JS_HAS_DEBUGGER_KEYWORD 1 /* has hook for debugger keyword */
|
||||
#define JS_HAS_ERROR_EXCEPTIONS 0 /* has error object hierarchy */
|
||||
|
||||
#elif JS_VERSION == 140
|
||||
|
||||
#define JS_BUG_AUTO_INDEX_PROPS 0 /* new object o: o.p = v sets o[0] */
|
||||
#define JS_BUG_NULL_INDEX_PROPS 0 /* o[0] defaults to null, not void */
|
||||
#define JS_BUG_EMPTY_INDEX_ZERO 0 /* o[""] is equivalent to o[0] */
|
||||
#define JS_BUG_SHORT_CIRCUIT 0 /* 1 && 1 => true, 1 && 0 => 0 bug */
|
||||
#define JS_BUG_EAGER_TOSTRING 0 /* o.toString() trumps o.valueOf() */
|
||||
#define JS_BUG_VOID_TOSTRING 0 /* void 0 + 0 == "undefined0" */
|
||||
#define JS_BUG_EVAL_THIS_FUN 0 /* eval('this') in function f is f */
|
||||
#define JS_BUG_EVAL_THIS_SCOPE 0 /* Math.eval('sin(x)') vs. local x */
|
||||
#define JS_BUG_FALLIBLE_EQOPS 0 /* fallible/intransitive equality ops */
|
||||
#define JS_BUG_FALLIBLE_TONUM 0 /* fallible ValueToNumber primitive */
|
||||
#define JS_BUG_WITH_CLOSURE 1 /* with(o)function f(){} sets o.f */
|
||||
#define JS_BUG_SET_ENUMERATE 0 /* o.p=q flags o.p JSPROP_ENUMERATE */
|
||||
|
||||
#define JS_HAS_PROP_DELETE 1 /* delete o.p removes p from o */
|
||||
#define JS_HAS_CALL_OBJECT 1 /* fun.caller is stack frame obj */
|
||||
#define JS_HAS_LABEL_STATEMENT 1 /* has break/continue to label: */
|
||||
#define JS_HAS_DO_WHILE_LOOP 1 /* has do {...} while (b) */
|
||||
#define JS_HAS_SWITCH_STATEMENT 1 /* has switch (v) {case c: ...} */
|
||||
#define JS_HAS_SOME_PERL_FUN 1 /* has array.join/reverse/sort */
|
||||
#define JS_HAS_MORE_PERL_FUN 1 /* has array.push, str.substr, etc */
|
||||
#define JS_HAS_VALUEOF_HINT 1 /* valueOf(hint) where hint is typeof */
|
||||
#define JS_HAS_LEXICAL_CLOSURE 1 /* nested functions, lexically closed */
|
||||
#define JS_HAS_APPLY_FUNCTION 1 /* has apply(fun, arg1, ... argN) */
|
||||
#define JS_HAS_CALL_FUNCTION 1 /* has fun.call(obj, arg1, ... argN) */
|
||||
#define JS_HAS_OBJ_PROTO_PROP 1 /* has o.__proto__ etc. */
|
||||
#define JS_HAS_REGEXPS 1 /* has perl r.e.s via RegExp, /pat/ */
|
||||
#define JS_HAS_SEQUENCE_OPS 1 /* has array.slice, string.concat */
|
||||
#define JS_HAS_INITIALIZERS 1 /* has var o = {'foo': 42, 'bar':3} */
|
||||
#define JS_HAS_OBJ_WATCHPOINT 1 /* has o.watch and o.unwatch */
|
||||
#define JS_HAS_EXPORT_IMPORT 1 /* has export fun; import obj.fun */
|
||||
#define JS_HAS_EVAL_THIS_SCOPE 1 /* Math.eval is same as with (Math) */
|
||||
#define JS_HAS_TRIPLE_EQOPS 1 /* has === and !== identity eqops */
|
||||
#define JS_HAS_SHARP_VARS 1 /* has #n=, #n# for object literals */
|
||||
#define JS_HAS_REPLACE_LAMBDA 1 /* has string.replace(re, lambda) */
|
||||
#define JS_HAS_SCRIPT_OBJECT 1 /* has (new Script("x++")).exec() */
|
||||
#define JS_HAS_XDR 1 /* has XDR API and object methods */
|
||||
#define JS_HAS_EXCEPTIONS 1 /* has exception handling */
|
||||
#define JS_HAS_UNDEFINED 1 /* has global "undefined" property */
|
||||
#define JS_HAS_TOSOURCE 1 /* has Object/Array toSource method */
|
||||
#define JS_HAS_IN_OPERATOR 1 /* has in operator ('p' in {p:1}) */
|
||||
#define JS_HAS_INSTANCEOF 1 /* has {p:1} instanceof Object */
|
||||
#define JS_HAS_ARGS_OBJECT 1 /* has minimal ECMA arguments object */
|
||||
#define JS_HAS_DEBUGGER_KEYWORD 1 /* has hook for debugger keyword */
|
||||
#define JS_HAS_ERROR_EXCEPTIONS 1 /* rt errors reflected as exceptions */
|
||||
|
||||
#define JS_HAS_DFLT_MSG_STRINGS 1 /* provides English error messages */
|
||||
|
||||
#else
|
||||
|
||||
#error "unknown JS_VERSION"
|
||||
|
||||
#endif
|
||||
@@ -1,288 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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;
|
||||
}
|
||||
@@ -1,702 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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
@@ -1,76 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 jsdate_h___
|
||||
#define jsdate_h___
|
||||
/*
|
||||
* JS Date class interface.
|
||||
*/
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
extern JSObject *
|
||||
js_InitDateClass(JSContext *cx, JSObject *obj);
|
||||
|
||||
/*
|
||||
* These functions provide a C interface to the date/time object
|
||||
*/
|
||||
extern JS_FRIEND_API(JSObject*)
|
||||
js_NewDateObject(JSContext* cx, int year, int mon, int mday,
|
||||
int hour, int min, int sec);
|
||||
|
||||
extern JS_FRIEND_API(int)
|
||||
js_DateGetYear(JSContext *cx, JSObject* obj);
|
||||
|
||||
extern JS_FRIEND_API(int)
|
||||
js_DateGetMonth(JSContext *cx, JSObject* obj);
|
||||
|
||||
extern JS_FRIEND_API(int)
|
||||
js_DateGetDate(JSContext *cx, JSObject* obj);
|
||||
|
||||
extern JS_FRIEND_API(int)
|
||||
js_DateGetHours(JSContext *cx, JSObject* obj);
|
||||
|
||||
extern JS_FRIEND_API(int)
|
||||
js_DateGetMinutes(JSContext *cx, JSObject* obj);
|
||||
|
||||
extern JS_FRIEND_API(int)
|
||||
js_DateGetSeconds(JSContext *cx, JSObject* obj);
|
||||
|
||||
extern JS_FRIEND_API(void)
|
||||
js_DateSetYear(JSContext *cx, JSObject *obj, int year);
|
||||
|
||||
extern JS_FRIEND_API(void)
|
||||
js_DateSetMonth(JSContext *cx, JSObject *obj, int year);
|
||||
|
||||
extern JS_FRIEND_API(void)
|
||||
js_DateSetDate(JSContext *cx, JSObject *obj, int date);
|
||||
|
||||
extern JS_FRIEND_API(void)
|
||||
js_DateSetHours(JSContext *cx, JSObject *obj, int hours);
|
||||
|
||||
extern JS_FRIEND_API(void)
|
||||
js_DateSetMinutes(JSContext *cx, JSObject *obj, int minutes);
|
||||
|
||||
extern JS_FRIEND_API(void)
|
||||
js_DateSetSeconds(JSContext *cx, JSObject *obj, int seconds);
|
||||
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsdate_h___ */
|
||||
@@ -1,859 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 debugging API.
|
||||
*/
|
||||
#include "jsstddef.h"
|
||||
#include <string.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"
|
||||
#include "jsdbgapi.h"
|
||||
#include "jsfun.h"
|
||||
#include "jsgc.h"
|
||||
#include "jsinterp.h"
|
||||
#include "jslock.h"
|
||||
#include "jsobj.h"
|
||||
#include "jsopcode.h"
|
||||
#include "jsscope.h"
|
||||
#include "jsscript.h"
|
||||
#include "jsstr.h"
|
||||
|
||||
typedef struct JSTrap {
|
||||
JSCList links;
|
||||
JSScript *script;
|
||||
jsbytecode *pc;
|
||||
JSOp op;
|
||||
JSTrapHandler handler;
|
||||
void *closure;
|
||||
} JSTrap;
|
||||
|
||||
static JSTrap *
|
||||
FindTrap(JSRuntime *rt, JSScript *script, jsbytecode *pc)
|
||||
{
|
||||
JSTrap *trap;
|
||||
|
||||
for (trap = (JSTrap *)rt->trapList.next;
|
||||
trap != (JSTrap *)&rt->trapList;
|
||||
trap = (JSTrap *)trap->links.next) {
|
||||
if (trap->script == script && trap->pc == pc)
|
||||
return trap;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
js_PatchOpcode(JSContext *cx, JSScript *script, jsbytecode *pc, JSOp op)
|
||||
{
|
||||
JSTrap *trap;
|
||||
|
||||
trap = FindTrap(cx->runtime, script, pc);
|
||||
if (trap)
|
||||
trap->op = op;
|
||||
else
|
||||
*pc = (jsbytecode)op;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
|
||||
JSTrapHandler handler, void *closure)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
JSTrap *trap;
|
||||
|
||||
rt = cx->runtime;
|
||||
trap = FindTrap(rt, script, pc);
|
||||
if (trap) {
|
||||
/* Restore opcode at pc so it can be saved again. */
|
||||
*pc = (jsbytecode)trap->op;
|
||||
} else {
|
||||
trap = JS_malloc(cx, sizeof *trap);
|
||||
if (!trap || !js_AddRoot(cx, &trap->closure, "trap->closure")) {
|
||||
if (trap)
|
||||
JS_free(cx, trap);
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
JS_APPEND_LINK(&trap->links, &rt->trapList);
|
||||
trap->script = script;
|
||||
trap->pc = pc;
|
||||
trap->op = (JSOp)*pc;
|
||||
trap->handler = handler;
|
||||
trap->closure = closure;
|
||||
*pc = JSOP_TRAP;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSOp)
|
||||
JS_GetTrapOpcode(JSContext *cx, JSScript *script, jsbytecode *pc)
|
||||
{
|
||||
JSTrap *trap;
|
||||
|
||||
trap = FindTrap(cx->runtime, script, pc);
|
||||
if (!trap) {
|
||||
JS_ASSERT(0); /* XXX can't happen */
|
||||
return JSOP_LIMIT;
|
||||
}
|
||||
return trap->op;
|
||||
}
|
||||
|
||||
static void
|
||||
DestroyTrap(JSContext *cx, JSTrap *trap)
|
||||
{
|
||||
JS_REMOVE_LINK(&trap->links);
|
||||
*trap->pc = (jsbytecode)trap->op;
|
||||
js_RemoveRoot(cx, &trap->closure);
|
||||
JS_free(cx, trap);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
|
||||
JSTrapHandler *handlerp, void **closurep)
|
||||
{
|
||||
JSTrap *trap;
|
||||
|
||||
trap = FindTrap(cx->runtime, script, pc);
|
||||
if (handlerp)
|
||||
*handlerp = trap ? trap->handler : NULL;
|
||||
if (closurep)
|
||||
*closurep = trap ? trap->closure : NULL;
|
||||
if (trap)
|
||||
DestroyTrap(cx, trap);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_ClearScriptTraps(JSContext *cx, JSScript *script)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
JSTrap *trap, *next;
|
||||
|
||||
rt = cx->runtime;
|
||||
for (trap = (JSTrap *)rt->trapList.next;
|
||||
trap != (JSTrap *)&rt->trapList;
|
||||
trap = next) {
|
||||
next = (JSTrap *)trap->links.next;
|
||||
if (trap->script == script)
|
||||
DestroyTrap(cx, trap);
|
||||
}
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_ClearAllTraps(JSContext *cx)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
JSTrap *trap, *next;
|
||||
|
||||
rt = cx->runtime;
|
||||
for (trap = (JSTrap *)rt->trapList.next;
|
||||
trap != (JSTrap *)&rt->trapList;
|
||||
trap = next) {
|
||||
next = (JSTrap *)trap->links.next;
|
||||
DestroyTrap(cx, trap);
|
||||
}
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSTrapStatus)
|
||||
JS_HandleTrap(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval)
|
||||
{
|
||||
JSTrap *trap;
|
||||
JSTrapStatus status;
|
||||
jsint op;
|
||||
|
||||
trap = FindTrap(cx->runtime, script, pc);
|
||||
if (!trap) {
|
||||
JS_ASSERT(0); /* XXX can't happen */
|
||||
return JSTRAP_ERROR;
|
||||
}
|
||||
/*
|
||||
* It's important that we not use 'trap->' after calling the callback --
|
||||
* the callback might remove the trap!
|
||||
*/
|
||||
op = (jsint)trap->op;
|
||||
status = trap->handler(cx, script, pc, rval, trap->closure);
|
||||
if (status == JSTRAP_CONTINUE) {
|
||||
/* By convention, return the true op to the interpreter in rval. */
|
||||
*rval = INT_TO_JSVAL(op);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_SetInterrupt(JSRuntime *rt, JSTrapHandler handler, void *closure)
|
||||
{
|
||||
rt->interruptHandler = handler;
|
||||
rt->interruptHandlerData = closure;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_ClearInterrupt(JSRuntime *rt, JSTrapHandler *handlerp, void **closurep)
|
||||
{
|
||||
if (handlerp)
|
||||
*handlerp = (JSTrapHandler)rt->interruptHandler;
|
||||
if (closurep)
|
||||
*closurep = rt->interruptHandlerData;
|
||||
rt->interruptHandler = 0;
|
||||
rt->interruptHandlerData = 0;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
typedef struct JSWatchPoint {
|
||||
JSCList links;
|
||||
JSObject *object; /* weak link, see js_FinalizeObject */
|
||||
jsval userid;
|
||||
JSScopeProperty *sprop;
|
||||
JSPropertyOp setter;
|
||||
JSWatchPointHandler handler;
|
||||
void *closure;
|
||||
jsrefcount nrefs;
|
||||
} JSWatchPoint;
|
||||
|
||||
#define HoldWatchPoint(wp) ((wp)->nrefs++)
|
||||
|
||||
static void
|
||||
DropWatchPoint(JSContext *cx, JSWatchPoint *wp)
|
||||
{
|
||||
if (--wp->nrefs != 0)
|
||||
return;
|
||||
wp->sprop->setter = wp->setter;
|
||||
JS_LOCK_OBJ_VOID(cx, wp->object,
|
||||
js_DropScopeProperty(cx, (JSScope *)wp->object->map,
|
||||
wp->sprop));
|
||||
JS_REMOVE_LINK(&wp->links);
|
||||
js_RemoveRoot(cx, &wp->closure);
|
||||
JS_free(cx, wp);
|
||||
}
|
||||
|
||||
static JSWatchPoint *
|
||||
FindWatchPoint(JSRuntime *rt, JSObject *obj, jsval userid)
|
||||
{
|
||||
JSWatchPoint *wp;
|
||||
|
||||
for (wp = (JSWatchPoint *)rt->watchPointList.next;
|
||||
wp != (JSWatchPoint *)&rt->watchPointList;
|
||||
wp = (JSWatchPoint *)wp->links.next) {
|
||||
if (wp->object == obj && wp->userid == userid)
|
||||
return wp;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JSScopeProperty *
|
||||
js_FindWatchPoint(JSRuntime *rt, JSObject *obj, jsval userid)
|
||||
{
|
||||
JSWatchPoint *wp;
|
||||
|
||||
wp = FindWatchPoint(rt, obj, userid);
|
||||
if (!wp)
|
||||
return NULL;
|
||||
return wp->sprop;
|
||||
}
|
||||
|
||||
JSBool DLL_CALLBACK
|
||||
js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
JSWatchPoint *wp;
|
||||
JSScopeProperty *sprop;
|
||||
JSSymbol *sym;
|
||||
jsval userid, value;
|
||||
jsid symid;
|
||||
JSScope *scope;
|
||||
JSAtom *atom;
|
||||
JSBool ok;
|
||||
|
||||
rt = cx->runtime;
|
||||
for (wp = (JSWatchPoint *)rt->watchPointList.next;
|
||||
wp != (JSWatchPoint *)&rt->watchPointList;
|
||||
wp = (JSWatchPoint *)wp->links.next) {
|
||||
sprop = wp->sprop;
|
||||
if (wp->object == obj && sprop->id == id) {
|
||||
JS_LOCK_OBJ(cx, obj);
|
||||
sym = sprop->symbols;
|
||||
if (!sym) {
|
||||
userid = wp->userid;
|
||||
atom = NULL;
|
||||
if (JSVAL_IS_INT(userid)) {
|
||||
symid = (jsid)userid;
|
||||
} else {
|
||||
atom = js_ValueToStringAtom(cx, userid);
|
||||
if (!atom) {
|
||||
JS_UNLOCK_OBJ(cx, obj);
|
||||
return JS_FALSE;
|
||||
}
|
||||
symid = (jsid)atom;
|
||||
}
|
||||
scope = (JSScope *) obj->map;
|
||||
JS_ASSERT(scope->props);
|
||||
ok = LOCKED_OBJ_GET_CLASS(obj)->addProperty(cx, obj, sprop->id,
|
||||
&value);
|
||||
if (!ok) {
|
||||
JS_UNLOCK_OBJ(cx, obj);
|
||||
return JS_FALSE;
|
||||
}
|
||||
ok = (scope->ops->add(cx, scope, symid, sprop) != NULL);
|
||||
if (!ok) {
|
||||
JS_UNLOCK_OBJ(cx, obj);
|
||||
return JS_FALSE;
|
||||
}
|
||||
sym = sprop->symbols;
|
||||
}
|
||||
JS_UNLOCK_OBJ(cx, obj);
|
||||
HoldWatchPoint(wp);
|
||||
ok = wp->handler(cx, obj, js_IdToValue(sym_id(sym)),
|
||||
OBJ_GET_SLOT(cx, obj, wp->sprop->slot), vp,
|
||||
wp->closure);
|
||||
if (ok)
|
||||
ok = wp->setter(cx, obj, id, vp);
|
||||
DropWatchPoint(cx, wp);
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
JS_ASSERT(0); /* XXX can't happen */
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval id,
|
||||
JSWatchPointHandler handler, void *closure)
|
||||
{
|
||||
JSAtom *atom;
|
||||
jsid symid;
|
||||
JSObject *pobj;
|
||||
JSScopeProperty *sprop;
|
||||
JSRuntime *rt;
|
||||
JSWatchPoint *wp;
|
||||
|
||||
if (!OBJ_IS_NATIVE(obj)) {
|
||||
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_CANT_WATCH,
|
||||
OBJ_GET_CLASS(cx, obj)->name);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
symid = (jsid)id;
|
||||
atom = NULL;
|
||||
} else {
|
||||
atom = js_ValueToStringAtom(cx, id);
|
||||
if (!atom)
|
||||
return JS_FALSE;
|
||||
symid = (jsid)atom;
|
||||
}
|
||||
|
||||
if (!js_LookupProperty(cx, obj, symid, &pobj, (JSProperty **)&sprop))
|
||||
return JS_FALSE;
|
||||
rt = cx->runtime;
|
||||
if (!sprop) {
|
||||
/* Check for a deleted symbol watchpoint, which holds its property. */
|
||||
sprop = js_FindWatchPoint(rt, obj, id);
|
||||
if (sprop) {
|
||||
#ifdef JS_THREADSAFE
|
||||
/* Emulate js_LookupProperty if thread-safe. */
|
||||
JS_LOCK_OBJ(cx, obj);
|
||||
sprop->nrefs++;
|
||||
#endif
|
||||
} else {
|
||||
/* Make a new property in obj so we can watch for the first set. */
|
||||
if (!js_DefineProperty(cx, obj, symid, JSVAL_VOID, NULL, NULL, 0,
|
||||
(JSProperty **)&sprop)) {
|
||||
sprop = NULL;
|
||||
}
|
||||
}
|
||||
} else if (pobj != obj) {
|
||||
/* Clone the prototype property so we can watch the right object. */
|
||||
jsval value;
|
||||
JSPropertyOp getter, setter;
|
||||
uintN attrs;
|
||||
|
||||
if (OBJ_IS_NATIVE(pobj)) {
|
||||
value = LOCKED_OBJ_GET_SLOT(pobj, sprop->slot);
|
||||
} else {
|
||||
if (!OBJ_GET_PROPERTY(cx, pobj, id, &value)) {
|
||||
OBJ_DROP_PROPERTY(cx, pobj, (JSProperty *)sprop);
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
getter = sprop->getter;
|
||||
setter = sprop->setter;
|
||||
attrs = sprop->attrs;
|
||||
OBJ_DROP_PROPERTY(cx, pobj, (JSProperty *)sprop);
|
||||
|
||||
if (!js_DefineProperty(cx, obj, symid, value, getter, setter, attrs,
|
||||
(JSProperty **)&sprop)) {
|
||||
sprop = NULL;
|
||||
}
|
||||
}
|
||||
if (!sprop)
|
||||
return JS_FALSE;
|
||||
|
||||
wp = FindWatchPoint(rt, obj, id);
|
||||
if (!wp) {
|
||||
wp = JS_malloc(cx, sizeof *wp);
|
||||
if (!wp)
|
||||
return JS_FALSE;
|
||||
if (!js_AddRoot(cx, &wp->closure, "wp->closure")) {
|
||||
JS_free(cx, wp);
|
||||
return JS_FALSE;
|
||||
}
|
||||
JS_APPEND_LINK(&wp->links, &rt->watchPointList);
|
||||
wp->object = obj;
|
||||
wp->userid = id;
|
||||
wp->sprop = js_HoldScopeProperty(cx, (JSScope *)obj->map, sprop);
|
||||
wp->setter = sprop->setter;
|
||||
sprop->setter = js_watch_set;
|
||||
wp->nrefs = 1;
|
||||
}
|
||||
wp->handler = handler;
|
||||
wp->closure = closure;
|
||||
OBJ_DROP_PROPERTY(cx, obj, (JSProperty *)sprop);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsval id,
|
||||
JSWatchPointHandler *handlerp, void **closurep)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
JSWatchPoint *wp;
|
||||
|
||||
rt = cx->runtime;
|
||||
for (wp = (JSWatchPoint *)rt->watchPointList.next;
|
||||
wp != (JSWatchPoint *)&rt->watchPointList;
|
||||
wp = (JSWatchPoint *)wp->links.next) {
|
||||
if (wp->object == obj && wp->userid == id) {
|
||||
if (handlerp)
|
||||
*handlerp = wp->handler;
|
||||
if (closurep)
|
||||
*closurep = wp->closure;
|
||||
DropWatchPoint(cx, wp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (handlerp)
|
||||
*handlerp = NULL;
|
||||
if (closurep)
|
||||
*closurep = NULL;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
JSWatchPoint *wp, *next;
|
||||
|
||||
rt = cx->runtime;
|
||||
for (wp = (JSWatchPoint *)rt->watchPointList.next;
|
||||
wp != (JSWatchPoint *)&rt->watchPointList;
|
||||
wp = next) {
|
||||
next = (JSWatchPoint *)wp->links.next;
|
||||
if (wp->object == obj)
|
||||
DropWatchPoint(cx, wp);
|
||||
}
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_ClearAllWatchPoints(JSContext *cx)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
JSWatchPoint *wp, *next;
|
||||
|
||||
rt = cx->runtime;
|
||||
for (wp = (JSWatchPoint *)rt->watchPointList.next;
|
||||
wp != (JSWatchPoint *)&rt->watchPointList;
|
||||
wp = next) {
|
||||
next = (JSWatchPoint *)wp->links.next;
|
||||
DropWatchPoint(cx, wp);
|
||||
}
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(uintN)
|
||||
JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc)
|
||||
{
|
||||
return js_PCToLineNumber(script, pc);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(jsbytecode *)
|
||||
JS_LineNumberToPC(JSContext *cx, JSScript *script, uintN lineno)
|
||||
{
|
||||
return js_LineNumberToPC(script, lineno);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSScript *)
|
||||
JS_GetFunctionScript(JSContext *cx, JSFunction *fun)
|
||||
{
|
||||
return fun->script;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSPrincipals *)
|
||||
JS_GetScriptPrincipals(JSContext *cx, JSScript *script)
|
||||
{
|
||||
return script->principals;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Stack Frame Iterator
|
||||
*/
|
||||
JS_PUBLIC_API(JSStackFrame *)
|
||||
JS_FrameIterator(JSContext *cx, JSStackFrame **iteratorp)
|
||||
{
|
||||
*iteratorp = (*iteratorp == NULL) ? cx->fp : (*iteratorp)->down;
|
||||
return *iteratorp;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSScript *)
|
||||
JS_GetFrameScript(JSContext *cx, JSStackFrame *fp)
|
||||
{
|
||||
return fp->script;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(jsbytecode *)
|
||||
JS_GetFramePC(JSContext *cx, JSStackFrame *fp)
|
||||
{
|
||||
return fp->pc;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void *)
|
||||
JS_GetFrameAnnotation(JSContext *cx, JSStackFrame *fp)
|
||||
{
|
||||
if (fp->annotation) {
|
||||
JSPrincipals *principals = fp->script
|
||||
? fp->script->principals
|
||||
: NULL;
|
||||
|
||||
if (principals == NULL)
|
||||
return NULL;
|
||||
|
||||
if (principals->globalPrivilegesEnabled(cx, principals)) {
|
||||
/*
|
||||
* Only give out an annotation if privileges have not
|
||||
* been revoked globally.
|
||||
*/
|
||||
return fp->annotation;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_SetFrameAnnotation(JSContext *cx, JSStackFrame *fp, void *annotation)
|
||||
{
|
||||
fp->annotation = annotation;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void *)
|
||||
JS_GetFramePrincipalArray(JSContext *cx, JSStackFrame *fp)
|
||||
{
|
||||
JSPrincipals *principals = fp->script
|
||||
? fp->script->principals
|
||||
: NULL;
|
||||
|
||||
return principals
|
||||
? principals->getPrincipalArray(cx, principals)
|
||||
: NULL;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
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)
|
||||
{
|
||||
return fp->thisp;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSFunction *)
|
||||
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 *)
|
||||
JS_GetScriptFilename(JSContext *cx, JSScript *script)
|
||||
{
|
||||
return script->filename;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(uintN)
|
||||
JS_GetScriptBaseLineNumber(JSContext *cx, JSScript *script)
|
||||
{
|
||||
return script->lineno;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(uintN)
|
||||
JS_GetScriptLineExtent(JSContext *cx, JSScript *script)
|
||||
{
|
||||
return js_GetScriptLineExtent(script);
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_SetNewScriptHook(JSRuntime *rt, JSNewScriptHook hook, void *callerdata)
|
||||
{
|
||||
rt->newScriptHook = hook;
|
||||
rt->newScriptHookData = callerdata;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_SetDestroyScriptHook(JSRuntime *rt, JSDestroyScriptHook hook,
|
||||
void *callerdata)
|
||||
{
|
||||
rt->destroyScriptHook = hook;
|
||||
rt->destroyScriptHookData = callerdata;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_EvaluateInStackFrame(JSContext *cx, JSStackFrame *fp,
|
||||
const char *bytes, uintN length,
|
||||
const char *filename, uintN lineno,
|
||||
jsval *rval)
|
||||
{
|
||||
JSScript *script;
|
||||
JSBool ok;
|
||||
|
||||
script = JS_CompileScriptForPrincipals(cx, fp->scopeChain,
|
||||
fp->script ? fp->script->principals
|
||||
: NULL,
|
||||
bytes, length, filename, lineno);
|
||||
if (!script)
|
||||
return JS_FALSE;
|
||||
ok = js_Execute(cx, fp->scopeChain, script, fp->fun, fp, JS_TRUE, rval);
|
||||
js_DestroyScript(cx, script);
|
||||
return ok;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
JS_PUBLIC_API(JSScopeProperty *)
|
||||
JS_PropertyIterator(JSObject *obj, JSScopeProperty **iteratorp)
|
||||
{
|
||||
JSScopeProperty *sprop;
|
||||
JSScope *scope;
|
||||
|
||||
sprop = *iteratorp;
|
||||
scope = (JSScope *) obj->map;
|
||||
sprop = (sprop == NULL) ? scope->props : sprop->next;
|
||||
*iteratorp = sprop;
|
||||
return sprop;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_GetPropertyDesc(JSContext *cx, JSObject *obj, JSScopeProperty *sprop,
|
||||
JSPropertyDesc *pd)
|
||||
{
|
||||
JSSymbol *sym;
|
||||
|
||||
sym = sprop->symbols;
|
||||
pd->id = sym ? js_IdToValue(sym_id(sym)) : JSVAL_VOID;
|
||||
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)
|
||||
: 0;
|
||||
if (!sym || !sym->next || (pd->flags & (JSPD_ARGUMENT | JSPD_VARIABLE))) {
|
||||
pd->alias = JSVAL_VOID;
|
||||
} else {
|
||||
pd->alias = js_IdToValue(sym_id(sym->next));
|
||||
pd->flags |= JSPD_ALIAS;
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda)
|
||||
{
|
||||
JSScope *scope;
|
||||
uint32 i, n;
|
||||
JSPropertyDesc *pd;
|
||||
JSScopeProperty *sprop;
|
||||
jsval state;
|
||||
jsid num_prop;
|
||||
|
||||
if (!OBJ_ENUMERATE(cx, obj, JSENUMERATE_INIT, &state, &num_prop))
|
||||
return JS_FALSE;
|
||||
scope = (JSScope *)obj->map;
|
||||
/* 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;
|
||||
}
|
||||
n = scope->map.freeslot;
|
||||
pd = JS_malloc(cx, (size_t)n * sizeof(JSPropertyDesc));
|
||||
if (!pd)
|
||||
return JS_FALSE;
|
||||
i = 0;
|
||||
for (sprop = scope->props; sprop; sprop = sprop->next) {
|
||||
if (!js_AddRoot(cx, &pd[i].id, NULL))
|
||||
goto bad;
|
||||
if (!js_AddRoot(cx, &pd[i].value, NULL))
|
||||
goto bad;
|
||||
JS_GetPropertyDesc(cx, obj, sprop, &pd[i]);
|
||||
if ((pd[i].flags & JSPD_ALIAS) && !js_AddRoot(cx, &pd[i].alias, NULL))
|
||||
goto bad;
|
||||
if (++i == n)
|
||||
break;
|
||||
}
|
||||
pda->length = i;
|
||||
pda->array = pd;
|
||||
return JS_TRUE;
|
||||
|
||||
bad:
|
||||
pda->length = i + 1;
|
||||
pda->array = pd;
|
||||
JS_PutPropertyDescArray(cx, pda);
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda)
|
||||
{
|
||||
JSPropertyDesc *pd;
|
||||
uint32 i;
|
||||
|
||||
pd = pda->array;
|
||||
for (i = 0; i < pda->length; i++) {
|
||||
js_RemoveRoot(cx, &pd[i].id);
|
||||
js_RemoveRoot(cx, &pd[i].value);
|
||||
if (pd[i].flags & JSPD_ALIAS)
|
||||
js_RemoveRoot(cx, &pd[i].alias);
|
||||
}
|
||||
JS_free(cx, pd);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
JS_PUBLIC_API(JSBool)
|
||||
JS_SetDebuggerHandler(JSRuntime *rt, JSTrapHandler handler, void *closure)
|
||||
{
|
||||
rt->debuggerHandler = handler;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,245 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 jsdbgapi_h___
|
||||
#define jsdbgapi_h___
|
||||
/*
|
||||
* JS debugger API.
|
||||
*/
|
||||
#include "jsapi.h"
|
||||
#include "jsopcode.h"
|
||||
#include "jsprvtd.h"
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
extern void
|
||||
js_PatchOpcode(JSContext *cx, JSScript *script, jsbytecode *pc, JSOp op);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
|
||||
JSTrapHandler handler, void *closure);
|
||||
|
||||
extern JS_PUBLIC_API(JSOp)
|
||||
JS_GetTrapOpcode(JSContext *cx, JSScript *script, jsbytecode *pc);
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
|
||||
JSTrapHandler *handlerp, void **closurep);
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_ClearScriptTraps(JSContext *cx, JSScript *script);
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_ClearAllTraps(JSContext *cx);
|
||||
|
||||
extern JS_PUBLIC_API(JSTrapStatus)
|
||||
JS_HandleTrap(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetInterrupt(JSRuntime *rt, JSTrapHandler handler, void *closure);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_ClearInterrupt(JSRuntime *rt, JSTrapHandler *handlerp, void **closurep);
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsval id,
|
||||
JSWatchPointHandler handler, void *closure);
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsval id,
|
||||
JSWatchPointHandler *handlerp, void **closurep);
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj);
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_ClearAllWatchPoints(JSContext *cx);
|
||||
|
||||
#ifdef JS_HAS_OBJ_WATCHPOINT
|
||||
/*
|
||||
* Hide these non-API function prototypes by testing whether the internal
|
||||
* header file "jsconfig.h" has been included.
|
||||
*/
|
||||
extern JSScopeProperty *
|
||||
js_FindWatchPoint(JSRuntime *rt, JSObject *obj, jsval userid);
|
||||
|
||||
extern JSBool DLL_CALLBACK
|
||||
js_watch_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
|
||||
#endif
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
extern JS_PUBLIC_API(uintN)
|
||||
JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc);
|
||||
|
||||
extern JS_PUBLIC_API(jsbytecode *)
|
||||
JS_LineNumberToPC(JSContext *cx, JSScript *script, uintN lineno);
|
||||
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_GetFunctionScript(JSContext *cx, JSFunction *fun);
|
||||
|
||||
extern JS_PUBLIC_API(JSPrincipals *)
|
||||
JS_GetScriptPrincipals(JSContext *cx, JSScript *script);
|
||||
|
||||
/*
|
||||
* Stack Frame Iterator
|
||||
*
|
||||
* Used to iterate through the JS stack frames to extract
|
||||
* information from the frames.
|
||||
*/
|
||||
|
||||
extern JS_PUBLIC_API(JSStackFrame *)
|
||||
JS_FrameIterator(JSContext *cx, JSStackFrame **iteratorp);
|
||||
|
||||
extern JS_PUBLIC_API(JSScript *)
|
||||
JS_GetFrameScript(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
extern JS_PUBLIC_API(jsbytecode *)
|
||||
JS_GetFramePC(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_IsNativeFrame(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
extern JS_PUBLIC_API(void *)
|
||||
JS_GetFrameAnnotation(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_SetFrameAnnotation(JSContext *cx, JSStackFrame *fp, void *annotation);
|
||||
|
||||
extern JS_PUBLIC_API(void *)
|
||||
JS_GetFramePrincipalArray(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
/* 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 *)
|
||||
JS_GetScriptFilename(JSContext *cx, JSScript *script);
|
||||
|
||||
extern JS_PUBLIC_API(uintN)
|
||||
JS_GetScriptBaseLineNumber(JSContext *cx, JSScript *script);
|
||||
|
||||
extern JS_PUBLIC_API(uintN)
|
||||
JS_GetScriptLineExtent(JSContext *cx, JSScript *script);
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
/*
|
||||
* Hook setters for script creation and destruction, see jsprvtd.h for the
|
||||
* typedefs. These macros provide binary compatibility and newer, shorter
|
||||
* synonyms.
|
||||
*/
|
||||
#define JS_SetNewScriptHook JS_SetNewScriptHookProc
|
||||
#define JS_SetDestroyScriptHook JS_SetDestroyScriptHookProc
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_SetNewScriptHook(JSRuntime *rt, JSNewScriptHook hook, void *callerdata);
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_SetDestroyScriptHook(JSRuntime *rt, JSDestroyScriptHook hook,
|
||||
void *callerdata);
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_EvaluateInStackFrame(JSContext *cx, JSStackFrame *fp,
|
||||
const char *bytes, uintN length,
|
||||
const char *filename, uintN lineno,
|
||||
jsval *rval);
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
typedef struct JSPropertyDesc {
|
||||
jsval id; /* primary id, a string or int */
|
||||
jsval value; /* property value */
|
||||
uint8 flags; /* flags, see below */
|
||||
uint8 spare; /* unused */
|
||||
uint16 slot; /* argument/variable slot */
|
||||
jsval alias; /* alias id if JSPD_ALIAS flag */
|
||||
} JSPropertyDesc;
|
||||
|
||||
#define JSPD_ENUMERATE 0x01 /* visible to for/in loop */
|
||||
#define JSPD_READONLY 0x02 /* assignment is error */
|
||||
#define JSPD_PERMANENT 0x04 /* property cannot be deleted */
|
||||
#define JSPD_ALIAS 0x08 /* property has an alias id */
|
||||
#define JSPD_ARGUMENT 0x10 /* argument to function */
|
||||
#define JSPD_VARIABLE 0x20 /* local variable in function */
|
||||
|
||||
typedef struct JSPropertyDescArray {
|
||||
uint32 length; /* number of elements in array */
|
||||
JSPropertyDesc *array; /* alloc'd by Get, freed by Put */
|
||||
} JSPropertyDescArray;
|
||||
|
||||
extern JS_PUBLIC_API(JSScopeProperty *)
|
||||
JS_PropertyIterator(JSObject *obj, JSScopeProperty **iteratorp);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_GetPropertyDesc(JSContext *cx, JSObject *obj, JSScopeProperty *sprop,
|
||||
JSPropertyDesc *pd);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda);
|
||||
|
||||
extern JS_PUBLIC_API(void)
|
||||
JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda);
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetDebuggerHandler(JSRuntime *rt, JSTrapHandler handler, void *closure);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure);
|
||||
|
||||
extern JS_PUBLIC_API(JSBool)
|
||||
JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure);
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsdbgapi_h___ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,54 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 jsdtoa_h___
|
||||
#define jsdtoa_h___
|
||||
/*
|
||||
* Public interface to portable double-precision floating point to string
|
||||
* and back conversion package.
|
||||
*/
|
||||
|
||||
#include "jscompat.h"
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
* PR_strtod() returns as a double-precision floating-point number
|
||||
* the value represented by the character string pointed to by
|
||||
* s00. The string is scanned up to the first unrecognized
|
||||
* character.
|
||||
* If the value of se is not (char **)NULL, a pointer to
|
||||
* the character terminating the scan is returned in the location pointed
|
||||
* to by se. If no number can be formed, se is set to s00r, and
|
||||
* zero is returned.
|
||||
*/
|
||||
extern PUBLIC_API(double)
|
||||
PR_strtod(const char *s00, char **se);
|
||||
|
||||
/*
|
||||
* PR_cnvtf()
|
||||
* conversion routines for floating point
|
||||
* prcsn - number of digits of precision to generate floating
|
||||
* point value.
|
||||
*/
|
||||
extern PUBLIC_API(void)
|
||||
PR_cnvtf(char *buf, intN bufsz, intN prcsn, double dval);
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsdtoa_h___ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,366 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 jsemit_h___
|
||||
#define jsemit_h___
|
||||
/*
|
||||
* JS bytecode generation.
|
||||
*/
|
||||
|
||||
#include "jsstddef.h"
|
||||
#include "jstypes.h"
|
||||
#include "jsatom.h"
|
||||
#include "jsopcode.h"
|
||||
#include "jsprvtd.h"
|
||||
#include "jspubtd.h"
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
typedef enum JSStmtType {
|
||||
STMT_BLOCK = 0, /* compound statement: { s1[;... sN] } */
|
||||
STMT_LABEL = 1, /* labeled statement: l: s */
|
||||
STMT_IF = 2, /* if (then) statement */
|
||||
STMT_ELSE = 3, /* else statement */
|
||||
STMT_SWITCH = 4, /* switch statement */
|
||||
STMT_WITH = 5, /* with statement */
|
||||
STMT_TRY = 6, /* try statement */
|
||||
STMT_CATCH = 7, /* catch block */
|
||||
STMT_FINALLY = 8, /* finally statement */
|
||||
STMT_DO_LOOP = 9, /* do/while loop statement */
|
||||
STMT_FOR_LOOP = 10, /* for loop statement */
|
||||
STMT_FOR_IN_LOOP = 11, /* for/in loop statement */
|
||||
STMT_WHILE_LOOP = 12 /* while loop statement */
|
||||
} JSStmtType;
|
||||
|
||||
#define STMT_IS_LOOP(stmt) ((stmt)->type >= STMT_DO_LOOP)
|
||||
|
||||
typedef struct JSStmtInfo JSStmtInfo;
|
||||
|
||||
struct JSStmtInfo {
|
||||
JSStmtType type; /* statement type */
|
||||
ptrdiff_t top; /* offset of loop top from cg base */
|
||||
ptrdiff_t update; /* loop update offset (top if none) */
|
||||
ptrdiff_t breaks; /* offset of last break in loop */
|
||||
ptrdiff_t continues; /* offset of last continue in loop */
|
||||
JSAtom *label; /* label name if type is STMT_LABEL */
|
||||
JSStmtInfo *down; /* info for enclosing statement */
|
||||
};
|
||||
|
||||
#define SET_STATEMENT_TOP(stmt, 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 */
|
||||
uint32 tryCount; /* total count of try statements parsed */
|
||||
JSStmtInfo *topStmt; /* top of statement info stack */
|
||||
};
|
||||
|
||||
#define TCF_IN_FUNCTION 0x01 /* parsing inside function body */
|
||||
#define TCF_RETURN_EXPR 0x02 /* function has 'return expr;' */
|
||||
#define TCF_RETURN_VOID 0x04 /* function has 'return;' */
|
||||
#define TCF_IN_FOR_INIT 0x08 /* parsing init expr of for; exclude 'in' */
|
||||
|
||||
#define TREE_CONTEXT_INIT(tc) \
|
||||
((tc)->flags = 0, (tc)->tryCount = 0, (tc)->topStmt = NULL)
|
||||
|
||||
struct JSCodeGenerator {
|
||||
void *codeMark; /* low watermark in cx->codePool */
|
||||
void *tempMark; /* low watermark in cx->tempPool */
|
||||
jsbytecode *base; /* base of JS bytecode vector */
|
||||
jsbytecode *limit; /* one byte beyond end of bytecode */
|
||||
jsbytecode *next; /* pointer to next free bytecode */
|
||||
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 */
|
||||
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)
|
||||
|
||||
/*
|
||||
* Initialize cg to allocate bytecode space from cx->codePool, and srcnote
|
||||
* space from cx->tempPool. Return true on success. Report an error and
|
||||
* return false if the initial code segment can't be allocated.
|
||||
*/
|
||||
extern JS_FRIEND_API(JSBool)
|
||||
js_InitCodeGenerator(JSContext *cx, JSCodeGenerator *cg,
|
||||
const char *filename, uintN lineno,
|
||||
JSPrincipals *principals);
|
||||
|
||||
/*
|
||||
* Release cx->codePool and cx->tempPool to marks set by js_InitCodeGenerator.
|
||||
*/
|
||||
extern JS_FRIEND_API(void)
|
||||
js_ResetCodeGenerator(JSContext *cx, JSCodeGenerator *cg);
|
||||
|
||||
/*
|
||||
* Emit one bytecode.
|
||||
*/
|
||||
extern ptrdiff_t
|
||||
js_Emit1(JSContext *cx, JSCodeGenerator *cg, JSOp op);
|
||||
|
||||
/*
|
||||
* Emit two bytecodes, an opcode (op) with a byte of immediate operand (op1).
|
||||
*/
|
||||
extern ptrdiff_t
|
||||
js_Emit2(JSContext *cx, JSCodeGenerator *cg, JSOp op, jsbytecode op1);
|
||||
|
||||
/*
|
||||
* Emit three bytecodes, an opcode with two bytes of immediate operands.
|
||||
*/
|
||||
extern ptrdiff_t
|
||||
js_Emit3(JSContext *cx, JSCodeGenerator *cg, JSOp op, jsbytecode op1,
|
||||
jsbytecode op2);
|
||||
|
||||
/*
|
||||
* Emit (1 + extra) bytecodes, for N bytes of op and its immediate operand.
|
||||
*/
|
||||
extern ptrdiff_t
|
||||
js_EmitN(JSContext *cx, JSCodeGenerator *cg, JSOp op, size_t extra);
|
||||
|
||||
/*
|
||||
* Unsafe macro to call js_SetJumpOffset and return false if it does.
|
||||
*/
|
||||
#define CHECK_AND_SET_JUMP_OFFSET(cx,cg,pc,off) \
|
||||
JS_BEGIN_MACRO \
|
||||
if (!js_SetJumpOffset(cx, cg, pc, off)) \
|
||||
return JS_FALSE; \
|
||||
JS_END_MACRO
|
||||
|
||||
#define CHECK_AND_SET_JUMP_OFFSET_AT(cx,cg,off) \
|
||||
CHECK_AND_SET_JUMP_OFFSET(cx, cg, CG_CODE(cg,off), CG_OFFSET(cg) - (off))
|
||||
|
||||
extern JSBool
|
||||
js_SetJumpOffset(JSContext *cx, JSCodeGenerator *cg, jsbytecode *pc,
|
||||
ptrdiff_t off);
|
||||
|
||||
/*
|
||||
* Push the C-stack-allocated struct at stmt onto the stmtInfo stack.
|
||||
*/
|
||||
extern void
|
||||
js_PushStatement(JSTreeContext *tc, JSStmtInfo *stmt, JSStmtType type,
|
||||
ptrdiff_t top);
|
||||
|
||||
/*
|
||||
* Emit a break instruction, recording it for backpatching.
|
||||
*/
|
||||
extern ptrdiff_t
|
||||
js_EmitBreak(JSContext *cx, JSCodeGenerator *cg, JSStmtInfo *stmt,
|
||||
JSAtomListElement *label);
|
||||
|
||||
/*
|
||||
* Emit a continue instruction, recording it for backpatching.
|
||||
*/
|
||||
extern ptrdiff_t
|
||||
js_EmitContinue(JSContext *cx, JSCodeGenerator *cg, JSStmtInfo *stmt,
|
||||
JSAtomListElement *label);
|
||||
|
||||
/*
|
||||
* Pop tc->topStmt. If the top JSStmtInfo struct is not stack-allocated, it
|
||||
* is up to the caller to free it.
|
||||
*/
|
||||
extern void
|
||||
js_PopStatement(JSTreeContext *tc);
|
||||
|
||||
/*
|
||||
* Like js_PopStatement(&cg->treeContext), also patch breaks and continues.
|
||||
* May fail if a jump offset overflows.
|
||||
*/
|
||||
extern JSBool
|
||||
js_PopStatementCG(JSContext *cx, JSCodeGenerator *cg);
|
||||
|
||||
/*
|
||||
* Emit code into cg for the tree rooted at pn.
|
||||
*/
|
||||
extern JSBool
|
||||
js_EmitTree(JSContext *cx, JSCodeGenerator *cg, JSParseNode *pn);
|
||||
|
||||
/*
|
||||
* Emit code into cg for the tree rooted at body, then create a persistent
|
||||
* script for fun from cg.
|
||||
*/
|
||||
extern JSBool
|
||||
js_EmitFunctionBody(JSContext *cx, JSCodeGenerator *cg, JSParseNode *body,
|
||||
JSFunction *fun);
|
||||
|
||||
/*
|
||||
* Source notes generated along with bytecode for decompiling and debugging.
|
||||
* A source note is a uint8 with 5 bits of type and 3 of offset from the pc of
|
||||
* the previous note. If 3 bits of offset aren't enough, extended delta notes
|
||||
* (SRC_XDELTA) consisting of 2 set high order bits followed by 6 offset bits
|
||||
* are emitted before the next note. Some notes have operand offsets encoded
|
||||
* immediately after them, in note bytes or byte-triples.
|
||||
*
|
||||
* At most one "gettable" note (i.e., a note of type other than SRC_NEWLINE,
|
||||
* SRC_SETLINE, and SRC_XDELTA) applies to a given bytecode.
|
||||
*
|
||||
* NB: the js_SrcNoteName and js_SrcNoteArity arrays in jsemit.c are indexed
|
||||
* by this enum, so their initializers need to match the order here.
|
||||
*/
|
||||
typedef enum JSSrcNoteType {
|
||||
SRC_NULL = 0, /* terminates a note vector */
|
||||
SRC_IF = 1, /* JSOP_IFEQ bytecode is from an if-then */
|
||||
SRC_IF_ELSE = 2, /* JSOP_IFEQ bytecode is from an if-then-else */
|
||||
SRC_WHILE = 3, /* JSOP_IFEQ is from a while loop */
|
||||
SRC_FOR = 4, /* JSOP_NOP or JSOP_POP in for loop head */
|
||||
SRC_CONTINUE = 5, /* JSOP_GOTO is a continue, not a break;
|
||||
also used on JSOP_ENDINIT if extra comma
|
||||
at end of array literal: [1,2,,] */
|
||||
SRC_VAR = 6, /* JSOP_NAME/FORNAME with a var declaration */
|
||||
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 */
|
||||
SRC_HIDDEN = 11, /* opcode shouldn't be decompiled */
|
||||
SRC_PCBASE = 12, /* offset of first obj.prop.subprop bytecode */
|
||||
SRC_LABEL = 13, /* JSOP_NOP for label: with atomid immediate */
|
||||
SRC_LABELBRACE = 14, /* JSOP_NOP for label: {...} begin brace */
|
||||
SRC_ENDBRACE = 15, /* JSOP_NOP for label: {...} end brace */
|
||||
SRC_BREAK2LABEL = 16, /* JSOP_GOTO for 'break label' with atomid */
|
||||
SRC_CONT2LABEL = 17, /* JSOP_GOTO for 'continue label' with atomid */
|
||||
SRC_SWITCH = 18, /* JSOP_*SWITCH with offset to end of switch,
|
||||
2nd off to first JSOP_CASE if condswitch */
|
||||
SRC_FUNCDEF = 19, /* JSOP_NOP for function f() with atomid */
|
||||
SRC_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 */
|
||||
SRC_XDELTA = 24 /* 24-31 are for extended delta notes */
|
||||
} JSSrcNoteType;
|
||||
|
||||
#define SN_TYPE_BITS 5
|
||||
#define SN_DELTA_BITS 3
|
||||
#define SN_XDELTA_BITS 6
|
||||
#define SN_TYPE_MASK (JS_BITMASK(SN_TYPE_BITS) << SN_DELTA_BITS)
|
||||
#define SN_DELTA_MASK ((ptrdiff_t)JS_BITMASK(SN_DELTA_BITS))
|
||||
#define SN_XDELTA_MASK ((ptrdiff_t)JS_BITMASK(SN_XDELTA_BITS))
|
||||
|
||||
#define SN_MAKE_NOTE(sn,t,d) (*(sn) = (jssrcnote) \
|
||||
(((t) << SN_DELTA_BITS) \
|
||||
| ((d) & SN_DELTA_MASK)))
|
||||
#define SN_MAKE_XDELTA(sn,d) (*(sn) = (jssrcnote) \
|
||||
((SRC_XDELTA << SN_DELTA_BITS) \
|
||||
| ((d) & SN_XDELTA_MASK)))
|
||||
|
||||
#define SN_IS_XDELTA(sn) ((*(sn) >> SN_DELTA_BITS) >= SRC_XDELTA)
|
||||
#define SN_TYPE(sn) (SN_IS_XDELTA(sn) ? SRC_XDELTA \
|
||||
: *(sn) >> SN_DELTA_BITS)
|
||||
#define SN_SET_TYPE(sn,type) SN_MAKE_NOTE(sn, type, SN_DELTA(sn))
|
||||
#define SN_IS_GETTABLE(sn) (SN_TYPE(sn) < SRC_NEWLINE)
|
||||
|
||||
#define SN_DELTA(sn) ((ptrdiff_t)(SN_IS_XDELTA(sn) \
|
||||
? *(sn) & SN_XDELTA_MASK \
|
||||
: *(sn) & SN_DELTA_MASK))
|
||||
#define SN_SET_DELTA(sn,delta) (SN_IS_XDELTA(sn) \
|
||||
? SN_MAKE_XDELTA(sn, delta) \
|
||||
: SN_MAKE_NOTE(sn, SN_TYPE(sn), delta))
|
||||
|
||||
#define SN_DELTA_LIMIT ((ptrdiff_t)JS_BIT(SN_DELTA_BITS))
|
||||
#define SN_XDELTA_LIMIT ((ptrdiff_t)JS_BIT(SN_XDELTA_BITS))
|
||||
|
||||
/*
|
||||
* Offset fields follow certain notes and are frequency-encoded: an offset in
|
||||
* [0,0x7f] consumes one byte, an offset in [0x80,0x7fffff] takes three, and
|
||||
* the high bit of the first byte is set.
|
||||
*/
|
||||
#define SN_3BYTE_OFFSET_FLAG 0x80
|
||||
#define SN_3BYTE_OFFSET_MASK 0x7f
|
||||
|
||||
extern JS_FRIEND_DATA(const char *) js_SrcNoteName[];
|
||||
extern JS_FRIEND_DATA(uint8) js_SrcNoteArity[];
|
||||
extern JS_FRIEND_DATA(uintN) js_SrcNoteLength(jssrcnote *sn);
|
||||
|
||||
#define SN_LENGTH(sn) ((js_SrcNoteArity[SN_TYPE(sn)] == 0) ? 1 \
|
||||
: js_SrcNoteLength(sn))
|
||||
#define SN_NEXT(sn) ((sn) + SN_LENGTH(sn))
|
||||
|
||||
/* A source note array is terminated by an all-zero element. */
|
||||
#define SN_MAKE_TERMINATOR(sn) (*(sn) = SRC_NULL)
|
||||
#define SN_IS_TERMINATOR(sn) (*(sn) == SRC_NULL)
|
||||
|
||||
/*
|
||||
* Append a new source note of the given type (and therefore size) to cg's
|
||||
* notes dynamic array, updating cg->noteCount. Return the new note's index
|
||||
* within the array pointed at by cg->notes. Return -1 if out of memory.
|
||||
*/
|
||||
extern intN
|
||||
js_NewSrcNote(JSContext *cx, JSCodeGenerator *cg, JSSrcNoteType type);
|
||||
|
||||
extern intN
|
||||
js_NewSrcNote2(JSContext *cx, JSCodeGenerator *cg, JSSrcNoteType type,
|
||||
ptrdiff_t offset);
|
||||
|
||||
extern intN
|
||||
js_NewSrcNote3(JSContext *cx, JSCodeGenerator *cg, JSSrcNoteType type,
|
||||
ptrdiff_t offset1, ptrdiff_t offset2);
|
||||
|
||||
/*
|
||||
* Get and set the offset operand identified by which (0 for the first, etc.).
|
||||
*/
|
||||
extern JS_FRIEND_API(ptrdiff_t)
|
||||
js_GetSrcNoteOffset(jssrcnote *sn, uintN which);
|
||||
|
||||
extern JSBool
|
||||
js_SetSrcNoteOffset(JSContext *cx, JSCodeGenerator *cg, uintN index,
|
||||
uintN which, ptrdiff_t offset);
|
||||
|
||||
/*
|
||||
* Finish taking source notes in cx's tempPool by copying them to new
|
||||
* stable store allocated via JS_malloc. Return null on malloc failure,
|
||||
* which means this function reported an error.
|
||||
*/
|
||||
extern jssrcnote *
|
||||
js_FinishTakingSrcNotes(JSContext *cx, JSCodeGenerator *cg);
|
||||
|
||||
/*
|
||||
* Allocate cg->treeContext.tryCount notes (plus one for the end sentinel)
|
||||
* from cx->tempPool and set up cg->tryBase/tryNext for exactly tryCount
|
||||
* js_NewTryNote calls. The storage is freed by js_ResetCodeGenerator.
|
||||
*/
|
||||
extern JSBool
|
||||
js_AllocTryNotes(JSContext *cx, JSCodeGenerator *cg);
|
||||
|
||||
/*
|
||||
* Grab the next trynote slot in cg, filling it in appropriately.
|
||||
*/
|
||||
extern JSTryNote *
|
||||
js_NewTryNote(JSContext *cx, JSCodeGenerator *cg, ptrdiff_t start,
|
||||
ptrdiff_t end, ptrdiff_t catchStart);
|
||||
|
||||
/*
|
||||
* Finish generating exception information, and copy it to JS_malloc
|
||||
* storage.
|
||||
*/
|
||||
extern JSBool
|
||||
js_FinishTakingTryNotes(JSContext *cx, JSCodeGenerator *cg, JSTryNote **tryp);
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsemit_h___ */
|
||||
@@ -1,477 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 */
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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___ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,106 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 jsfun_h___
|
||||
#define jsfun_h___
|
||||
/*
|
||||
* JS function definitions.
|
||||
*/
|
||||
#include "jsprvtd.h"
|
||||
#include "jspubtd.h"
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
struct JSFunction {
|
||||
jsrefcount nrefs; /* number of referencing objects */
|
||||
JSObject *object; /* back-pointer to GC'ed object header */
|
||||
JSNative call; /* native method pointer or null */
|
||||
uint16 nargs; /* minimum number of actual arguments */
|
||||
uint16 extra; /* number of arg slots for local GC roots */
|
||||
uint16 nvars; /* number of local variables */
|
||||
uint8 flags; /* bound method and other flags, see jsapi.h */
|
||||
uint8 spare; /* reserved for future use */
|
||||
JSAtom *atom; /* name for diagnostics and decompiling */
|
||||
JSScript *script; /* interpreted bytecode descriptor or null */
|
||||
};
|
||||
|
||||
extern JSClass js_ArgumentsClass;
|
||||
extern JSClass js_CallClass;
|
||||
extern JSClass js_ClosureClass;
|
||||
/* JS_FRIEND_DATA so that JSVAL_IS_FUNCTION is callable from outside */
|
||||
extern JS_FRIEND_DATA(JSClass) js_FunctionClass;
|
||||
|
||||
/*
|
||||
* NB: jsapi.h and jsobj.h must be included before any call to this macro.
|
||||
*/
|
||||
#define JSVAL_IS_FUNCTION(cx, v) \
|
||||
(JSVAL_IS_OBJECT(v) && JSVAL_TO_OBJECT(v) && \
|
||||
OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(v)) == &js_FunctionClass)
|
||||
|
||||
extern JSBool
|
||||
js_IsIdentifier(JSString *str);
|
||||
|
||||
extern JSObject *
|
||||
js_InitFunctionClass(JSContext *cx, JSObject *obj);
|
||||
|
||||
extern JSBool
|
||||
js_InitArgsCallClosureClasses(JSContext *cx, JSObject *obj,
|
||||
JSObject *arrayProto);
|
||||
|
||||
extern JSFunction *
|
||||
js_NewFunction(JSContext *cx, JSObject *funobj, JSNative call, uintN nargs,
|
||||
uintN flags, JSObject *parent, JSAtom *atom);
|
||||
|
||||
extern JSBool
|
||||
js_LinkFunctionObject(JSContext *cx, JSFunction *fun, JSObject *object);
|
||||
|
||||
extern JSFunction *
|
||||
js_DefineFunction(JSContext *cx, JSObject *obj, JSAtom *atom, JSNative call,
|
||||
uintN nargs, uintN flags);
|
||||
|
||||
extern JSFunction *
|
||||
js_ValueToFunction(JSContext *cx, jsval *vp, JSBool constructing);
|
||||
|
||||
extern void
|
||||
js_ReportIsNotFunction(JSContext *cx, jsval *vp, JSBool constructing);
|
||||
|
||||
extern JSObject *
|
||||
js_GetCallObject(JSContext *cx, JSStackFrame *fp, JSObject *parent,
|
||||
JSObject *withobj);
|
||||
|
||||
extern JSBool
|
||||
js_PutCallObject(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
extern JSBool
|
||||
js_GetCallVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
|
||||
|
||||
extern JSBool
|
||||
js_SetCallVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
|
||||
|
||||
extern JSObject *
|
||||
js_GetArgsObject(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
extern JSBool
|
||||
js_PutArgsObject(JSContext *cx, JSStackFrame *fp);
|
||||
|
||||
extern JSBool
|
||||
js_XDRFunction(JSXDRState *xdr, JSObject **objp);
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsfun_h___ */
|
||||
@@ -1,925 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 Mark-and-Sweep Garbage Collector.
|
||||
*
|
||||
* 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
|
||||
* 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 JS_ARENA_DESTROY */
|
||||
#include <string.h> /* for memset, called by jsarena.h macros if DEBUG */
|
||||
#include "jstypes.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 */
|
||||
#ifndef NSPR20
|
||||
#include "jshash.h"
|
||||
#else
|
||||
/* Removed by JSIFY: #include "JShash.h"
|
||||
*/
|
||||
#include "jshash.h" /* Added by JSIFY */
|
||||
#endif
|
||||
#include "jsapi.h"
|
||||
#include "jsatom.h"
|
||||
#include "jscntxt.h"
|
||||
#include "jsfun.h"
|
||||
#include "jsgc.h"
|
||||
#include "jsinterp.h"
|
||||
#include "jslock.h"
|
||||
#include "jsnum.h"
|
||||
#include "jsobj.h"
|
||||
#include "jsscope.h"
|
||||
#include "jsscript.h"
|
||||
#include "jsstr.h"
|
||||
|
||||
/*
|
||||
* Arena sizes, the first must be a multiple of the second so the two arena
|
||||
* pools can be maintained (in particular, arenas may be destroyed from the
|
||||
* middle of each pool) in parallel.
|
||||
*/
|
||||
#define GC_ARENA_SIZE 8192 /* 1024 (512 on Alpha) objects */
|
||||
#define GC_FLAGS_SIZE (GC_ARENA_SIZE / sizeof(JSGCThing))
|
||||
#define GC_ROOTS_SIZE 256 /* SWAG, small enough to amortize */
|
||||
|
||||
static JSHashNumber gc_hash_root(const void *key);
|
||||
|
||||
struct JSGCThing {
|
||||
JSGCThing *next;
|
||||
uint8 *flagp;
|
||||
};
|
||||
|
||||
typedef void (*GCFinalizeOp)(JSContext *cx, JSGCThing *thing);
|
||||
|
||||
static GCFinalizeOp gc_finalizers[GCX_NTYPES];
|
||||
|
||||
#ifdef JS_GCMETER
|
||||
#define METER(x) x
|
||||
#else
|
||||
#define METER(x) /* nothing */
|
||||
#endif
|
||||
|
||||
JSBool
|
||||
js_InitGC(JSRuntime *rt, uint32 maxbytes)
|
||||
{
|
||||
if (!gc_finalizers[GCX_OBJECT]) {
|
||||
gc_finalizers[GCX_OBJECT] = (GCFinalizeOp)js_FinalizeObject;
|
||||
gc_finalizers[GCX_STRING] = (GCFinalizeOp)js_FinalizeString;
|
||||
gc_finalizers[GCX_DOUBLE] = (GCFinalizeOp)js_FinalizeDouble;
|
||||
}
|
||||
|
||||
JS_InitArenaPool(&rt->gcArenaPool, "gc-arena", GC_ARENA_SIZE,
|
||||
sizeof(JSGCThing));
|
||||
JS_InitArenaPool(&rt->gcFlagsPool, "gc-flags", GC_FLAGS_SIZE,
|
||||
sizeof(uint8));
|
||||
rt->gcRootsHash = JS_NewHashTable(GC_ROOTS_SIZE, gc_hash_root,
|
||||
JS_CompareValues, JS_CompareValues,
|
||||
NULL, NULL);
|
||||
if (!rt->gcRootsHash)
|
||||
return JS_FALSE;
|
||||
rt->gcMaxBytes = maxbytes;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
#ifdef JS_GCMETER
|
||||
void
|
||||
js_DumpGCStats(JSRuntime *rt, FILE *fp)
|
||||
{
|
||||
fprintf(fp, "\nGC allocation statistics:\n");
|
||||
fprintf(fp, " bytes currently allocated: %lu\n", rt->gcBytes);
|
||||
fprintf(fp, " alloc attempts: %lu\n", rt->gcStats.alloc);
|
||||
fprintf(fp, " GC freelist length: %lu\n", rt->gcStats.freelen);
|
||||
fprintf(fp, " recycles through GC freelist: %lu\n", rt->gcStats.recycle);
|
||||
fprintf(fp, "alloc retries after running GC: %lu\n", rt->gcStats.retry);
|
||||
fprintf(fp, " allocation failures: %lu\n", rt->gcStats.fail);
|
||||
fprintf(fp, " valid lock calls: %lu\n", rt->gcStats.lock);
|
||||
fprintf(fp, " valid unlock calls: %lu\n", rt->gcStats.unlock);
|
||||
fprintf(fp, " locks that hit stuck counts: %lu\n", rt->gcStats.stuck);
|
||||
fprintf(fp, " unlocks that saw stuck counts: %lu\n", rt->gcStats.unstuck);
|
||||
fprintf(fp, " mark recursion depth: %lu\n", rt->gcStats.depth);
|
||||
fprintf(fp, " maximum mark recursion depth: %lu\n", rt->gcStats.maxdepth);
|
||||
fprintf(fp, " maximum GC nesting level: %lu\n", rt->gcStats.maxlevel);
|
||||
fprintf(fp, " potentially useful GC calls: %lu\n", rt->gcStats.poke);
|
||||
fprintf(fp, " useless GC calls: %lu\n", rt->gcStats.nopoke);
|
||||
fprintf(fp, " thing arena corruption: %lu\n", rt->gcStats.badarena);
|
||||
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 JS_ARENAMETER
|
||||
JS_DumpArenaStats(fp);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
js_FinishGC(JSRuntime *rt)
|
||||
{
|
||||
#ifdef JS_ARENAMETER
|
||||
JS_DumpArenaStats(stdout);
|
||||
#endif
|
||||
#ifdef JS_GCMETER
|
||||
js_DumpGCStats(rt, stdout);
|
||||
#endif
|
||||
JS_FinishArenaPool(&rt->gcArenaPool);
|
||||
JS_FinishArenaPool(&rt->gcFlagsPool);
|
||||
JS_ArenaFinish();
|
||||
JS_HashTableDestroy(rt->gcRootsHash);
|
||||
rt->gcRootsHash = NULL;
|
||||
rt->gcFreeList = NULL;
|
||||
}
|
||||
|
||||
JSBool
|
||||
js_AddRoot(JSContext *cx, void *rp, const char *name)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
JSBool ok;
|
||||
|
||||
rt = cx->runtime;
|
||||
JS_LOCK_GC_VOID(rt,
|
||||
ok = (JS_HashTableAdd(rt->gcRootsHash, rp, (void *)name) != NULL));
|
||||
if (!ok)
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return ok;
|
||||
}
|
||||
|
||||
JSBool
|
||||
js_RemoveRoot(JSContext *cx, void *rp)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
|
||||
rt = cx->runtime;
|
||||
JS_LOCK_GC_VOID(rt, JS_HashTableRemove(rt->gcRootsHash, rp));
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
void *
|
||||
js_AllocGCThing(JSContext *cx, uintN flags)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
JSGCThing *thing;
|
||||
uint8 *flagp;
|
||||
#ifdef TOO_MUCH_GC
|
||||
JSBool tried_gc = JS_TRUE;
|
||||
js_GC(cx);
|
||||
#else
|
||||
JSBool tried_gc = JS_FALSE;
|
||||
#endif
|
||||
|
||||
rt = cx->runtime;
|
||||
JS_LOCK_GC(rt);
|
||||
METER(rt->gcStats.alloc++);
|
||||
retry:
|
||||
thing = rt->gcFreeList;
|
||||
if (thing) {
|
||||
rt->gcFreeList = thing->next;
|
||||
flagp = thing->flagp;
|
||||
METER(rt->gcStats.freelen--);
|
||||
METER(rt->gcStats.recycle++);
|
||||
} else {
|
||||
if (rt->gcBytes < rt->gcMaxBytes) {
|
||||
JS_ARENA_ALLOCATE(thing, &rt->gcArenaPool, sizeof(JSGCThing));
|
||||
JS_ARENA_ALLOCATE(flagp, &rt->gcFlagsPool, sizeof(uint8));
|
||||
}
|
||||
if (!thing || !flagp) {
|
||||
if (thing)
|
||||
JS_ARENA_RELEASE(&rt->gcArenaPool, thing);
|
||||
if (!tried_gc) {
|
||||
JS_UNLOCK_GC(rt);
|
||||
js_GC(cx);
|
||||
tried_gc = JS_TRUE;
|
||||
JS_LOCK_GC(rt);
|
||||
METER(rt->gcStats.retry++);
|
||||
goto retry;
|
||||
}
|
||||
METER(rt->gcStats.fail++);
|
||||
JS_UNLOCK_GC(rt);
|
||||
JS_ReportOutOfMemory(cx);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
*flagp = (uint8)flags;
|
||||
rt->gcBytes += sizeof(JSGCThing) + sizeof(uint8);
|
||||
cx->newborn[flags & GCF_TYPEMASK] = thing;
|
||||
|
||||
/*
|
||||
* Clear thing before unlocking in case a GC run is about to scan it,
|
||||
* finding it via cx->newborn[].
|
||||
*/
|
||||
thing->next = NULL;
|
||||
thing->flagp = NULL;
|
||||
JS_UNLOCK_GC(rt);
|
||||
return thing;
|
||||
}
|
||||
|
||||
static uint8 *
|
||||
gc_find_flags(JSRuntime *rt, void *thing)
|
||||
{
|
||||
jsuword index, offset, length;
|
||||
JSArena *a, *fa;
|
||||
|
||||
index = 0;
|
||||
for (a = rt->gcArenaPool.first.next; a; a = a->next) {
|
||||
offset = JS_UPTRDIFF(thing, a->base);
|
||||
length = a->avail - a->base;
|
||||
if (offset < length) {
|
||||
index += offset / sizeof(JSGCThing);
|
||||
for (fa = rt->gcFlagsPool.first.next; fa; fa = fa->next) {
|
||||
offset = fa->avail - fa->base;
|
||||
if (index < offset)
|
||||
return (uint8 *)fa->base + index;
|
||||
index -= offset;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
index += length / sizeof(JSGCThing);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JSBool
|
||||
js_LockGCThing(JSContext *cx, void *thing)
|
||||
{
|
||||
uint8 *flagp, flags;
|
||||
|
||||
if (!thing)
|
||||
return JS_TRUE;
|
||||
flagp = gc_find_flags(cx->runtime, thing);
|
||||
if (!flagp)
|
||||
return JS_FALSE;
|
||||
flags = *flagp;
|
||||
if ((flags & GCF_LOCKMASK) != GCF_LOCKMASK) {
|
||||
*flagp = (uint8)(flags + GCF_LOCK);
|
||||
} else {
|
||||
METER(cx->runtime->gcStats.stuck++);
|
||||
}
|
||||
METER(cx->runtime->gcStats.lock++);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool
|
||||
js_UnlockGCThing(JSContext *cx, void *thing)
|
||||
{
|
||||
uint8 *flagp, flags;
|
||||
|
||||
if (!thing)
|
||||
return JS_TRUE;
|
||||
flagp = gc_find_flags(cx->runtime, thing);
|
||||
if (!flagp)
|
||||
return JS_FALSE;
|
||||
flags = *flagp;
|
||||
if ((flags & GCF_LOCKMASK) != GCF_LOCKMASK) {
|
||||
*flagp = (uint8)(flags - GCF_LOCK);
|
||||
} else {
|
||||
METER(cx->runtime->gcStats.unstuck++);
|
||||
}
|
||||
METER(cx->runtime->gcStats.unlock++);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
#ifdef GC_MARK_DEBUG
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "jsprf.h"
|
||||
|
||||
JS_FRIEND_DATA(FILE *) js_DumpGCHeap;
|
||||
JS_FRIEND_DATA(void *) js_LiveThingToFind;
|
||||
|
||||
typedef struct GCMarkNode GCMarkNode;
|
||||
|
||||
struct GCMarkNode {
|
||||
void *thing;
|
||||
char *name;
|
||||
GCMarkNode *next;
|
||||
GCMarkNode *prev;
|
||||
};
|
||||
|
||||
static void
|
||||
gc_dump_thing(JSGCThing *thing, uint8 flags, GCMarkNode *prev, FILE *fp)
|
||||
{
|
||||
GCMarkNode *next = NULL;
|
||||
char *path = NULL;
|
||||
JSObject *obj;
|
||||
JSClass *clasp;
|
||||
|
||||
while (prev) {
|
||||
next = prev;
|
||||
prev = prev->prev;
|
||||
}
|
||||
while (next) {
|
||||
path = JS_sprintf_append(path, "%s.", next->name);
|
||||
next = next->next;
|
||||
}
|
||||
if (!path)
|
||||
return;
|
||||
|
||||
fprintf(fp, "%08lx ", (long)thing);
|
||||
switch (flags & GCF_TYPEMASK) {
|
||||
case GCX_OBJECT:
|
||||
obj = (JSObject *)thing;
|
||||
clasp = JSVAL_TO_PRIVATE(obj->slots[JSSLOT_CLASS]);
|
||||
fprintf(fp, "object %s", clasp->name);
|
||||
break;
|
||||
case GCX_STRING:
|
||||
fprintf(fp, "string %s", JS_GetStringBytes((JSString *)thing));
|
||||
break;
|
||||
case GCX_DOUBLE:
|
||||
fprintf(fp, "double %g", *(jsdouble *)thing);
|
||||
break;
|
||||
case GCX_DECIMAL:
|
||||
break;
|
||||
}
|
||||
fprintf(fp, " via %s\n", path);
|
||||
free(path);
|
||||
}
|
||||
|
||||
static void
|
||||
gc_mark_node(JSRuntime *rt, void *thing, GCMarkNode *prev);
|
||||
|
||||
#define GC_MARK(_rt, _thing, _name, _prev) \
|
||||
JS_BEGIN_MACRO \
|
||||
GCMarkNode _node; \
|
||||
_node.thing = _thing; \
|
||||
_node.name = _name; \
|
||||
_node.next = NULL; \
|
||||
_node.prev = _prev; \
|
||||
if (_prev) ((GCMarkNode *)(_prev))->next = &_node; \
|
||||
gc_mark_node(_rt, _thing, &_node); \
|
||||
JS_END_MACRO
|
||||
|
||||
static void
|
||||
gc_mark(JSRuntime *rt, void *thing)
|
||||
{
|
||||
GC_MARK(rt, thing, "atom", NULL);
|
||||
}
|
||||
|
||||
#define GC_MARK_ATOM(rt, atom, prev) gc_mark_atom(rt, atom, prev)
|
||||
#define GC_MARK_SCRIPT(rt, script, prev) gc_mark_script(rt, script, prev)
|
||||
|
||||
#else /* !GC_MARK_DEBUG */
|
||||
|
||||
#define GC_MARK(rt, thing, name, prev) gc_mark(rt, thing)
|
||||
#define GC_MARK_ATOM(rt, atom, prev) gc_mark_atom(rt, atom)
|
||||
#define GC_MARK_SCRIPT(rt, script, prev) gc_mark_script(rt, script)
|
||||
|
||||
static void
|
||||
gc_mark(JSRuntime *rt, void *thing);
|
||||
|
||||
#endif /* !GC_MARK_DEBUG */
|
||||
|
||||
static void
|
||||
gc_mark_atom(JSRuntime *rt, JSAtom *atom
|
||||
#ifdef GC_MARK_DEBUG
|
||||
, GCMarkNode *prev
|
||||
#endif
|
||||
)
|
||||
{
|
||||
jsval key;
|
||||
|
||||
if (!atom || atom->flags & ATOM_MARK)
|
||||
return;
|
||||
atom->flags |= ATOM_MARK;
|
||||
key = ATOM_KEY(atom);
|
||||
if (JSVAL_IS_GCTHING(key)) {
|
||||
#ifdef GC_MARK_DEBUG
|
||||
char name[32];
|
||||
|
||||
if (JSVAL_IS_STRING(key)) {
|
||||
JS_snprintf(name, sizeof name, "'%s'",
|
||||
JS_GetStringBytes(JSVAL_TO_STRING(key)));
|
||||
} else {
|
||||
JS_snprintf(name, sizeof name, "<%x>", key);
|
||||
}
|
||||
#endif
|
||||
GC_MARK(rt, JSVAL_TO_GCTHING(key), name, prev);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gc_mark_script(JSRuntime *rt, JSScript *script
|
||||
#ifdef GC_MARK_DEBUG
|
||||
, GCMarkNode *prev
|
||||
#endif
|
||||
)
|
||||
{
|
||||
JSAtomMap *map;
|
||||
uintN i, length;
|
||||
JSAtom **vector;
|
||||
|
||||
map = &script->atomMap;
|
||||
length = map->length;
|
||||
vector = map->vector;
|
||||
for (i = 0; i < length; i++)
|
||||
GC_MARK_ATOM(rt, vector[i], prev);
|
||||
}
|
||||
|
||||
static void
|
||||
#ifdef GC_MARK_DEBUG
|
||||
gc_mark_node(JSRuntime *rt, void *thing, GCMarkNode *prev)
|
||||
#else
|
||||
gc_mark(JSRuntime *rt, void *thing)
|
||||
#endif
|
||||
{
|
||||
uint8 flags, *flagp;
|
||||
JSObject *obj;
|
||||
jsval v, *vp, *end;
|
||||
JSScope *scope;
|
||||
JSClass *clasp;
|
||||
JSScript *script;
|
||||
JSFunction *fun;
|
||||
JSScopeProperty *sprop;
|
||||
JSSymbol *sym;
|
||||
|
||||
if (!thing)
|
||||
return;
|
||||
flagp = gc_find_flags(rt, thing);
|
||||
if (!flagp)
|
||||
return;
|
||||
|
||||
/* Check for something on the GC freelist to handle recycled stack. */
|
||||
flags = *flagp;
|
||||
if (flags == GCF_FINAL)
|
||||
return;
|
||||
|
||||
#ifdef GC_MARK_DEBUG
|
||||
if (js_LiveThingToFind == thing)
|
||||
gc_dump_thing(thing, flags, prev, stderr);
|
||||
#endif
|
||||
|
||||
if (flags & GCF_MARK)
|
||||
return;
|
||||
*flagp |= GCF_MARK;
|
||||
METER(if (++rt->gcStats.depth > rt->gcStats.maxdepth)
|
||||
rt->gcStats.maxdepth = rt->gcStats.depth);
|
||||
|
||||
#ifdef GC_MARK_DEBUG
|
||||
if (js_DumpGCHeap)
|
||||
gc_dump_thing(thing, flags, prev, js_DumpGCHeap);
|
||||
#endif
|
||||
|
||||
if ((flags & GCF_TYPEMASK) == GCX_OBJECT) {
|
||||
obj = thing;
|
||||
vp = obj->slots;
|
||||
if (vp) {
|
||||
scope = OBJ_IS_NATIVE(obj) ? (JSScope *) obj->map : NULL;
|
||||
if (scope) {
|
||||
clasp = JSVAL_TO_PRIVATE(obj->slots[JSSLOT_CLASS]);
|
||||
|
||||
if (clasp == &js_ScriptClass) {
|
||||
v = vp[JSSLOT_PRIVATE];
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
script = JSVAL_TO_PRIVATE(v);
|
||||
if (script)
|
||||
GC_MARK_SCRIPT(rt, script, prev);
|
||||
}
|
||||
}
|
||||
|
||||
if (clasp == &js_FunctionClass) {
|
||||
v = vp[JSSLOT_PRIVATE];
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
fun = JSVAL_TO_PRIVATE(v);
|
||||
if (fun) {
|
||||
if (fun->atom)
|
||||
GC_MARK_ATOM(rt, fun->atom, prev);
|
||||
if (fun->script)
|
||||
GC_MARK_SCRIPT(rt, fun->script, prev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (sprop = scope->props; sprop; sprop = sprop->next) {
|
||||
for (sym = sprop->symbols; sym; sym = sym->next) {
|
||||
if (JSVAL_IS_INT(sym_id(sym)))
|
||||
continue;
|
||||
GC_MARK_ATOM(rt, sym_atom(sym), prev);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!scope || scope->object == obj)
|
||||
end = vp + obj->map->freeslot;
|
||||
else
|
||||
end = vp + JS_INITIAL_NSLOTS;
|
||||
for (; vp < end; vp++) {
|
||||
v = *vp;
|
||||
if (JSVAL_IS_GCTHING(v)) {
|
||||
#ifdef GC_MARK_DEBUG
|
||||
char name[32];
|
||||
|
||||
if (scope) {
|
||||
uint32 slot;
|
||||
jsval nval;
|
||||
|
||||
slot = vp - obj->slots;
|
||||
for (sprop = scope->props; ; sprop = sprop->next) {
|
||||
if (!sprop) {
|
||||
switch (slot) {
|
||||
case JSSLOT_PROTO:
|
||||
strcpy(name, "__proto__");
|
||||
break;
|
||||
case JSSLOT_PARENT:
|
||||
strcpy(name, "__parent__");
|
||||
break;
|
||||
case JSSLOT_PRIVATE:
|
||||
strcpy(name, "__private__");
|
||||
break;
|
||||
default:
|
||||
JS_snprintf(name, sizeof name,
|
||||
"**UNKNOWN SLOT %ld**",
|
||||
(long)slot);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (sprop->slot == slot) {
|
||||
nval = sprop->symbols
|
||||
? js_IdToValue(sym_id(sprop->symbols))
|
||||
: sprop->id;
|
||||
if (JSVAL_IS_INT(nval)) {
|
||||
JS_snprintf(name, sizeof name, "%ld",
|
||||
(long)JSVAL_TO_INT(nval));
|
||||
} else if (JSVAL_IS_STRING(nval)) {
|
||||
JS_snprintf(name, sizeof name, "%s",
|
||||
JS_GetStringBytes(JSVAL_TO_STRING(nval)));
|
||||
} else {
|
||||
strcpy(name, "**FINALIZED ATOM KEY**");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
GC_MARK(rt, JSVAL_TO_GCTHING(v), name, prev);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
METER(rt->gcStats.depth--);
|
||||
}
|
||||
|
||||
static JSHashNumber
|
||||
gc_hash_root(const void *key)
|
||||
{
|
||||
JSHashNumber num = (JSHashNumber) key; /* help lame MSVC1.5 on Win16 */
|
||||
|
||||
return num >> 2;
|
||||
}
|
||||
|
||||
STATIC_DLL_CALLBACK(intN)
|
||||
gc_root_marker(JSHashEntry *he, intN i, void *arg)
|
||||
{
|
||||
void **rp = (void **)he->key;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
JS_FRIEND_API(void)
|
||||
js_ForceGC(JSContext *cx)
|
||||
{
|
||||
cx->newborn[GCX_OBJECT] = NULL;
|
||||
cx->newborn[GCX_STRING] = NULL;
|
||||
cx->newborn[GCX_DOUBLE] = NULL;
|
||||
cx->runtime->gcPoke = JS_TRUE;
|
||||
js_GC(cx);
|
||||
JS_ArenaFinish();
|
||||
}
|
||||
|
||||
void
|
||||
js_GC(JSContext *cx)
|
||||
{
|
||||
JSRuntime *rt;
|
||||
JSContext *iter, *acx;
|
||||
JSArena *a, *ma, *fa, **ap, **fap;
|
||||
jsval v, *vp, *sp;
|
||||
jsuword begin, end;
|
||||
JSStackFrame *fp, *chain;
|
||||
void *mark;
|
||||
uint8 flags, *flagp;
|
||||
JSGCThing *thing, *final, **flp, **oflp;
|
||||
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. */
|
||||
JS_ASSERT(!JS_IS_RUNTIME_LOCKED(rt));
|
||||
#endif
|
||||
|
||||
/* Let the API user decide to defer a GC if it wants to. */
|
||||
if (rt->gcCallback && !rt->gcCallback(cx, JSGC_BEGIN))
|
||||
return;
|
||||
|
||||
/* Lock out other GC allocator and collector invocations. */
|
||||
JS_LOCK_GC(rt);
|
||||
|
||||
/* Do nothing if no assignment has executed since the last GC. */
|
||||
if (!rt->gcPoke) {
|
||||
METER(rt->gcStats.nopoke++);
|
||||
JS_UNLOCK_GC(rt);
|
||||
return;
|
||||
}
|
||||
rt->gcPoke = JS_FALSE;
|
||||
METER(rt->gcStats.poke++);
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
/* Bump gcLevel and return rather than nest on this context. */
|
||||
if (cx->gcActive) {
|
||||
rt->gcLevel++;
|
||||
METER(if (rt->gcLevel > rt->gcStats.maxlevel)
|
||||
rt->gcStats.maxlevel = rt->gcLevel);
|
||||
if (rt->gcLevel > 1) {
|
||||
JS_UNLOCK_GC(rt);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we're in a request, indicate, temporarily, that we're inactive. */
|
||||
if (cx->requestDepth) {
|
||||
rt->requestCount--;
|
||||
JS_NOTIFY_REQUEST_DONE(rt);
|
||||
}
|
||||
|
||||
/* If another thread is already in GC, don't attempt GC; wait instead. */
|
||||
if (rt->gcLevel > 0) {
|
||||
while (rt->gcLevel > 0)
|
||||
JS_AWAIT_GC_DONE(rt);
|
||||
if (cx->requestDepth)
|
||||
rt->requestCount++;
|
||||
JS_UNLOCK_GC(rt);
|
||||
return;
|
||||
}
|
||||
|
||||
/* No other thread is in GC, so indicate that we're now in GC. */
|
||||
rt->gcLevel = 1;
|
||||
|
||||
/* Also indicate that GC is active on this context. */
|
||||
cx->gcActive = JS_TRUE;
|
||||
|
||||
/* Wait for all other requests to finish. */
|
||||
while (rt->requestCount > 0)
|
||||
JS_AWAIT_REQUEST_DONE(rt);
|
||||
|
||||
#else /* !JS_THREADSAFE */
|
||||
|
||||
/* Bump gcLevel and return rather than nest; the outer gc will restart. */
|
||||
rt->gcLevel++;
|
||||
METER(if (rt->gcLevel > rt->gcStats.maxlevel)
|
||||
rt->gcStats.maxlevel = rt->gcLevel);
|
||||
if (rt->gcLevel > 1)
|
||||
return;
|
||||
|
||||
#endif /* !JS_THREADSAFE */
|
||||
|
||||
/* Drop atoms held by the property cache, and clear property weak links. */
|
||||
js_FlushPropertyCache(cx);
|
||||
restart:
|
||||
rt->gcNumber++;
|
||||
|
||||
/* Mark phase. */
|
||||
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)
|
||||
*/
|
||||
chain = acx->fp;
|
||||
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 (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 == (jsuword)sp)
|
||||
break;
|
||||
}
|
||||
}
|
||||
do {
|
||||
GC_MARK(rt, fp->scopeChain, "scope chain", NULL);
|
||||
GC_MARK(rt, fp->thisp, "this", NULL);
|
||||
if (JSVAL_IS_GCTHING(fp->rval))
|
||||
GC_MARK(rt, JSVAL_TO_GCTHING(fp->rval), "rval", NULL);
|
||||
if (fp->callobj)
|
||||
GC_MARK(rt, fp->callobj, "call object", NULL);
|
||||
if (fp->argsobj)
|
||||
GC_MARK(rt, fp->argsobj, "arguments object", NULL);
|
||||
if (fp->script)
|
||||
GC_MARK_SCRIPT(rt, fp->script, NULL);
|
||||
if (fp->sharpArray)
|
||||
GC_MARK(rt, fp->sharpArray, "sharp array", NULL);
|
||||
} while ((fp = fp->down) != 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 = JS_ARENA_MARK(&cx->tempPool);
|
||||
js_SweepAtomState(&rt->atomState);
|
||||
fa = rt->gcFlagsPool.first.next;
|
||||
flagp = (uint8 *)fa->base;
|
||||
for (a = rt->gcArenaPool.first.next; a; a = a->next) {
|
||||
for (thing = (JSGCThing *)a->base; thing < (JSGCThing *)a->avail;
|
||||
thing++) {
|
||||
if (flagp >= (uint8 *)fa->avail) {
|
||||
fa = fa->next;
|
||||
JS_ASSERT(fa);
|
||||
if (!fa) {
|
||||
METER(rt->gcStats.badflag++);
|
||||
goto out;
|
||||
}
|
||||
flagp = (uint8 *)fa->base;
|
||||
}
|
||||
flags = *flagp;
|
||||
if (flags & GCF_MARK) {
|
||||
*flagp &= ~GCF_MARK;
|
||||
} else if (!(flags & (GCF_LOCKMASK | GCF_FINAL))) {
|
||||
JS_ARENA_ALLOCATE(final, &cx->tempPool, sizeof(JSGCThing));
|
||||
if (!final)
|
||||
goto out;
|
||||
final->next = thing;
|
||||
final->flagp = flagp;
|
||||
JS_ASSERT(rt->gcBytes >= sizeof(JSGCThing) + sizeof(uint8));
|
||||
rt->gcBytes -= sizeof(JSGCThing) + sizeof(uint8);
|
||||
}
|
||||
flagp++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Finalize phase. Don't hold the GC lock while running finalizers! */
|
||||
JS_UNLOCK_GC(rt);
|
||||
for (final = mark; ; final++) {
|
||||
if ((jsuword)final >= ma->avail) {
|
||||
ma = ma->next;
|
||||
if (!ma)
|
||||
break;
|
||||
final = (JSGCThing *)ma->base;
|
||||
}
|
||||
thing = final->next;
|
||||
flagp = final->flagp;
|
||||
flags = *flagp;
|
||||
finalizer = gc_finalizers[flags & GCF_TYPEMASK];
|
||||
if (finalizer) {
|
||||
*flagp |= GCF_FINAL;
|
||||
finalizer(cx, thing);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set flags to GCF_FINAL, signifying that thing is free, but don't
|
||||
* thread thing onto rt->gcFreeList. We need the GC lock to rebuild
|
||||
* the freelist below while also looking for free-able arenas.
|
||||
*/
|
||||
*flagp = GCF_FINAL;
|
||||
}
|
||||
JS_LOCK_GC(rt);
|
||||
|
||||
/* Free unused arenas and rebuild the freelist. */
|
||||
ap = &rt->gcArenaPool.first.next;
|
||||
a = *ap;
|
||||
if (!a)
|
||||
goto out;
|
||||
thing = (JSGCThing *)a->base;
|
||||
a_all_clear = f_all_clear = JS_TRUE;
|
||||
flp = oflp = &rt->gcFreeList;
|
||||
*flp = NULL;
|
||||
METER(rt->gcStats.freelen = 0);
|
||||
|
||||
fap = &rt->gcFlagsPool.first.next;
|
||||
while ((fa = *fap) != NULL) {
|
||||
/* XXX optimize by unrolling to use word loads */
|
||||
for (flagp = (uint8 *)fa->base; ; flagp++) {
|
||||
JS_ASSERT(a);
|
||||
if (!a) {
|
||||
METER(rt->gcStats.badarena++);
|
||||
goto out;
|
||||
}
|
||||
if (thing >= (JSGCThing *)a->avail) {
|
||||
if (a_all_clear) {
|
||||
JS_ARENA_DESTROY(&rt->gcArenaPool, a, ap);
|
||||
flp = oflp;
|
||||
METER(rt->gcStats.afree++);
|
||||
} else {
|
||||
ap = &a->next;
|
||||
a_all_clear = JS_TRUE;
|
||||
oflp = flp;
|
||||
}
|
||||
a = *ap;
|
||||
if (!a)
|
||||
break;
|
||||
thing = (JSGCThing *)a->base;
|
||||
}
|
||||
if (flagp >= (uint8 *)fa->avail)
|
||||
break;
|
||||
if (*flagp != GCF_FINAL) {
|
||||
a_all_clear = f_all_clear = JS_FALSE;
|
||||
} else {
|
||||
thing->flagp = flagp;
|
||||
*flp = thing;
|
||||
flp = &thing->next;
|
||||
METER(rt->gcStats.freelen++);
|
||||
}
|
||||
thing++;
|
||||
}
|
||||
if (f_all_clear) {
|
||||
JS_ARENA_DESTROY(&rt->gcFlagsPool, fa, fap);
|
||||
METER(rt->gcStats.fafree++);
|
||||
} else {
|
||||
fap = &fa->next;
|
||||
f_all_clear = JS_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Terminate the new freelist. */
|
||||
*flp = NULL;
|
||||
|
||||
out:
|
||||
JS_ARENA_RELEASE(&cx->tempPool, mark);
|
||||
if (rt->gcLevel > 1) {
|
||||
rt->gcLevel = 1;
|
||||
goto restart;
|
||||
}
|
||||
rt->gcLevel = 0;
|
||||
rt->gcLastBytes = rt->gcBytes;
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
/* If we were invoked during a request, undo the temporary decrement. */
|
||||
if (cx->requestDepth)
|
||||
rt->requestCount++;
|
||||
cx->gcActive = JS_FALSE;
|
||||
JS_NOTIFY_GC_DONE(rt);
|
||||
JS_UNLOCK_GC(rt);
|
||||
#endif
|
||||
if (rt->gcCallback)
|
||||
(void) rt->gcCallback(cx, JSGC_END);
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 jsgc_h___
|
||||
#define jsgc_h___
|
||||
/*
|
||||
* JS Garbage Collector.
|
||||
*/
|
||||
#include "jspubtd.h"
|
||||
|
||||
JS_BEGIN_EXTERN_C
|
||||
|
||||
/* GC thing type indexes. */
|
||||
#define GCX_OBJECT 0 /* JSObject */
|
||||
#define GCX_STRING 1 /* JSString */
|
||||
#define GCX_DOUBLE 2 /* jsdouble */
|
||||
#define GCX_DECIMAL 3 /* JSDecimal */
|
||||
#define GCX_NTYPES 4
|
||||
|
||||
/* GC flag definitions (type index goes in low bits). */
|
||||
#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 (JS_BITMASK(4) << GCF_LOCKBIT)
|
||||
#define GCF_LOCK JS_BIT(GCF_LOCKBIT) /* lock request bit in API */
|
||||
|
||||
#if 1
|
||||
/*
|
||||
* Since we're forcing a GC from JS_GC anyway, don't bother wasting cycles
|
||||
* loading oldval. XXX remove implied force, poke in addroot/removeroot, &c
|
||||
*/
|
||||
#define GC_POKE(cx, oldval) ((cx)->runtime->gcPoke = JS_TRUE)
|
||||
#else
|
||||
#define GC_POKE(cx, oldval) ((cx)->runtime->gcPoke = JSVAL_IS_GCTHING(oldval))
|
||||
#endif
|
||||
|
||||
extern JSBool
|
||||
js_InitGC(JSRuntime *rt, uint32 maxbytes);
|
||||
|
||||
extern void
|
||||
js_FinishGC(JSRuntime *rt);
|
||||
|
||||
extern JSBool
|
||||
js_AddRoot(JSContext *cx, void *rp, const char *name);
|
||||
|
||||
extern JSBool
|
||||
js_RemoveRoot(JSContext *cx, void *rp);
|
||||
|
||||
extern void *
|
||||
js_AllocGCThing(JSContext *cx, uintN flags);
|
||||
|
||||
extern JSBool
|
||||
js_LockGCThing(JSContext *cx, void *thing);
|
||||
|
||||
extern JSBool
|
||||
js_UnlockGCThing(JSContext *cx, void *thing);
|
||||
|
||||
extern JS_FRIEND_API(void)
|
||||
js_ForceGC(JSContext *cx);
|
||||
|
||||
extern void
|
||||
js_GC(JSContext *cx);
|
||||
|
||||
#ifdef JS_GCMETER
|
||||
|
||||
typedef struct JSGCStats {
|
||||
uint32 alloc; /* number of allocation attempts */
|
||||
uint32 freelen; /* gcFreeList length */
|
||||
uint32 recycle; /* number of things recycled through gcFreeList */
|
||||
uint32 retry; /* allocation attempt retries after running the GC */
|
||||
uint32 fail; /* allocation failures */
|
||||
uint32 lock; /* valid lock calls */
|
||||
uint32 unlock; /* valid unlock calls */
|
||||
uint32 stuck; /* stuck reference counts seen by lock calls */
|
||||
uint32 unstuck; /* unlock calls that saw a stuck lock count */
|
||||
uint32 depth; /* mark recursion depth */
|
||||
uint32 maxdepth; /* maximum mark recursion depth */
|
||||
uint32 maxlevel; /* maximum GC nesting (indirect recursion) level */
|
||||
uint32 poke; /* number of potentially useful GC calls */
|
||||
uint32 nopoke; /* useless GC calls where js_PokeGC was not set */
|
||||
uint32 badarena; /* thing arena corruption */
|
||||
uint32 badflag; /* flags arena corruption */
|
||||
uint32 afree; /* thing arenas freed so far */
|
||||
uint32 fafree; /* flags arenas freed so far */
|
||||
} JSGCStats;
|
||||
|
||||
extern void
|
||||
js_DumpGCStats(JSRuntime *rt, FILE *fp);
|
||||
|
||||
#endif /* JS_GCMETER */
|
||||
|
||||
JS_END_EXTERN_C
|
||||
|
||||
#endif /* jsgc_h___ */
|
||||
@@ -1,457 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 hash table package.
|
||||
*/
|
||||
#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) JS_BIT(PR_HASH_BITS - (ht)->shift)
|
||||
|
||||
/* The smallest table has 16 buckets */
|
||||
#define MINBUCKETSLOG2 4
|
||||
#define MINBUCKETS JS_BIT(MINBUCKETSLOG2)
|
||||
|
||||
/* Compute the maximum entries given n buckets that we will tolerate, ~90% */
|
||||
#define OVERLOADED(n) ((n) - ((n) >> 3))
|
||||
|
||||
/* Compute the number of entries below which we shrink the table by half */
|
||||
#define UNDERLOADED(n) (((n) > MINBUCKETS) ? ((n) >> 2) : 0)
|
||||
|
||||
/*
|
||||
** Stubs for default hash allocator ops.
|
||||
*/
|
||||
static void *
|
||||
DefaultAllocTable(void *pool, size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
static void
|
||||
DefaultFreeTable(void *pool, void *item)
|
||||
{
|
||||
free(item);
|
||||
}
|
||||
|
||||
static JSHashEntry *
|
||||
DefaultAllocEntry(void *pool, const void *key)
|
||||
{
|
||||
return malloc(sizeof(JSHashEntry));
|
||||
}
|
||||
|
||||
static void
|
||||
DefaultFreeEntry(void *pool, JSHashEntry *he, uintN flag)
|
||||
{
|
||||
if (flag == HT_FREE_ENTRY)
|
||||
free(he);
|
||||
}
|
||||
|
||||
static JSHashAllocOps defaultHashAllocOps = {
|
||||
DefaultAllocTable, DefaultFreeTable,
|
||||
DefaultAllocEntry, DefaultFreeEntry
|
||||
};
|
||||
|
||||
IMPLEMENT(JSHashTable *)
|
||||
JS_NewHashTable(uint32 n, JSHashFunction keyHash,
|
||||
JSHashComparator keyCompare, JSHashComparator valueCompare,
|
||||
JSHashAllocOps *allocOps, void *allocPriv)
|
||||
{
|
||||
JSHashTable *ht;
|
||||
size_t nb;
|
||||
|
||||
if (n <= MINBUCKETS) {
|
||||
n = MINBUCKETSLOG2;
|
||||
} else {
|
||||
n = JS_CeilingLog2(n);
|
||||
if ((int32)n < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!allocOps) allocOps = &defaultHashAllocOps;
|
||||
|
||||
ht = (*allocOps->allocTable)(allocPriv, sizeof *ht);
|
||||
if (!ht)
|
||||
return NULL;
|
||||
memset(ht, 0, sizeof *ht);
|
||||
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 NULL;
|
||||
}
|
||||
#endif /* WIN16 */
|
||||
nb = n * sizeof(JSHashEntry *);
|
||||
ht->buckets = (*allocOps->allocTable)(allocPriv, nb);
|
||||
if (!ht->buckets) {
|
||||
(*allocOps->freeTable)(allocPriv, ht);
|
||||
return NULL;
|
||||
}
|
||||
memset(ht->buckets, 0, nb);
|
||||
|
||||
ht->keyHash = keyHash;
|
||||
ht->keyCompare = keyCompare;
|
||||
ht->valueCompare = valueCompare;
|
||||
ht->allocOps = allocOps;
|
||||
ht->allocPriv = allocPriv;
|
||||
return ht;
|
||||
}
|
||||
|
||||
IMPLEMENT(void)
|
||||
JS_HashTableDestroy(JSHashTable *ht)
|
||||
{
|
||||
uint32 i, n;
|
||||
JSHashEntry *he, *next;
|
||||
JSHashAllocOps *allocOps = ht->allocOps;
|
||||
void *allocPriv = ht->allocPriv;
|
||||
|
||||
n = NBUCKETS(ht);
|
||||
for (i = 0; i < n; i++) {
|
||||
for (he = ht->buckets[i]; he; he = next) {
|
||||
next = he->next;
|
||||
(*allocOps->freeEntry)(allocPriv, he, HT_FREE_ENTRY);
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
memset(ht->buckets, 0xDB, n * sizeof ht->buckets[0]);
|
||||
#endif
|
||||
(*allocOps->freeTable)(allocPriv, ht->buckets);
|
||||
#ifdef DEBUG
|
||||
memset(ht, 0xDB, sizeof *ht);
|
||||
#endif
|
||||
(*allocOps->freeTable)(allocPriv, ht);
|
||||
}
|
||||
|
||||
/*
|
||||
** Multiplicative hash, from Knuth 6.4.
|
||||
*/
|
||||
IMPLEMENT(JSHashEntry **)
|
||||
JS_HashTableRawLookup(JSHashTable *ht, JSHashNumber keyHash, const void *key)
|
||||
{
|
||||
JSHashEntry *he, **hep, **hep0;
|
||||
JSHashNumber h;
|
||||
|
||||
#ifdef HASHMETER
|
||||
ht->nlookups++;
|
||||
#endif
|
||||
h = keyHash * PR_GOLDEN_RATIO;
|
||||
h >>= ht->shift;
|
||||
hep = hep0 = &ht->buckets[h];
|
||||
while ((he = *hep) != NULL) {
|
||||
if (he->keyHash == keyHash && (*ht->keyCompare)(key, he->key)) {
|
||||
/* Move to front of chain if not already there */
|
||||
if (hep != hep0) {
|
||||
*hep = he->next;
|
||||
he->next = *hep0;
|
||||
*hep0 = he;
|
||||
}
|
||||
return hep0;
|
||||
}
|
||||
hep = &he->next;
|
||||
#ifdef HASHMETER
|
||||
ht->nsteps++;
|
||||
#endif
|
||||
}
|
||||
return hep;
|
||||
}
|
||||
|
||||
IMPLEMENT(JSHashEntry *)
|
||||
JS_HashTableRawAdd(JSHashTable *ht, JSHashEntry **hep,
|
||||
JSHashNumber keyHash, const void *key, void *value)
|
||||
{
|
||||
uint32 i, n;
|
||||
JSHashEntry *he, *next, **oldbuckets;
|
||||
size_t nb;
|
||||
|
||||
/* Grow the table if it is overloaded */
|
||||
n = NBUCKETS(ht);
|
||||
if (ht->nentries >= OVERLOADED(n)) {
|
||||
#ifdef HASHMETER
|
||||
ht->ngrows++;
|
||||
#endif
|
||||
ht->shift--;
|
||||
oldbuckets = ht->buckets;
|
||||
#if defined(XP_PC) && defined _MSC_VER && _MSC_VER <= 800
|
||||
if (2 * n > 16000)
|
||||
return NULL;
|
||||
#endif /* WIN16 */
|
||||
nb = 2 * n * sizeof(JSHashEntry *);
|
||||
ht->buckets = (*ht->allocOps->allocTable)(ht->allocPriv, nb);
|
||||
if (!ht->buckets) {
|
||||
ht->buckets = oldbuckets;
|
||||
return NULL;
|
||||
}
|
||||
memset(ht->buckets, 0, nb);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (he = oldbuckets[i]; he; he = next) {
|
||||
next = he->next;
|
||||
hep = JS_HashTableRawLookup(ht, he->keyHash, he->key);
|
||||
JS_ASSERT(*hep == NULL);
|
||||
he->next = NULL;
|
||||
*hep = he;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
memset(oldbuckets, 0xDB, n * sizeof oldbuckets[0]);
|
||||
#endif
|
||||
(*ht->allocOps->freeTable)(ht->allocPriv, oldbuckets);
|
||||
hep = JS_HashTableRawLookup(ht, keyHash, key);
|
||||
}
|
||||
|
||||
/* Make a new key value entry */
|
||||
he = (*ht->allocOps->allocEntry)(ht->allocPriv, key);
|
||||
if (!he)
|
||||
return NULL;
|
||||
he->keyHash = keyHash;
|
||||
he->key = key;
|
||||
he->value = value;
|
||||
he->next = *hep;
|
||||
*hep = he;
|
||||
ht->nentries++;
|
||||
return he;
|
||||
}
|
||||
|
||||
IMPLEMENT(JSHashEntry *)
|
||||
JS_HashTableAdd(JSHashTable *ht, const void *key, void *value)
|
||||
{
|
||||
JSHashNumber keyHash;
|
||||
JSHashEntry *he, **hep;
|
||||
|
||||
keyHash = (*ht->keyHash)(key);
|
||||
hep = JS_HashTableRawLookup(ht, keyHash, key);
|
||||
if ((he = *hep) != NULL) {
|
||||
/* Hit; see if values match */
|
||||
if ((*ht->valueCompare)(he->value, value)) {
|
||||
/* key,value pair is already present in table */
|
||||
return he;
|
||||
}
|
||||
if (he->value)
|
||||
(*ht->allocOps->freeEntry)(ht->allocPriv, he, HT_FREE_VALUE);
|
||||
he->value = value;
|
||||
return he;
|
||||
}
|
||||
return JS_HashTableRawAdd(ht, hep, keyHash, key, value);
|
||||
}
|
||||
|
||||
IMPLEMENT(void)
|
||||
JS_HashTableRawRemove(JSHashTable *ht, JSHashEntry **hep, JSHashEntry *he)
|
||||
{
|
||||
uint32 i, n;
|
||||
JSHashEntry *next, **oldbuckets;
|
||||
size_t nb;
|
||||
|
||||
*hep = he->next;
|
||||
(*ht->allocOps->freeEntry)(ht->allocPriv, he, HT_FREE_ENTRY);
|
||||
|
||||
/* Shrink table if it's underloaded */
|
||||
n = NBUCKETS(ht);
|
||||
if (--ht->nentries < UNDERLOADED(n)) {
|
||||
#ifdef HASHMETER
|
||||
ht->nshrinks++;
|
||||
#endif
|
||||
ht->shift++;
|
||||
oldbuckets = ht->buckets;
|
||||
nb = n * sizeof(JSHashEntry*) / 2;
|
||||
ht->buckets = (*ht->allocOps->allocTable)(ht->allocPriv, nb);
|
||||
if (!ht->buckets) {
|
||||
ht->buckets = oldbuckets;
|
||||
return;
|
||||
}
|
||||
memset(ht->buckets, 0, nb);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for (he = oldbuckets[i]; he; he = next) {
|
||||
next = he->next;
|
||||
hep = JS_HashTableRawLookup(ht, he->keyHash, he->key);
|
||||
JS_ASSERT(*hep == NULL);
|
||||
he->next = NULL;
|
||||
*hep = he;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
memset(oldbuckets, 0xDB, n * sizeof oldbuckets[0]);
|
||||
#endif
|
||||
(*ht->allocOps->freeTable)(ht->allocPriv, oldbuckets);
|
||||
}
|
||||
}
|
||||
|
||||
IMPLEMENT(JSBool)
|
||||
JS_HashTableRemove(JSHashTable *ht, const void *key)
|
||||
{
|
||||
JSHashNumber keyHash;
|
||||
JSHashEntry *he, **hep;
|
||||
|
||||
keyHash = (*ht->keyHash)(key);
|
||||
hep = JS_HashTableRawLookup(ht, keyHash, key);
|
||||
if ((he = *hep) == NULL)
|
||||
return JS_FALSE;
|
||||
|
||||
/* Hit; remove element */
|
||||
JS_HashTableRawRemove(ht, hep, he);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
IMPLEMENT(void *)
|
||||
JS_HashTableLookup(JSHashTable *ht, const void *key)
|
||||
{
|
||||
JSHashNumber keyHash;
|
||||
JSHashEntry *he, **hep;
|
||||
|
||||
keyHash = (*ht->keyHash)(key);
|
||||
hep = JS_HashTableRawLookup(ht, keyHash, key);
|
||||
if ((he = *hep) != NULL) {
|
||||
return he->value;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
** Iterate over the entries in the hash table calling func for each
|
||||
** entry found. Stop if "f" says to (return value & JS_ENUMERATE_STOP).
|
||||
** Return a count of the number of elements scanned.
|
||||
*/
|
||||
IMPLEMENT(int)
|
||||
JS_HashTableEnumerateEntries(JSHashTable *ht, JSHashEnumerator f, void *arg)
|
||||
{
|
||||
JSHashEntry *he, **hep;
|
||||
uint32 i, nbuckets;
|
||||
int rv, n = 0;
|
||||
JSHashEntry *todo = NULL;
|
||||
|
||||
nbuckets = NBUCKETS(ht);
|
||||
for (i = 0; i < nbuckets; i++) {
|
||||
hep = &ht->buckets[i];
|
||||
while ((he = *hep) != NULL) {
|
||||
rv = (*f)(he, n, arg);
|
||||
n++;
|
||||
if (rv & (HT_ENUMERATE_REMOVE | HT_ENUMERATE_UNHASH)) {
|
||||
*hep = he->next;
|
||||
if (rv & HT_ENUMERATE_REMOVE) {
|
||||
he->next = todo;
|
||||
todo = he;
|
||||
}
|
||||
} else {
|
||||
hep = &he->next;
|
||||
}
|
||||
if (rv & HT_ENUMERATE_STOP) {
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
hep = &todo;
|
||||
while ((he = *hep) != NULL) {
|
||||
JS_HashTableRawRemove(ht, hep, he);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
#ifdef HASHMETER
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
IMPLEMENT(void)
|
||||
JS_HashTableDumpMeter(JSHashTable *ht, JSHashEnumerator dump, FILE *fp)
|
||||
{
|
||||
double mean, variance;
|
||||
uint32 nchains, nbuckets;
|
||||
uint32 i, n, maxChain, maxChainLen;
|
||||
JSHashEntry *he;
|
||||
|
||||
variance = 0;
|
||||
nchains = 0;
|
||||
maxChainLen = 0;
|
||||
nbuckets = NBUCKETS(ht);
|
||||
for (i = 0; i < nbuckets; i++) {
|
||||
he = ht->buckets[i];
|
||||
if (!he)
|
||||
continue;
|
||||
nchains++;
|
||||
for (n = 0; he; he = he->next)
|
||||
n++;
|
||||
variance += n * n;
|
||||
if (n > maxChainLen) {
|
||||
maxChainLen = n;
|
||||
maxChain = i;
|
||||
}
|
||||
}
|
||||
mean = (double)ht->nentries / nchains;
|
||||
variance = fabs(variance / nchains - mean * mean);
|
||||
|
||||
fprintf(fp, "\nHash table statistics:\n");
|
||||
fprintf(fp, " number of lookups: %u\n", ht->nlookups);
|
||||
fprintf(fp, " number of entries: %u\n", ht->nentries);
|
||||
fprintf(fp, " number of grows: %u\n", ht->ngrows);
|
||||
fprintf(fp, " number of shrinks: %u\n", ht->nshrinks);
|
||||
fprintf(fp, " mean steps per hash: %g\n", (double)ht->nsteps
|
||||
/ ht->nlookups);
|
||||
fprintf(fp, "mean hash chain length: %g\n", mean);
|
||||
fprintf(fp, " standard deviation: %g\n", sqrt(variance));
|
||||
fprintf(fp, " max hash chain length: %u\n", maxChainLen);
|
||||
fprintf(fp, " max hash chain: [%u]\n", maxChain);
|
||||
|
||||
for (he = ht->buckets[maxChain], i = 0; he; he = he->next, i++)
|
||||
if ((*dump)(he, i, fp) != HT_ENUMERATE_NEXT)
|
||||
break;
|
||||
}
|
||||
#endif /* HASHMETER */
|
||||
|
||||
IMPLEMENT(int)
|
||||
JS_HashTableDump(JSHashTable *ht, JSHashEnumerator dump, FILE *fp)
|
||||
{
|
||||
int count;
|
||||
|
||||
count = JS_HashTableEnumerateEntries(ht, dump, fp);
|
||||
#ifdef HASHMETER
|
||||
JS_HashTableDumpMeter(ht, dump, fp);
|
||||
#endif
|
||||
return count;
|
||||
}
|
||||
|
||||
IMPLEMENT(JSHashNumber)
|
||||
JS_HashString(const void *key)
|
||||
{
|
||||
JSHashNumber h;
|
||||
const unsigned char *s;
|
||||
|
||||
h = 0;
|
||||
for (s = key; *s; s++)
|
||||
h = (h >> 28) ^ (h << 4) ^ *s;
|
||||
return h;
|
||||
}
|
||||
|
||||
IMPLEMENT(int)
|
||||
JS_CompareValues(const void *v1, const void *v2)
|
||||
{
|
||||
return v1 == v2;
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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___ */
|
||||
@@ -1,482 +0,0 @@
|
||||
#!/usr/local/bin/perl
|
||||
|
||||
# This script modifies C code to use the hijacked NSPR routines that are
|
||||
# now baked into the JavaScript engine rather than using the NSPR
|
||||
# routines that they were based on, i.e. types like PRArenaPool are changed
|
||||
# to JSArenaPool.
|
||||
#
|
||||
# This script was used in 9/98 to facilitate the incorporation of some NSPR
|
||||
# code into the JS engine so as to minimize dependency on NSPR.
|
||||
#
|
||||
|
||||
# Command-line: jsify.pl [options] [filename]*
|
||||
#
|
||||
# Options:
|
||||
# -r Reverse direction of transformation, i.e. JS ==> NSPR2
|
||||
# -outdir Directory in which to place output files
|
||||
|
||||
|
||||
# NSPR2 symbols that will be modified to JS symbols, e.g.
|
||||
# PRArena <==> JSArena
|
||||
|
||||
@NSPR_symbols = (
|
||||
"PRArena",
|
||||
"PRArenaPool",
|
||||
"PRArenaStats",
|
||||
"PR_ARENAMETER",
|
||||
"PR_ARENA_",
|
||||
"PR_ARENA_ALIGN",
|
||||
"PR_ARENA_ALLOCATE",
|
||||
"PR_ARENA_CONST_ALIGN_MASK",
|
||||
"PR_ARENA_DEFAULT_ALIGN",
|
||||
"PR_ARENA_DESTROY",
|
||||
"PR_ARENA_GROW",
|
||||
"PR_ARENA_MARK",
|
||||
"PR_ARENA_RELEASE",
|
||||
|
||||
"PR_smprintf",
|
||||
"PR_smprintf_free",
|
||||
"PR_snprintf",
|
||||
"PR_sprintf_append",
|
||||
"PR_sscanf",
|
||||
"PR_sxprintf",
|
||||
"PR_vsmprintf",
|
||||
"PR_vsnprintf",
|
||||
"PR_vsprintf_append",
|
||||
"PR_vsxprintf",
|
||||
|
||||
"PRCList",
|
||||
"PRCListStr",
|
||||
"PRCLists",
|
||||
|
||||
"PRDestroyEventProc",
|
||||
"PREvent",
|
||||
"PREventFunProc",
|
||||
"PREventQueue",
|
||||
"PRHandleEventProc",
|
||||
"PR_PostEvent",
|
||||
"PR_PostSynchronousEvent",
|
||||
"PR_ProcessPendingEvents",
|
||||
"PR_CreateEventQueue",
|
||||
"PR_DequeueEvent",
|
||||
"PR_DestroyEvent",
|
||||
"PR_DestroyEventQueue",
|
||||
"PR_EventAvailable",
|
||||
"PR_EventLoop",
|
||||
"PR_GetEvent",
|
||||
"PR_GetEventOwner",
|
||||
"PR_GetEventQueueMonitor",
|
||||
"PR_GetEventQueueSelectFD",
|
||||
"PR_GetMainEventQueue",
|
||||
"PR_HandleEvent",
|
||||
"PR_InitEvent",
|
||||
"PR_ENTER_EVENT_QUEUE_MONITOR",
|
||||
"PR_EXIT_EVENT_QUEUE_MONITOR",
|
||||
"PR_MapEvents",
|
||||
"PR_RevokeEvents",
|
||||
|
||||
"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
@@ -1,209 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 jsinterp_h___
|
||||
#define jsinterp_h___
|
||||
/*
|
||||
* JS interpreter interface.
|
||||
*/
|
||||
#include "jsprvtd.h"
|
||||
#include "jspubtd.h"
|
||||
|
||||
/*
|
||||
* JS stack frame, allocated on the C stack.
|
||||
*/
|
||||
struct JSStackFrame {
|
||||
JSObject *callobj; /* lazily created Call object */
|
||||
JSObject *argsobj; /* lazily created arguments object */
|
||||
JSScript *script; /* script being interpreted */
|
||||
JSFunction *fun; /* function being called or null */
|
||||
JSObject *thisp; /* "this" pointer if in method */
|
||||
uintN argc; /* actual argument count */
|
||||
jsval *argv; /* base of argument stack slots */
|
||||
jsval rval; /* function return value */
|
||||
uintN nvars; /* local variable count */
|
||||
jsval *vars; /* base of variable stack slots */
|
||||
JSStackFrame *down; /* previous frame */
|
||||
void *annotation; /* used by Java security */
|
||||
JSObject *scopeChain; /* scope chain */
|
||||
jsbytecode *pc; /* program counter */
|
||||
jsval *sp; /* stack pointer */
|
||||
uintN sharpDepth; /* array/object initializer depth */
|
||||
JSObject *sharpArray; /* scope for #n= initializer vars */
|
||||
JSPackedBool constructing; /* true if called via new operator */
|
||||
uint8 overrides; /* bit-set of overridden Call properties */
|
||||
JSPackedBool debugging; /* true if for JS_EvaluateInStackFrame */
|
||||
JSStackFrame *dormantNext; /* next dormant frame chain */
|
||||
};
|
||||
|
||||
/*
|
||||
* Property cache for quickened get/set property opcodes.
|
||||
*/
|
||||
#define PROPERTY_CACHE_LOG2 10
|
||||
#define PROPERTY_CACHE_SIZE JS_BIT(PROPERTY_CACHE_LOG2)
|
||||
#define PROPERTY_CACHE_MASK JS_BITMASK(PROPERTY_CACHE_LOG2)
|
||||
|
||||
#define PROPERTY_CACHE_HASH(obj, id) \
|
||||
((((jsuword)(obj) >> JSVAL_TAGBITS) ^ (jsuword)(id)) & PROPERTY_CACHE_MASK)
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
|
||||
#if HAVE_ATOMIC_DWORD_ACCESS
|
||||
|
||||
#define PCE_LOAD(cache, pce, entry) JS_ATOMIC_DWORD_LOAD(pce, entry)
|
||||
#define PCE_STORE(cache, pce, entry) JS_ATOMIC_DWORD_STORE(pce, entry)
|
||||
|
||||
#else /* !HAVE_ATOMIC_DWORD_ACCESS */
|
||||
|
||||
#define PCE_LOAD(cache, pce, entry) \
|
||||
JS_BEGIN_MACRO \
|
||||
uint32 _prefills; \
|
||||
uint32 _fills = (cache)->fills; \
|
||||
do { \
|
||||
/* Load until cache->fills is stable (see FILL macro below). */ \
|
||||
_prefills = _fills; \
|
||||
(entry) = *(pce); \
|
||||
} while ((_fills = (cache)->fills) != _prefills); \
|
||||
JS_END_MACRO
|
||||
|
||||
#define PCE_STORE(cache, pce, entry) \
|
||||
JS_BEGIN_MACRO \
|
||||
do { \
|
||||
/* Store until no racing collider stores half or all of pce. */ \
|
||||
*(pce) = (entry); \
|
||||
} while (PCE_OBJECT(*pce) != PCE_OBJECT(entry) || \
|
||||
PCE_PROPERTY(*pce) != PCE_PROPERTY(entry)); \
|
||||
JS_END_MACRO
|
||||
|
||||
#endif /* !HAVE_ATOMIC_DWORD_ACCESS */
|
||||
|
||||
#else /* !JS_THREADSAFE */
|
||||
|
||||
#define PCE_LOAD(cache, pce, entry) ((entry) = *(pce))
|
||||
#define PCE_STORE(cache, pce, entry) (*(pce) = (entry))
|
||||
|
||||
#endif /* !JS_THREADSAFE */
|
||||
|
||||
typedef union JSPropertyCacheEntry {
|
||||
struct {
|
||||
JSObject *object; /* weak link to object */
|
||||
JSProperty *property; /* weak link to property, or not-found id */
|
||||
} s;
|
||||
#ifdef HAVE_ATOMIC_DWORD_ACCESS
|
||||
prdword align;
|
||||
#endif
|
||||
} JSPropertyCacheEntry;
|
||||
|
||||
/* These may be called in lvalue or rvalue position. */
|
||||
#define PCE_OBJECT(entry) ((entry).s.object)
|
||||
#define PCE_PROPERTY(entry) ((entry).s.property)
|
||||
|
||||
typedef struct JSPropertyCache {
|
||||
JSPropertyCacheEntry table[PROPERTY_CACHE_SIZE];
|
||||
JSBool empty;
|
||||
uint32 fills;
|
||||
uint32 recycles;
|
||||
uint32 tests;
|
||||
uint32 misses;
|
||||
uint32 flushes;
|
||||
} JSPropertyCache;
|
||||
|
||||
/* Property-not-found lookup results are cached using this invalid pointer. */
|
||||
#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) \
|
||||
JS_BEGIN_MACRO \
|
||||
uintN _hashIndex = (uintN)PROPERTY_CACHE_HASH(obj, id); \
|
||||
JSPropertyCache *_cache = (cache); \
|
||||
JSPropertyCacheEntry *_pce = &_cache->table[_hashIndex]; \
|
||||
JSPropertyCacheEntry _entry; \
|
||||
JSProperty *_pce_prop; \
|
||||
PCE_LOAD(_cache, _pce, _entry); \
|
||||
_pce_prop = PCE_PROPERTY(_entry); \
|
||||
if (_pce_prop && _pce_prop != prop) \
|
||||
_cache->recycles++; \
|
||||
PCE_OBJECT(_entry) = obj; \
|
||||
PCE_PROPERTY(_entry) = prop; \
|
||||
_cache->empty = JS_FALSE; \
|
||||
_cache->fills++; \
|
||||
PCE_STORE(_cache, _pce, _entry); \
|
||||
JS_END_MACRO
|
||||
|
||||
#define PROPERTY_CACHE_TEST(cache, obj, id, prop) \
|
||||
JS_BEGIN_MACRO \
|
||||
uintN _hashIndex = (uintN)PROPERTY_CACHE_HASH(obj, id); \
|
||||
JSPropertyCache *_cache = (cache); \
|
||||
JSPropertyCacheEntry *_pce = &_cache->table[_hashIndex]; \
|
||||
JSPropertyCacheEntry _entry; \
|
||||
JSProperty *_pce_prop; \
|
||||
PCE_LOAD(_cache, _pce, _entry); \
|
||||
_pce_prop = PCE_PROPERTY(_entry); \
|
||||
_cache->tests++; \
|
||||
if (_pce_prop && \
|
||||
(((jsword)_pce_prop & 1) \
|
||||
? PROP_NOT_FOUND_ID(_pce_prop) \
|
||||
: sym_id(((JSScopeProperty *)_pce_prop)->symbols)) == id && \
|
||||
PCE_OBJECT(_entry) == obj) { \
|
||||
prop = _pce_prop; \
|
||||
} else { \
|
||||
_cache->misses++; \
|
||||
prop = NULL; \
|
||||
} \
|
||||
JS_END_MACRO
|
||||
|
||||
extern void
|
||||
js_FlushPropertyCache(JSContext *cx);
|
||||
|
||||
extern void
|
||||
js_FlushPropertyCacheByProp(JSContext *cx, JSProperty *prop);
|
||||
|
||||
extern jsval *
|
||||
js_AllocStack(JSContext *cx, uintN nslots, void **markp);
|
||||
|
||||
extern void
|
||||
js_FreeStack(JSContext *cx, void *mark);
|
||||
|
||||
extern JSBool
|
||||
js_GetArgument(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
|
||||
|
||||
extern JSBool
|
||||
js_SetArgument(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
|
||||
|
||||
extern JSBool
|
||||
js_GetLocalVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
|
||||
|
||||
extern JSBool
|
||||
js_SetLocalVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
|
||||
|
||||
extern JSBool
|
||||
js_Invoke(JSContext *cx, uintN argc, JSBool constructing);
|
||||
|
||||
extern JSBool
|
||||
js_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval,
|
||||
uintN argc, jsval *argv, jsval *rval);
|
||||
|
||||
extern JSBool
|
||||
js_Execute(JSContext *cx, JSObject *chain, JSScript *script, JSFunction *fun,
|
||||
JSStackFrame *down, JSBool debugging, jsval *result);
|
||||
|
||||
extern JSBool
|
||||
js_Interpret(JSContext *cx, jsval *result);
|
||||
|
||||
#endif /* jsinterp_h___ */
|
||||
@@ -1,782 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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.
|
||||
*/
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
|
||||
/*
|
||||
* JS locking stubs.
|
||||
*/
|
||||
#include "jsstddef.h"
|
||||
#include <stdlib.h>
|
||||
#include "jspubtd.h"
|
||||
#include "prthread.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"
|
||||
#include "jslock.h"
|
||||
|
||||
static PRLock *_global_lock;
|
||||
|
||||
static void
|
||||
js_LockGlobal()
|
||||
{
|
||||
PR_Lock(_global_lock);
|
||||
}
|
||||
|
||||
static void
|
||||
js_UnlockGlobal()
|
||||
{
|
||||
PR_Unlock(_global_lock);
|
||||
}
|
||||
|
||||
#define ReadWord(W) (W)
|
||||
#define AtomicAddBody(P,I)\
|
||||
jsword n;\
|
||||
do {\
|
||||
n = ReadWord(*(P));\
|
||||
} while (!js_CompareAndSwap(P, n, n + I));
|
||||
|
||||
#if defined(_WIN32) && !defined(NSPR_LOCK)
|
||||
#pragma warning( disable : 4035 )
|
||||
|
||||
JS_INLINE int
|
||||
js_CompareAndSwap(jsword *w, jsword ov, jsword nv)
|
||||
{
|
||||
__asm {
|
||||
mov eax,ov
|
||||
mov ecx, nv
|
||||
mov ebx, w
|
||||
lock cmpxchg [ebx], ecx
|
||||
sete al
|
||||
and eax,1h
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(SOLARIS) && !defined(NSPR_LOCK)
|
||||
|
||||
#ifndef ULTRA_SPARC
|
||||
JS_INLINE jsword
|
||||
js_ReadWord(jsword *p)
|
||||
{
|
||||
jsword n;
|
||||
while ((n = *p) == -1)
|
||||
;
|
||||
return n;
|
||||
}
|
||||
|
||||
#undef ReadWord
|
||||
#define ReadWord(W) js_ReadWord(&(W))
|
||||
|
||||
static PRLock *_counter_lock;
|
||||
#define UsingCounterLock 1
|
||||
|
||||
#undef AtomicAddBody
|
||||
#define AtomicAddBody(P,I) \
|
||||
PR_Lock(_counter_lock);\
|
||||
*(P) += I;\
|
||||
PR_Unlock(_counter_lock);
|
||||
|
||||
#endif /* !ULTRA_SPARC */
|
||||
|
||||
JS_INLINE int
|
||||
js_CompareAndSwap(jsword *w, jsword ov, jsword nv)
|
||||
{
|
||||
#if defined(__GNUC__)
|
||||
unsigned int res;
|
||||
#ifndef ULTRA_SPARC
|
||||
JS_ASSERT(nv >= 0);
|
||||
asm volatile ("
|
||||
stbar
|
||||
swap [%1],%4
|
||||
1: tst %4
|
||||
bneg,a 1b
|
||||
swap [%1],%4
|
||||
cmp %2,%4
|
||||
be,a 2f
|
||||
swap [%1],%3
|
||||
swap [%1],%4
|
||||
ba 3f
|
||||
mov 0,%0
|
||||
2: mov 1,%0
|
||||
3:"
|
||||
: "=r" (res)
|
||||
: "r" (w), "r" (ov), "r" (nv), "r" (-1));
|
||||
#else /* ULTRA_SPARC */
|
||||
JS_ASSERT(ov != nv);
|
||||
asm volatile ("
|
||||
stbar
|
||||
cas [%1],%2,%3
|
||||
cmp %2,%3
|
||||
be,a 1f
|
||||
mov 1,%0
|
||||
mov 0,%0
|
||||
1:"
|
||||
: "=r" (res)
|
||||
: "r" (w), "r" (ov), "r" (nv));
|
||||
#endif /* ULTRA_SPARC */
|
||||
return (int)res;
|
||||
#else /* !__GNUC__ */
|
||||
extern int compare_and_swap(jsword*,jsword,jsword);
|
||||
#ifndef ULTRA_SPARC
|
||||
JS_ASSERT(nv >= 0);
|
||||
#else
|
||||
JS_ASSERT(ov != nv);
|
||||
#endif
|
||||
return compare_and_swap(w,ov,nv);
|
||||
#endif
|
||||
}
|
||||
|
||||
#elif defined(AIX) && !defined(NSPR_LOCK)
|
||||
#include <sys/atomic_op.h>
|
||||
|
||||
JS_INLINE int
|
||||
js_CompareAndSwap(jsword *w, jsword ov, jsword nv)
|
||||
{
|
||||
return !_check_lock(w,ov,nv);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static PRLock *_counter_lock;
|
||||
#define UsingCounterLock 1
|
||||
|
||||
#undef AtomicAddBody
|
||||
#define AtomicAddBody(P,I) \
|
||||
PR_Lock(_counter_lock);\
|
||||
*(P) += I;\
|
||||
PR_Unlock(_counter_lock);
|
||||
|
||||
static PRLock *_compare_and_swap_lock;
|
||||
#define UsingCompareAndSwapLock 1
|
||||
|
||||
JS_INLINE int
|
||||
js_CompareAndSwap(jsword *w, jsword ov, jsword nv)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
PR_Lock(_compare_and_swap_lock);
|
||||
if (*w == ov) {
|
||||
*w = nv;
|
||||
res = 1;
|
||||
}
|
||||
PR_Unlock(_compare_and_swap_lock);
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif /* arch-tests */
|
||||
|
||||
JS_INLINE void
|
||||
js_AtomicAdd(jsword *p, jsword i)
|
||||
{
|
||||
AtomicAddBody(p,i);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void
|
||||
js_NewLock(JSThinLock *p)
|
||||
{
|
||||
#ifdef NSPR_LOCK
|
||||
p->owner = 0;
|
||||
p->fat = (JSFatLock*)JS_NEW_LOCK();
|
||||
#else
|
||||
memset(p, 0, sizeof(JSThinLock));
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
js_DestroyLock(JSThinLock *p)
|
||||
{
|
||||
#ifdef NSPR_LOCK
|
||||
p->owner = 0xdeadbeef;
|
||||
JS_DESTROY_LOCK(((JSLock*)p->fat));
|
||||
#else
|
||||
JS_ASSERT(p->owner == 0);
|
||||
JS_ASSERT(p->fat == NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void js_Dequeue(JSThinLock *);
|
||||
|
||||
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;
|
||||
jsword me = cx->thread;
|
||||
#endif
|
||||
|
||||
JS_ASSERT(obj->slots && slot < obj->map->freeslot);
|
||||
#ifndef NSPR_LOCK
|
||||
JS_ASSERT(me == CurrentThreadId());
|
||||
if (js_CompareAndSwap(&p->owner, 0, me)) {
|
||||
if (scp == (JSScope *)obj->map) {
|
||||
v = obj->slots[slot];
|
||||
if (!js_CompareAndSwap(&p->owner, me, 0)) {
|
||||
scp->count = 1;
|
||||
js_UnlockObj(cx,obj);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
if (!js_CompareAndSwap(&p->owner, me, 0))
|
||||
js_Dequeue(p);
|
||||
}
|
||||
else if (Thin_RemoveWait(ReadWord(p->owner)) == me) {
|
||||
return obj->slots[slot];
|
||||
}
|
||||
#endif
|
||||
js_LockObj(cx,obj);
|
||||
v = obj->slots[slot];
|
||||
js_UnlockObj(cx,obj);
|
||||
return v;
|
||||
}
|
||||
|
||||
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;
|
||||
jsword me = cx->thread;
|
||||
#endif
|
||||
|
||||
JS_ASSERT(obj->slots && slot < obj->map->freeslot);
|
||||
#ifndef NSPR_LOCK
|
||||
JS_ASSERT(me == CurrentThreadId());
|
||||
if (js_CompareAndSwap(&p->owner, 0, me)) {
|
||||
if (scp == (JSScope *)obj->map) {
|
||||
obj->slots[slot] = v;
|
||||
if (!js_CompareAndSwap(&p->owner, me, 0)) {
|
||||
scp->count = 1;
|
||||
js_UnlockObj(cx,obj);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!js_CompareAndSwap(&p->owner, me, 0))
|
||||
js_Dequeue(p);
|
||||
}
|
||||
else if (Thin_RemoveWait(ReadWord(p->owner)) == me) {
|
||||
obj->slots[slot] = v;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
js_LockObj(cx,obj);
|
||||
obj->slots[slot] = v;
|
||||
js_UnlockObj(cx,obj);
|
||||
}
|
||||
|
||||
static JSFatLock *
|
||||
mallocFatlock()
|
||||
{
|
||||
JSFatLock *fl = (JSFatLock *)malloc(sizeof(JSFatLock)); /* for now */
|
||||
JS_ASSERT(fl);
|
||||
fl->susp = 0;
|
||||
fl->next = NULL;
|
||||
fl->prev = NULL;
|
||||
fl->slock = PR_NewLock();
|
||||
fl->svar = JS_NewCondVar(fl->slock);
|
||||
return fl;
|
||||
}
|
||||
|
||||
static void
|
||||
freeFatlock(JSFatLock *fl)
|
||||
{
|
||||
PR_DestroyLock(fl->slock);
|
||||
PR_DestroyCondVar(fl->svar);
|
||||
free(fl);
|
||||
}
|
||||
|
||||
static int
|
||||
js_SuspendThread(JSThinLock *p)
|
||||
{
|
||||
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 (fl->susp < 1) {
|
||||
PR_Unlock(fl->slock);
|
||||
return 1;
|
||||
}
|
||||
stat = PR_WaitCondVar(fl->svar,JS_INTERVAL_NO_TIMEOUT);
|
||||
if (stat == JS_FAILURE) {
|
||||
fl->susp--;
|
||||
return 0;
|
||||
}
|
||||
PR_Unlock(fl->slock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
js_ResumeThread(JSThinLock *p)
|
||||
{
|
||||
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);
|
||||
JS_ASSERT(stat != JS_FAILURE);
|
||||
PR_Unlock(fl->slock);
|
||||
}
|
||||
|
||||
static JSFatLock *
|
||||
listOfFatlocks(int l)
|
||||
{
|
||||
JSFatLock *m;
|
||||
JSFatLock *m0;
|
||||
int i;
|
||||
|
||||
JS_ASSERT(l>0);
|
||||
m0 = m = mallocFatlock();
|
||||
for (i=1; i<l; i++) {
|
||||
m->next = mallocFatlock();
|
||||
m = m->next;
|
||||
}
|
||||
return m0;
|
||||
}
|
||||
|
||||
static void
|
||||
deleteListOfFatlocks(JSFatLock *m)
|
||||
{
|
||||
JSFatLock *m0;
|
||||
for (; m; m=m0) {
|
||||
m0 = m->next;
|
||||
freeFatlock(m);
|
||||
}
|
||||
}
|
||||
|
||||
static JSFatLockTable _fl_table;
|
||||
|
||||
JSFatLock *
|
||||
allocateFatlock()
|
||||
{
|
||||
JSFatLock *m;
|
||||
|
||||
js_LockGlobal();
|
||||
if (_fl_table.free == NULL) {
|
||||
#ifdef DEBUG
|
||||
printf("Ran out of fat locks!\n");
|
||||
#endif
|
||||
_fl_table.free = listOfFatlocks(10);
|
||||
}
|
||||
m = _fl_table.free;
|
||||
_fl_table.free = m->next;
|
||||
_fl_table.free->prev = NULL;
|
||||
m->susp = 0;
|
||||
m->next = _fl_table.taken;
|
||||
m->prev = NULL;
|
||||
if (_fl_table.taken != NULL)
|
||||
_fl_table.taken->prev = m;
|
||||
_fl_table.taken = m;
|
||||
js_UnlockGlobal();
|
||||
return m;
|
||||
}
|
||||
|
||||
void
|
||||
deallocateFatlock(JSFatLock *m)
|
||||
{
|
||||
if (m == NULL)
|
||||
return;
|
||||
js_LockGlobal();
|
||||
if (m->prev != NULL)
|
||||
m->prev->next = m->next;
|
||||
if (m->next != NULL)
|
||||
m->next->prev = m->prev;
|
||||
if (m == _fl_table.taken)
|
||||
_fl_table.taken = m->next;
|
||||
m->next = _fl_table.free;
|
||||
_fl_table.free = m;
|
||||
js_UnlockGlobal();
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(int)
|
||||
js_SetupLocks(int l)
|
||||
{
|
||||
if (l > 10000) /* l equals number of initially allocated fat locks */
|
||||
#ifdef DEBUG
|
||||
printf("Number %d very large in js_SetupLocks()!\n",l);
|
||||
#endif
|
||||
if (_global_lock)
|
||||
return 1;
|
||||
_global_lock = PR_NewLock();
|
||||
JS_ASSERT(_global_lock);
|
||||
#ifdef UsingCounterLock
|
||||
_counter_lock = PR_NewLock();
|
||||
JS_ASSERT(_counter_lock);
|
||||
#endif
|
||||
#ifdef UsingCompareAndSwapLock
|
||||
_compare_and_swap_lock = PR_NewLock();
|
||||
JS_ASSERT(_compare_and_swap_lock);
|
||||
#endif
|
||||
_fl_table.free = listOfFatlocks(l);
|
||||
_fl_table.taken = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
js_CleanupLocks()
|
||||
{
|
||||
if (_global_lock != NULL) {
|
||||
deleteListOfFatlocks(_fl_table.free);
|
||||
_fl_table.free = NULL;
|
||||
deleteListOfFatlocks(_fl_table.taken);
|
||||
_fl_table.taken = NULL;
|
||||
PR_DestroyLock(_global_lock);
|
||||
_global_lock = NULL;
|
||||
#ifdef UsingCounterLock
|
||||
PR_DestroyLock(_counter_lock);
|
||||
_counter_lock = NULL;
|
||||
#endif
|
||||
#ifdef UsingCompareAndSwapLock
|
||||
PR_DestroyLock(_compare_and_swap_lock);
|
||||
_compare_and_swap_lock = NULL;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(void)
|
||||
js_InitContextForLocking(JSContext *cx)
|
||||
{
|
||||
cx->thread = CurrentThreadId();
|
||||
JS_ASSERT(Thin_GetWait(cx->thread) == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
It is important that emptyFatlock() clears p->fat in the empty case
|
||||
while holding p->slock. This serializes the access of p->fat wrt
|
||||
js_SuspendThread(), which also requires p->slock. There would
|
||||
otherwise be a race condition as follows. Thread A is about to
|
||||
clear p->fat, having woken up after being suspended in a situation
|
||||
where no other thread has yet suspended on p. However, suppose
|
||||
thread B is about to suspend on p, having just released the global
|
||||
lock, and is currently calling js_SuspendThread(). In the unfortunate
|
||||
case where A precedes B ever so slightly, A will think that it
|
||||
should clear p->fat (being currently empty but not for long), at the
|
||||
same time as B is about to suspend on p->fat. Now, A deallocates
|
||||
p->fat while B is about to suspend on it. Thus, the suspension of B
|
||||
is lost and B will not be properly activated.
|
||||
|
||||
Using p->slock as below (and correspondingly in js_SuspendThread()),
|
||||
js_SuspendThread() will notice that p->fat is empty, and hence return
|
||||
immediately.
|
||||
|
||||
*/
|
||||
|
||||
int
|
||||
emptyFatlock(JSThinLock *p)
|
||||
{
|
||||
JSFatLock *fl;
|
||||
int i;
|
||||
PRLock* lck;
|
||||
|
||||
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;
|
||||
}
|
||||
lck = fl->slock;
|
||||
PR_Lock(lck);
|
||||
i = fl->susp;
|
||||
if (i < 1) {
|
||||
fl->susp = -1;
|
||||
deallocateFatlock(fl);
|
||||
fl = NULL;
|
||||
}
|
||||
js_AtomicSet((jsword*)&p->fat,(jsword)fl);
|
||||
PR_Unlock(lck);
|
||||
return i < 1;
|
||||
}
|
||||
|
||||
/*
|
||||
Fast locking and unlocking is implemented by delaying the
|
||||
allocation of a system lock (fat lock) until contention. As long as
|
||||
a locking thread A runs uncontended, the lock is represented solely
|
||||
by storing A's identity in the object being locked.
|
||||
|
||||
If another thread B tries to lock the object currently locked by A,
|
||||
B is enqueued into a fat lock structure (which might have to be
|
||||
allocated and pointed to by the object), and suspended using NSPR
|
||||
conditional variables (wait). A wait bit (Bacon bit) is set in the
|
||||
lock word of the object, signalling to A that when releasing the
|
||||
lock, B must be dequeued and notified.
|
||||
|
||||
The basic operation of the locking primitives (js_Lock(),
|
||||
js_Unlock(), js_Enqueue(), and js_Dequeue()) is
|
||||
compare-and-swap. Hence, when locking into p, if
|
||||
compare-and-swap(p,NULL,me) succeeds this implies that p is
|
||||
unlocked. Similarly, when unlocking p, if
|
||||
compare-and-swap(p,me,NULL) succeeds this implies that p is
|
||||
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), 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, jsword me)
|
||||
{
|
||||
jsword o, n;
|
||||
|
||||
while (1) {
|
||||
o = ReadWord(p->owner);
|
||||
n = Thin_SetWait(o);
|
||||
if (o != 0 && js_CompareAndSwap(&p->owner,o,n)) {
|
||||
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
|
||||
me = Thin_SetWait(me);
|
||||
}
|
||||
else if (js_CompareAndSwap(&p->owner,0,me)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
js_Dequeue(JSThinLock *p)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
JS_INLINE void
|
||||
js_Lock(JSThinLock *p, jsword me)
|
||||
{
|
||||
JS_ASSERT(me == CurrentThreadId());
|
||||
if (js_CompareAndSwap(&p->owner, 0, me))
|
||||
return;
|
||||
if (Thin_RemoveWait(ReadWord(p->owner)) != me)
|
||||
js_Enqueue(p, me);
|
||||
#ifdef DEBUG
|
||||
else
|
||||
JS_ASSERT(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
JS_INLINE void
|
||||
js_Unlock(JSThinLock *p, jsword me)
|
||||
{
|
||||
JS_ASSERT(me == CurrentThreadId());
|
||||
if (js_CompareAndSwap(&p->owner, me, 0))
|
||||
return;
|
||||
if (Thin_RemoveWait(ReadWord(p->owner)) == me)
|
||||
js_Dequeue(p);
|
||||
#ifdef DEBUG
|
||||
else
|
||||
JS_ASSERT(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
js_LockRuntime(JSRuntime *rt)
|
||||
{
|
||||
jsword me = CurrentThreadId();
|
||||
JSThinLock *p;
|
||||
|
||||
JS_ASSERT(Thin_RemoveWait(ReadWord(rt->rtLock.owner)) != me);
|
||||
p = &rt->rtLock;
|
||||
JS_LOCK0(p,me);
|
||||
}
|
||||
|
||||
void
|
||||
js_UnlockRuntime(JSRuntime *rt)
|
||||
{
|
||||
jsword me = CurrentThreadId();
|
||||
JSThinLock *p;
|
||||
|
||||
JS_ASSERT(Thin_RemoveWait(ReadWord(rt->rtLock.owner)) == me);
|
||||
p = &rt->rtLock;
|
||||
JS_UNLOCK0(p,me);
|
||||
}
|
||||
|
||||
JS_INLINE void
|
||||
js_LockScope1(JSContext *cx, JSScope *scope, jsword me)
|
||||
{
|
||||
JSThinLock *p;
|
||||
|
||||
if (Thin_RemoveWait(ReadWord(scope->lock.owner)) == me) {
|
||||
JS_ASSERT(scope->count > 0);
|
||||
scope->count++;
|
||||
} else {
|
||||
p = &scope->lock;
|
||||
JS_LOCK0(p,me);
|
||||
JS_ASSERT(scope->count == 0);
|
||||
scope->count = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
js_LockScope(JSContext *cx, JSScope *scope)
|
||||
{
|
||||
JS_ASSERT(cx->thread == CurrentThreadId());
|
||||
js_LockScope1(cx,scope,cx->thread);
|
||||
}
|
||||
|
||||
void
|
||||
js_UnlockScope(JSContext *cx, JSScope *scope)
|
||||
{
|
||||
jsword me = cx->thread;
|
||||
JSThinLock *p;
|
||||
|
||||
JS_ASSERT(scope->count > 0);
|
||||
if (Thin_RemoveWait(ReadWord(scope->lock.owner)) != me) {
|
||||
JS_ASSERT(0);
|
||||
return;
|
||||
}
|
||||
if (--scope->count == 0) {
|
||||
p = &scope->lock;
|
||||
JS_UNLOCK0(p,me);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
js_TransferScopeLock(JSContext *cx, JSScope *oldscope, JSScope *newscope)
|
||||
{
|
||||
jsword me;
|
||||
JSThinLock *p;
|
||||
|
||||
JS_ASSERT(JS_IS_SCOPE_LOCKED(newscope));
|
||||
/*
|
||||
* If the last reference to oldscope went away, newscope needs no lock
|
||||
* state update.
|
||||
*/
|
||||
if (!oldscope) {
|
||||
return;
|
||||
}
|
||||
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
|
||||
* from the current point (under js_GetMutableScope).
|
||||
*/
|
||||
newscope->count = oldscope->count;
|
||||
/*
|
||||
* Reset oldscope's lock state so that it is completely unlocked.
|
||||
*/
|
||||
oldscope->count = 0;
|
||||
p = &oldscope->lock;
|
||||
me = cx->thread;
|
||||
JS_UNLOCK0(p,me);
|
||||
}
|
||||
|
||||
void
|
||||
js_LockObj(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
JSScope *scope;
|
||||
jsword me = cx->thread;
|
||||
JS_ASSERT(me == CurrentThreadId());
|
||||
for (;;) {
|
||||
scope = (JSScope *) obj->map;
|
||||
js_LockScope1(cx, scope, me);
|
||||
|
||||
/* If obj still has this scope, we're done. */
|
||||
if (scope == (JSScope *) obj->map)
|
||||
return;
|
||||
|
||||
/* Lost a race with a mutator; retry with obj's new scope. */
|
||||
js_UnlockScope(cx, scope);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
js_UnlockObj(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
js_UnlockScope(cx, (JSScope *) obj->map);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
JSBool
|
||||
js_IsRuntimeLocked(JSRuntime *rt)
|
||||
{
|
||||
return CurrentThreadId() == Thin_RemoveWait(ReadWord(rt->rtLock.owner));
|
||||
}
|
||||
|
||||
JSBool
|
||||
js_IsObjLocked(JSObject *obj)
|
||||
{
|
||||
JSObjectMap *map = obj->map;
|
||||
|
||||
return MAP_IS_NATIVE(map) && CurrentThreadId() == Thin_RemoveWait(ReadWord(((JSScope *)map)->lock.owner));
|
||||
}
|
||||
|
||||
JSBool
|
||||
js_IsScopeLocked(JSScope *scope)
|
||||
{
|
||||
return CurrentThreadId() == Thin_RemoveWait(ReadWord(scope->lock.owner));
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef ReadWord
|
||||
#endif /* JS_THREADSAFE */
|
||||
@@ -1,219 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.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 jslock_h__
|
||||
#define jslock_h__
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
|
||||
#include "jstypes.h"
|
||||
#include "prlock.h"
|
||||
#include "prcvar.h"
|
||||
#ifndef NSPR20
|
||||
#include "jshash.h"
|
||||
#else
|
||||
/* Removed by JSIFY: #include "JShash.h"
|
||||
*/
|
||||
#include "jshash.h" /* Added by JSIFY */
|
||||
#endif
|
||||
|
||||
#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;
|
||||
PRLock* slock;
|
||||
PRCondVar* svar;
|
||||
struct JSFatLock *next;
|
||||
struct JSFatLock *prev;
|
||||
} JSFatLock;
|
||||
|
||||
typedef struct JSThinLock {
|
||||
jsword owner;
|
||||
JSFatLock *fat;
|
||||
} JSThinLock;
|
||||
|
||||
typedef PRLock JSLock;
|
||||
|
||||
typedef struct JSFatLockTable {
|
||||
JSFatLock *free;
|
||||
JSFatLock *taken;
|
||||
} JSFatLockTable;
|
||||
|
||||
#define JS_ATOMIC_ADDREF(p, i) js_AtomicAdd(p,i)
|
||||
|
||||
#define CurrentThreadId() (jsword)PR_GetCurrentThread()
|
||||
#define JS_CurrentThreadId() js_CurrentThreadId()
|
||||
#define JS_NEW_LOCK() PR_NewLock()
|
||||
#define JS_DESTROY_LOCK(l) PR_DestroyLock(l)
|
||||
#define JS_ACQUIRE_LOCK(l) PR_Lock(l)
|
||||
#define JS_RELEASE_LOCK(l) PR_Unlock(l)
|
||||
#define JS_LOCK0(P,M) js_Lock(P,M)
|
||||
#define JS_UNLOCK0(P,M) js_Unlock(P,M)
|
||||
|
||||
#define JS_NEW_CONDVAR(l) 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 JS_INTERVAL_NO_TIMEOUT
|
||||
#define JS_NOTIFY_CONDVAR(cv) PR_NotifyCondVar(cv)
|
||||
#define JS_NOTIFY_ALL_CONDVAR(cv) PR_NotifyAllCondVar(cv)
|
||||
|
||||
#ifdef DEBUG
|
||||
#include "jsscope.h"
|
||||
|
||||
#define _SET_OBJ_INFO(obj,f,l) \
|
||||
_SET_SCOPE_INFO(((JSScope*)obj->map),f,l)
|
||||
|
||||
#define _SET_SCOPE_INFO(scope,f,l) \
|
||||
(JS_ASSERT(scope->count > 0 && scope->count <= 4), \
|
||||
scope->file[scope->count-1] = f, \
|
||||
scope->line[scope->count-1] = l)
|
||||
#endif /* DEBUG */
|
||||
|
||||
#define JS_LOCK_RUNTIME(rt) js_LockRuntime(rt)
|
||||
#define JS_UNLOCK_RUNTIME(rt) js_UnlockRuntime(rt)
|
||||
#define JS_LOCK_OBJ(cx,obj) (js_LockObj(cx, obj), \
|
||||
_SET_OBJ_INFO(obj,__FILE__,__LINE__))
|
||||
#define JS_UNLOCK_OBJ(cx,obj) js_UnlockObj(cx, obj)
|
||||
#define JS_LOCK_SCOPE(cx,scope) (js_LockScope(cx, scope), \
|
||||
_SET_SCOPE_INFO(scope,__FILE__,__LINE__))
|
||||
#define JS_UNLOCK_SCOPE(cx,scope) js_UnlockScope(cx, scope)
|
||||
#define JS_TRANSFER_SCOPE_LOCK(cx, scope, newscope) js_TransferScopeLock(cx, scope, newscope)
|
||||
|
||||
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);
|
||||
extern void js_UnlockObj(JSContext *cx, JSObject *obj);
|
||||
extern void js_LockScope(JSContext *cx, JSScope *scope);
|
||||
extern void js_UnlockScope(JSContext *cx, JSScope *scope);
|
||||
extern JS_PUBLIC_API(int) js_SetupLocks(int);
|
||||
extern JS_PUBLIC_API(void) js_CleanupLocks();
|
||||
extern JS_PUBLIC_API(void) js_InitContextForLocking(JSContext *);
|
||||
extern void js_TransferScopeLock(JSContext *, JSScope *, JSScope *);
|
||||
extern JS_PUBLIC_API(jsval) js_GetSlotWhileLocked(JSContext *, JSObject *, uint32);
|
||||
extern JS_PUBLIC_API(void) js_SetSlotWhileLocked(JSContext *, JSObject *, uint32, jsval);
|
||||
extern void js_NewLock(JSThinLock *);
|
||||
extern void js_DestroyLock(JSThinLock *);
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#define JS_IS_RUNTIME_LOCKED(rt) js_IsRuntimeLocked(rt)
|
||||
#define JS_IS_OBJ_LOCKED(obj) js_IsObjLocked(obj)
|
||||
#define JS_IS_SCOPE_LOCKED(scope) js_IsScopeLocked(scope)
|
||||
|
||||
extern JSBool js_IsRuntimeLocked(JSRuntime *rt);
|
||||
extern JSBool js_IsObjLocked(JSObject *obj);
|
||||
extern JSBool js_IsScopeLocked(JSScope *scope);
|
||||
|
||||
#else
|
||||
|
||||
#define JS_IS_RUNTIME_LOCKED(rt) 0
|
||||
#define JS_IS_OBJ_LOCKED(obj) 1
|
||||
#define JS_IS_SCOPE_LOCKED(scope) 1
|
||||
|
||||
#endif /* DEBUG */
|
||||
|
||||
#define JS_LOCK_OBJ_VOID(cx, obj, e) \
|
||||
JS_BEGIN_MACRO \
|
||||
js_LockObj(cx, obj); \
|
||||
e; \
|
||||
js_UnlockObj(cx, obj); \
|
||||
JS_END_MACRO
|
||||
|
||||
#define JS_LOCK_VOID(cx, e) \
|
||||
JS_BEGIN_MACRO \
|
||||
JSRuntime *_rt = (cx)->runtime; \
|
||||
JS_LOCK_RUNTIME_VOID(_rt, e); \
|
||||
JS_END_MACRO
|
||||
|
||||
#if defined(JS_ONLY_NSPR_LOCKS) || !(defined(_WIN32) || defined(SOLARIS) || defined(AIX))
|
||||
|
||||
#undef JS_LOCK0
|
||||
#undef JS_UNLOCK0
|
||||
#define JS_LOCK0(P,M) JS_ACQUIRE_LOCK(((JSLock*)(P)->fat)); (P)->owner = (M)
|
||||
#define JS_UNLOCK0(P,M) (P)->owner = 0; JS_RELEASE_LOCK(((JSLock*)(P)->fat))
|
||||
#define NSPR_LOCK 1
|
||||
|
||||
#endif /* arch-tests */
|
||||
|
||||
#else /* !JS_THREADSAFE */
|
||||
|
||||
#define JS_ATOMIC_ADDREF(p,i) (*(p) += i)
|
||||
|
||||
#define JS_CurrentThreadId() 0
|
||||
#define JS_NEW_LOCK() NULL
|
||||
#define JS_DESTROY_LOCK(l) ((void)0)
|
||||
#define JS_ACQUIRE_LOCK(l) ((void)0)
|
||||
#define JS_RELEASE_LOCK(l) ((void)0)
|
||||
#define JS_LOCK0(P,M) ((void)0)
|
||||
#define JS_UNLOCK0(P,M) ((void)0)
|
||||
|
||||
#define JS_NEW_CONDVAR(l) NULL
|
||||
#define JS_DESTROY_CONDVAR(cv) ((void)0)
|
||||
#define JS_WAIT_CONDVAR(cv,to) ((void)0)
|
||||
#define JS_NOTIFY_CONDVAR(cv) ((void)0)
|
||||
#define JS_NOTIFY_ALL_CONDVAR(cv) ((void)0)
|
||||
|
||||
#define JS_LOCK_RUNTIME(rt) ((void)0)
|
||||
#define JS_UNLOCK_RUNTIME(rt) ((void)0)
|
||||
#define JS_LOCK_OBJ(cx,obj) ((void)0)
|
||||
#define JS_UNLOCK_OBJ(cx,obj) ((void)0)
|
||||
#define JS_LOCK_OBJ_VOID(cx,obj,e) (e)
|
||||
#define JS_LOCK_SCOPE(cx,scope) ((void)0)
|
||||
#define JS_UNLOCK_SCOPE(cx,scope) ((void)0)
|
||||
#define JS_TRANSFER_SCOPE_LOCK(c,o,n) ((void)0)
|
||||
|
||||
#define JS_IS_RUNTIME_LOCKED(rt) 1
|
||||
#define JS_IS_OBJ_LOCKED(obj) 1
|
||||
#define JS_IS_SCOPE_LOCKED(scope) 1
|
||||
#define JS_LOCK_VOID(cx, e) JS_LOCK_RUNTIME_VOID((cx)->runtime, e)
|
||||
|
||||
#endif /* !JS_THREADSAFE */
|
||||
|
||||
#define JS_LOCK_RUNTIME_VOID(rt,e) \
|
||||
JS_BEGIN_MACRO \
|
||||
JS_LOCK_RUNTIME(rt); \
|
||||
e; \
|
||||
JS_UNLOCK_RUNTIME(rt); \
|
||||
JS_END_MACRO
|
||||
|
||||
#define JS_LOCK_GC(rt) JS_ACQUIRE_LOCK((rt)->gcLock)
|
||||
#define JS_UNLOCK_GC(rt) JS_RELEASE_LOCK((rt)->gcLock)
|
||||
#define JS_LOCK_GC_VOID(rt,e) (JS_LOCK_GC(rt), (e), JS_UNLOCK_GC(rt))
|
||||
#define JS_AWAIT_GC_DONE(rt) JS_WAIT_CONDVAR((rt)->gcDone, JS_NO_TIMEOUT)
|
||||
#define JS_NOTIFY_GC_DONE(rt) JS_NOTIFY_ALL_CONDVAR((rt)->gcDone)
|
||||
#define JS_AWAIT_REQUEST_DONE(rt) JS_WAIT_CONDVAR((rt)->requestDone, \
|
||||
JS_NO_TIMEOUT)
|
||||
#define JS_NOTIFY_REQUEST_DONE(rt) JS_NOTIFY_CONDVAR((rt)->requestDone)
|
||||
|
||||
#define JS_LOCK(P,CX) JS_LOCK0(P,(CX)->thread)
|
||||
#define JS_UNLOCK(P,CX) JS_UNLOCK0(P,(CX)->thread)
|
||||
|
||||
#ifndef _SET_OBJ_INFO
|
||||
#define _SET_OBJ_INFO(obj,f,l) ((void)0)
|
||||
#endif
|
||||
#ifndef _SET_SCOPE_INFO
|
||||
#define _SET_SCOPE_INFO(scope,f,l) ((void)0)
|
||||
#endif
|
||||
|
||||
#endif /* jslock_h___ */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user