diff options
Diffstat (limited to 'files/zh-cn/mozilla/projects/spidermonkey')
28 files changed, 0 insertions, 4610 deletions
diff --git a/files/zh-cn/mozilla/projects/spidermonkey/build_documentation/index.html b/files/zh-cn/mozilla/projects/spidermonkey/build_documentation/index.html deleted file mode 100644 index ecb793016e..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/build_documentation/index.html +++ /dev/null @@ -1,294 +0,0 @@ ---- -title: SpiderMonkey Build Documentation -slug: Mozilla/Projects/SpiderMonkey/Build_Documentation -translation_of: Mozilla/Projects/SpiderMonkey/Build_Documentation ---- -<div>{{SpiderMonkeySidebar("General")}}</div> - -<h2 id="构建_SpiderMonkey">构建 SpiderMonkey</h2> - -<p>使用本说明来构建最新的 SpiderMonkey 源码.</p> - -<p><strong>在构建前, 确保有适合你计算机的构建工具:</strong> <a href="/en-US/Developer_Guide/Build_Instructions/Linux_Prerequisites" title="en/Linux_Build_Prerequisites">Linux</a>, <a href="/en/Developer_Guide/Build_Instructions/Windows_Prerequisites" title="en/Windows_Build_Prerequisites">Windows</a>, <a href="/en/Developer_Guide/Build_Instructions/Mac_OS_X_Prerequisites" title="en/Mac_OS_X_Build_Prerequisites">Mac</a>, <a href="/en/Developer_Guide/Build_Instructions" title="en/Build_Documentation">others</a>. 当构建的版本低于28, 你还需要外加 <a href="/en/NSPR" title="en/NSPR">NSPR</a>.</p> - -<p style="margin: 0px 0px 1.7em; padding: 0px;">以及理所当然地, 你需要 <a class="internal" href="Getting_SpiderMonkey_source_code" title="En/SpiderMonkey/Getting SpiderMonkey source code#Getting the latest SpiderMonkey source code">获取 SpiderMonkey 源代码。</a></p> - -<h3 id="非开发者_(优化)_模式构建">非开发者 (优化) 模式构建</h3> - -<p>如果你想在生产环境中安装使用SpiderMonkey或运行标准性能测试,可以使用此步骤。 (如果你想在你的C++应用中把 SpiderMonkey 作为库使用, 或从事改进 SpiderMonkey 本身的工作, 按之后的描述,使用 开发者/调试 模式构建.)</p> - -<pre class="eval">cd js/src -autoconf2.13 - -# This name should end with "_OPT.OBJ" to make the version control system ignore it. -mkdir build_OPT.OBJ -cd build_OPT.OBJ -../configure -# Use "mozmake" on Windows -make -</pre> - -<p>一些注意事项:</p> - -<ul> - <li> - <p>The most common build problems are dependency problems. See the <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions#Getting_started">build prerequisites page for your platform</a>.</p> - </li> - <li> - <p>SpiderMonkey does not support building in your source directory. You must configure and build in a separate build directory, as shown above.</p> - </li> - <li> - <p>Yes, autoconf version 2.13 really is required. Later versions won't work. (However, don't install it as your system <code>autoconf</code>. That also won't work, and it's a bad idea because that version is so old.)</p> - </li> -</ul> - -<div class="note"> -<p><strong>Note</strong>: If you are on Mac and getting an error similar to</p> - -<p>"<code>checking whether the C compiler (gcc-4.2 ) works... no<br> - configure: error: installation or configuration problem: C compiler cannot create executables.</code>"</p> - -<p>You can try configuring like so:</p> - -<pre><code>CC=clang CXX=clang++ ../configure</code></pre> - -<p>It is also possible that baldrdash may fail to compile with</p> - -<pre>/usr/local/Cellar/llvm/7.0.1/lib/clang/7.0.1/include/inttypes.h:30:15: fatal error: 'inttypes.h' file not found - -/usr/local/Cellar/llvm/7.0.1/lib/clang/7.0.1/include/inttypes.h:30:15: fatal error: 'inttypes.h' file not found, err: true</pre> - -<p>This is because, starting from Mohave, headers are no longer installed in /usr/include. Refer the <a href="https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes">release notes</a> under Command Line Tools -> New Features</p> - -<p>The release notes also states that this compatibility package will no longer be provided in the near future, so the build system on macOS will have to be adapted to look for headers in the SDK<br> - <br> - Until then, the following should help,</p> - -<pre><code>open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pk -</code></pre> -</div> - -<p>This builds an executable named <code>js</code> in the directory <code>build-release/dist/bin</code>. You can test it with <code>dist/bin/js --help</code>, which displays a help page. At this point, you're ready to <a href="/en/SpiderMonkey/Introduction_to_the_JavaScript_shell" title="en/Introduction_to_the_JavaScript_shell">run and try out the shell</a>.</p> - -<p>On Mac, Linux, or UNIX, you can install SpiderMonkey on your system with the additional command <code>make install</code>. This installs the shared library to <code>/usr/local/lib</code>, the C header files to <code>/usr/local/include</code>, and the <code>js</code> executable to<code>/usr/local/bin</code>.</p> - -<h3 id="开发者_(调试)_模式构建">开发者 (调试) 模式构建</h3> - -<p>For developing and debugging SpiderMonkey itself, it is best to have both a debug build (for everyday debugging) and an optimized build (for performance testing), in separate build directories. Thus, in addition to following the steps above, you should also create a debug build using these steps:</p> - -<pre class="eval">cd js/src -autoconf2.13 - -# This name should end with "_DBG.OBJ" to make the version control system ignore it. -mkdir build_DBG.OBJ -cd build_DBG.OBJ -../configure --enable-debug --disable-optimize -# Use "mozmake" on Windows -make -</pre> - -<p>You can also build debug builds of SpiderMonkey with the <code>JS_GC_ZEAL</code> option, which adds a new built-in function to SpiderMonkey that lets you configure zealous garbage collection. This can help debug memory leaks and other memory-related problems. See <a class="internal" href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCZeal" title="En/SpiderMonkey/JSAPI Reference/JS SetGCZeal"><code>JS_SetGCZeal()</code></a> for details.</p> - -<p>For a list of other available build options, type (assuming the current working directory is one of the above-created build directories):</p> - -<pre class="eval">../configure --help -</pre> - -<h4 id="生成编译数据库">生成编译数据库</h4> - -<p>Some tools (like IDEs, static analyzers and refactoring tools) consume a file called <code><a href="https://clang.llvm.org/docs/JSONCompilationDatabase.html">compile_commands.json</a></code> which contains a description of all the pieces required to build a piece of software so that tools don't have to also understand a build system.</p> - -<p>To generate a <code>compile_commands.json</code> with the SpiderMonkey <code>configure</code> script, enable the CompileDB backend, like this:</p> - -<pre class="syntaxbox"> ../configure <options> --enable-build-backends=CompileDB,RecursiveMake -</pre> - -<p>(RecursiveMake is there as you'd likely also want to be able to build!)</p> - -<h3 id="Building" name="Building">Windows Builds</h3> - -<div class="note"> -<p>Since version 28, <strong>threadsafe builds are the default</strong>, and should work out of the box on all POSIX platforms. Hence, the following instructions should only be relevant if you're on Windows or compiling an older version of SpiderMonkey.</p> -</div> - -<p>The <a href="https://wiki.mozilla.org/MozillaBuild">MozillaBuild</a> batch file you used to open your shell (e.g. <code>start-shell-msvc2013.bat</code> or <code>start-shell-msvc2013-x64.bat</code>) determines whether the compiler toolchain will target 32-bit or 64-bit builds. To create a 64-bit build, note that you must configure with <code>--target=x86_64-pc-mingw32 --host=x86_64-pc-mingw32</code>.</p> - -<p>Since the POSIX NSPR emulation is not available for Windows, a working version of NSPR must be available to your build. <strong>The easiest option is to configure with <code>--enable-nspr-build.</code></strong><code> </code>This configure option builds the in-tree version of NSPR which is probably what you want; <span style="line-height: normal;"><span style="line-height: normal;">because SpiderMonkey uses newer NSPR symbols, the NSPR that ships with your operating system probably does not work.</span></span></p> - -<p>If <code>--enable-nspr-build</code> does not work, explicitly tell <code>configure</code> where to find NSPR using the <code>--with-nspr-cflags</code> and <code>--with-nspr-libs</code> configure options. For example, assuming your local NSPR has been installed to <code>C:/mozilla-build/msys/local</code>:</p> - -<pre><span style="line-height: normal;"><code><span style="line-height: normal;"><code><code>./configure<code> --with-nspr-cflags="-IC:/mozilla-build/msys/local/include" \ - --with-nspr-libs="<span style="line-height: normal;"><code><span style="line-height: normal;"><code><code><code>C:/mozilla-build/msys/local</code></code></code></span></code></span>/lib/libnspr4.a \ - <span style="line-height: normal;"><code><span style="line-height: normal;"><code><code><code>C:/mozilla-build/msys/local</code></code></code></span></code></span>/lib/libplds4.a \ - <span style="line-height: normal;"><code><span style="line-height: normal;"><code><code><code>C:/mozilla-build/msys/local</code></code></code></span></code></span>/lib/libplc4.a"</code> -</code></code></span></code></span></pre> - -<p>If you get symbol loading or dynamic library errors, you can force the correct NSPR to load with:</p> - -<pre><span style="line-height: normal;">PATH="$PATH;<span style="line-height: normal;">C:/mozilla-build/msys/local/lib/</span><span style="line-height: normal;">" ./js</span></span></pre> - -<h2 id="指定安装目录">指定安装目录</h2> - -<p><code>make install</code> puts files in the following directories by default. You can override this by passing options to the <code>configure</code> script:</p> - -<table class="standard-table"> - <tbody> - <tr> - <th>What it is</th> - <th>Where it gets put</th> - <th><code>configure</code> option</th> - </tr> - <tr> - <td>executables, shell scripts</td> - <td><code>/usr/local/bin</code></td> - <td><code>--bindir</code></td> - </tr> - <tr> - <td>libraries, data</td> - <td><code>/usr/local/lib</code></td> - <td><code>--libdir</code></td> - </tr> - <tr> - <td>architecture-independent data</td> - <td><code>/usr/local/share</code></td> - <td><code>--sharedir</code></td> - </tr> - <tr> - <td>C header files</td> - <td><code>/usr/local/include</code></td> - <td><code>--includedir</code></td> - </tr> - </tbody> -</table> - -<p>For convenience, you can pass the <code>configure</code> script an option of the form <code>--prefix=<PREFIXDIR></code>, which substitutes <code><PREFIXDIR></code> for <code>/usr/local</code> in all the settings above, in one step. This is usually the least troublesome thing to do, as it preserves the typical arrangement of <code>lib</code>, <code>bin</code>, and the rest.</p> - -<div class="note"><strong>Note:</strong> All directories you pass to <code>configure</code> are recorded in the generated makefile, so you don't need to specify them again until you re-run <code>configure</code>.</div> - -<h2 id="构建_SpiderMonkey_作为静态库">构建 SpiderMonkey 作为静态库</h2> - -<p>默认情况下, SpiderMonkey 会构建为共享库. However, you can build SpiderMonkey as a static library by specifying the <code>--disable-shared-js</code> flag when you run <code>configure</code>.</p> - -<h2 id="指定编译器及编译标签">指定编译器及编译标签</h2> - -<p>If you want to use a compiler other than the one the <code>configure</code> script chooses for you by default, you can set the <code>CXX</code> variable in the environment when you run <code>configure</code>. This will save the values you specify in the generated makefile, so once you've set it, you don't need to do so again until you re-run <code>configure</code>.</p> - -<p>If you'd like to pass certain flags to the compiler, you can set the <code>CXXFLAGS</code> environment variable when you run <code>configure</code>. For example, if you're using the GNU toolchain, the following will pass the <code>-g3</code> flag to the compiler, causing it to emit debug information about macros. Then you can use those macros in <code>gdb</code> commands:</p> - -<pre class="eval">$ <strong>CXXFLAGS=-g3 $SRC/configure</strong> -<em>...</em> -checking whether the C++ compiler (c++ -g3 ) works... yes -<em>...</em> -$ -</pre> - -<h2 id="交叉编译选项">交叉编译选项</h2> - -<p>For cross-compiling you will need a cross-compiling compiler. That tends to be easier with clang as clang has cross-compiling support built in. You may need other libraries though. For example on debian linux you'll need the following to cross compile from x86_64 to x86.</p> - -<pre class="syntaxbox">apt install clang libstdc++-8-dev-i386-cross binutils-i686-gnu zlib1g-dev:i386</pre> - -<p>You'll also need rust, in addition to having normal rust set up you'll need to add another target to your existing rust toolchain (don't add a new toolchain spidermonkey will use only one toolchain and use it for both host and target code:</p> - -<pre class="syntaxbox">rustup target add i686-unknown-linux-gnu</pre> - -<p>To build a 32-bit version on a 64-bit Linux system, you can use the following:</p> - -<pre class="eval">PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig CC="gcc -m32 -mfpmath=sse -msse -msse2" CXX="g++ -m32 -mfpmath=sse -msse -msse2" AR=ar \ -$SRC/configure --target=i686-pc-linux -</pre> - -<p>Or for clang.</p> - -<pre class="syntaxbox">$SRC/configure --target=i686-pc-linux-gnu</pre> - -<p>To build a 32-bit arm version on a 64-bit Linux system, that runs in the arm simulator, you can use the following:</p> - -<pre> AR=ar CC="gcc -m32 -mfpmath=sse -msse -msse2" CXX="g++ -m32 -mfpmath=sse -msse -msse2" \ - $SRC/configure --target=i686-pc-linux --enable-simulator=arm -</pre> - -<p>To build a 32-bit version on a 64-bit Mac system (the target version is specific to your OS/X SDK), you can use the following:</p> - -<pre class="syntaxbox">$SRC/configure --target=i386-apple-darwin16.7.0 # Choose the appropriate SDK version for your version of OS/X</pre> - -<p>To build a 64-bit version on a 32-bit Mac system (e.g. Mac OS X 10.5), you can use the following:</p> - -<pre class="eval">AR=ar CC="gcc -m64" CXX="g++ -m64" ../configure --target=x86_64-apple-darwin10.0.0 -</pre> - -<p>To build a 64-bit Windows version, you can use the following:</p> - -<pre class="eval">$SRC/configure --host=x86_64-pc-mingw32 --target=x86_64-pc-mingw32 -</pre> - -<div class="note"><strong>Note:</strong> You must have started your MozillaBuild shell with the proper -x64.bat script in order for the 64-bit compilers to be in your PATH.</div> - -<p>Whatever compiler and flags you pass to <code>configure</code> are recorded in the generated makefile, so you don't need to specify them again until you re-run <code>configure</code>.</p> - -<h2 id="Building_your_application">Building your application</h2> - -<p>While "How to build your complete application" is clearly out of scope for this document, here are some tips that will help get you on your way:</p> - -<ul> - <li>The SpiderMonkey developers frequently and deliberately change the JSAPI ABI. You cannot use headers built for one version/configuration of JSAPI to create object files which will be linked against another.</li> - <li>Support for JS_THREADSAFE was recently removed, and threadsafe builds are now enabled by default.</li> - <li>The <code>js-config</code> script, described below, is the recommended way to determine correct include paths, required libraries, etc. for your embedding to use during compilation. We highly recommend calling the <code>js-config</code> script from your embedding's makefile to set your CFLAGS, LDFLAGS, and so forth.</li> - <li>To install SpiderMonkey somewhere other than the default, you must use the <code>configure</code> <code>--prefix</code> option, as described above. Failure to do so may break your <code>js-config.h</code> header or <code>js-config</code> script.</li> - <li>Some features detected by the <code>configure</code> script do not work for cross-compilation.</li> -</ul> - -<h3 id="Using_the_js-config_script">Using the js-config script</h3> - -<p>In addition to the SpiderMonkey libraries, header files, and shell, the SpiderMonkey build also produces a shell script named <code>js-config</code> which other build systems can use to find out how to compile code using the SpiderMonkey APIs, and how to link with the SpiderMonkey libraries.</p> - -<div class="note"><strong>Note:</strong> In SpiderMonkey 1.8.5, the js-config script is not generated properly on many platforms. If the instructions below do not work, you can try this <a href="/en/SpiderMonkey/1.8.5#js-config" title="https://developer.mozilla.org/en/SpiderMonkey/1.8.5#js-config">workaround</a>.</div> - -<p>When invoked with the <code>--cflags</code> option, <code>js-config</code> prints the flags that you should pass to the C compiler when compiling files that use the SpiderMonkey API. These flags ensure the compiler will find the SpiderMonkey header files.</p> - -<pre class="eval">$ ./js-config --cflags # Example output: -I/usr/local/include/js -I/usr/include/nspr -</pre> - -<p>When invoked with the <code>--libs</code> option, <code>js-config</code> prints the flags that you should pass to the C compiler when linking an executable or shared library that uses SpiderMonkey. These flags ensure the compiler will find the SpiderMonkey libraries, along with any libraries that SpiderMonkey itself depends upon (like NSPR).</p> - -<pre class="eval">$ ./js-config --libs # Example output: -L/usr/local/lib -lmozjs -L/usr/lib -lplds4 -lplc4 -lnspr4 -lpthread -ldl -ldl -lm -lm -ldl</pre> - -<h2 id="Test" name="Test">Testing SpiderMonkey</h2> - -<ul> - <li> - <p>Run <code>${BUILDDIR}/dist/bin/js </code><code>Y.js</code> and check if appropriate output is printed. (It should say: <code>5! is 120</code>.)</p> - </li> - <li> - <p>Run the main test suite by running <code>./tests/jstests.py ${BUILDDIR}/dist/bin/js</code></p> - </li> - <li> - <p>Run JIT-specific tests by running: <code>./jit-test/jit_test.py ${BUILDDIR}/dist/bin/js</code></p> - </li> -</ul> - -<h2 id="Building_SpiderMonkey_1.8_or_earlier">Building SpiderMonkey 1.8 or earlier</h2> - -<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.286em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;">Use these instructions to build SpiderMonkey from an official source release or from the old CVS repository. To build the latest SpiderMonkey sources from Mercurial, see <a href="#Building_SpiderMonkey_tip" style="text-decoration: none; color: rgb(51, 102, 153) !important; cursor: default;">Building SpiderMonkey </a>above.</p> - -<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.286em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;"><a href="/en/SpiderMonkey" style="text-decoration: none; color: rgb(51, 102, 153) !important; cursor: default;" title="en/SpiderMonkey">SpiderMonkey</a> is easy to build from source if you have the usual Mozilla build prerequisites installed. Before you begin, make sure you have right build tools for your computer: <a href="/en/Developer_Guide/Build_Instructions/Linux_Prerequisites" style="text-decoration: none; color: rgb(51, 102, 153) !important; cursor: default;" title="en/Linux_Build_Prerequisites">Linux</a>, <a href="/en/Developer_Guide/Build_Instructions/Windows_Prerequisites" style="text-decoration: none; color: rgb(51, 102, 153) !important; cursor: default;" title="en/Windows_Build_Prerequisites">Windows</a>, <a href="/en/Developer_Guide/Build_Instructions/Mac_OS_X_Prerequisites" style="text-decoration: none; color: rgb(51, 102, 153) !important; cursor: default;" title="en/Mac_OS_X_Build_Prerequisites">Mac</a>, <a href="/en/Developer_Guide/Build_Instructions" style="text-decoration: none; color: rgb(51, 102, 153) !important; cursor: default;" title="en/Build_Documentation">others</a>.</p> - -<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.286em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;">First, download a SpiderMonkey source distribution, such as <a class="external" href="http://ftp.mozilla.org/pub/mozilla.org/js/js-1.8.0-rc1.tar.gz" style="text-decoration: none; color: rgb(51, 102, 153) !important; cursor: default;">SpiderMonkey 1.8 Release Candidate 1</a>.</p> - -<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.286em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;">To build, use these commands:</p> - -<pre class="eval" style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.286em; margin-left: 0px; padding-top: 15px; padding-right: 15px; padding-bottom: 15px; padding-left: 15px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; background-clip: initial; background-color: rgb(246, 246, 242); font: normal normal normal 100%/normal 'Courier New', 'Andale Mono', monospace;">tar xvzf js-1.8.0-rc1.tar.gz -cd js/src -make -f Makefile.ref -</pre> - -<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.286em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;">This builds a debug version of SpiderMonkey. All build files are created in a subdirectory named depending on your system (for example,<code style="font: normal normal normal 100%/normal 'Courier New', 'Andale Mono', monospace; color: inherit; font-weight: inherit;">Linux_All_DBG.OBJ</code> if you are on Linux). To install this build on your system, see <a class="external" href="http://ebixio.com/blog/2010/07/31/how-to-install-libjs-spidermonkey/" style="text-decoration: none; color: rgb(51, 102, 153) !important; cursor: default;" title="http://ebixio.com/blog/2010/07/31/how-to-install-libjs-spidermonkey/">SpiderMonkey installation instructions</a>.</p> - -<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.286em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;">To build an optimized (non-debug) version of SpiderMonkey:</p> - -<pre class="eval" style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.286em; margin-left: 0px; padding-top: 15px; padding-right: 15px; padding-bottom: 15px; padding-left: 15px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; background-clip: initial; background-color: rgb(246, 246, 242); font: normal normal normal 100%/normal 'Courier New', 'Andale Mono', monospace;">make BUILD_OPT=1 -f Makefile.ref</pre> - -<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.286em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;">To build a <a href="/en/SpiderMonkey/JSAPI_Reference/JS_THREADSAFE" style="text-decoration: none; color: rgb(51, 102, 153) !important; cursor: default;" title="JS_THREADSAFE">thread-safe</a> version of SpiderMonkey:</p> - -<pre class="eval" style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.286em; margin-left: 0px; padding-top: 15px; padding-right: 15px; padding-bottom: 15px; padding-left: 15px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: dotted; border-right-style: dotted; border-bottom-style: dotted; border-left-style: dotted; background-clip: initial; background-color: rgb(246, 246, 242); font: normal normal normal 100%/normal 'Courier New', 'Andale Mono', monospace;">make JS_DIST=/full/path/to/directory/containing/nspr JS_THREADSAFE=1 -f Makefile.ref -</pre> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/comparision_of_js_engines/index.html b/files/zh-cn/mozilla/projects/spidermonkey/comparision_of_js_engines/index.html deleted file mode 100644 index 934e38ad7a..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/comparision_of_js_engines/index.html +++ /dev/null @@ -1,105 +0,0 @@ ---- -title: JS 引擎比较 -slug: Mozilla/Projects/SpiderMonkey/Comparision_of_JS_engines ---- -<h2 id="概述">概述</h2> -<p>本页用来纪录各个开源 JS 引擎(SpiderMonkey、V8、JavaScriptCore)在算法、未来趋势上的比较。除非额外说明,内存相关的数据<strong>假设系统为 32 位</strong>。</p> -<h2 id="类、函数、词汇比较表">类、函数、词汇比较表</h2> -<p>为了让懂得其中一个 JS 引擎的程序员迅速了解另外一个引擎,以下整理这些引擎共同概念的实现比较(把鼠标放在类/函数上面可以找到定义该类/函数的文件):</p> -<h3 id="常见">常见</h3> -<table class="standard-table"> - <thead> - <tr> - <th scope="col">SpiderMonkey</th> - <th scope="col">V8</th> - <th scope="col">备注</th> - </tr> - </thead> - <tbody> - <tr> - <td><a href="http://hg.mozilla.org/mozilla-central/file/73eefb421e2a/js/public/Value.h#l872" title="public/Value.h:JS::Value"><code>Value</code></a></td> - <td><a href="http://code.google.com/p/v8/source/browse/branches/bleeding_edge/src/objects.h?r=19048#930" title="src/objects.h:v8::internal::MaybeObject *"><code style="white-space: nowrap;">MaybeObject *</code></a></td> - <td>代表一个 JS 值(数值、字符串、对象……)的类。SpiderMonkey 是用 <a href="http://wingolog.org/archives/2011/05/18/value-representation-in-javascript-implementations">nun-boxing</a>,总是一个 <code>double</code> 的大小(因此在 32 位的系统下,传值需要<a href="http://hg.mozilla.org/mozilla-central/file/73eefb421e2a/js/src/jit/RegisterSets.h#l88">两个 cycle</a>)。V8 是用 <a href="https://github.com/oupengsoftware/v8/wiki/Memory-Layout#wiki-tagged-pointer">tagged pointer</a>,总是一个指针的大小,浮点数存在堆上。<code>MaybeObject</code> 还是很多非 JS 语言对象(代码块等等)的<a href="http://sphinx.oupeng.com/wp-content/uploads/2013/07/v8-class-hierarchy.html">父类</a>。</td> - </tr> - <tr> - <td> <a href="http://hg.mozilla.org/mozilla-central/file/f550b112a19b/js/src/vm/ObjectImpl.h#l685" title="src/vm/ObjectImpl.h:js::ObjectImpl"><code>ObjectImpl</code></a></td> - <td><a href="http://code.google.com/p/v8/source/browse/branches/bleeding_edge/src/objects.h?r=19048#2089" title="src/objects.h:v8::internal::JSObject"><code>JSObject</code></a></td> - <td>JS 对象(<code>obj instanceof Object</code>)的实现类。SpiderMonkey 与 V8 皆是把部分属性存放在对象行内,部分用外链的一个数组储存的模式。SpiderMonkey 也将小数组的数据存在行内(但是<a href="http://hg.mozilla.org/mozilla-central/file/f550b112a19b/js/src/jsgc.h#l258">不会分两半</a>),而 V8 的 JS 数组对象(貌似)都是将数据存在外链的数组上。在 SpiderMonkey 中,只有在 new space 的 JS 对象的外链数组的空间由虚拟机分配,其他情况的外链数组的空间<a href="http://hg.mozilla.org/mozilla-central/file/f550b112a19b/js/src/gc/Nursery.cpp#l582">由 <code>malloc</code> 分配</a>(因此内存会比较分裂?)。<code>ObjectImpl</code> 除了有连接到 <code>Shape</code> 的指针之外,还有一个链到 <code>TypeObject</code> 的指针:16 B(<code>ObjectImpl</code>)vs. 12 B(<code>JSObject</code>)。在 SpiderMonkey 中,数据用 <code>Value</code> 存,也就是说,对于一个有 <em>k</em> 个行内属性的 JS 对象来说,内存占用是:16 B + <em>k</em> * 8 B(<code>ObjectImpl</code>)vs. 12 B + <em>k</em> * 4 B(<code>JSObject</code>),行外的情形 V8 则会再多用 8 B(<code>FixedArray</code> 的标头)。</td> - </tr> - <tr> - <td><span style="white-space: nowrap;"><a href="http://hg.mozilla.org/mozilla-central/file/f550b112a19b/js/src/vm/Shape.h#l37" title="src/vm/Shape.h:js::Shape"><code>Shape</code></a>、<code><a href="http://hg.mozilla.org/mozilla-central/file/f550b112a19b/js/src/jsinfer.h#l868" title="src/jsinfer.h:js::types::TypeObject">TypeObject</a>、</code><a href="http://hg.mozilla.org/mozilla-central/file/73eefb421e2a/js/public/Class.h#l590" title="public/Class.h::js::Class"><code>Class</code></a></span></td> - <td><a href="http://code.google.com/p/v8/source/browse/branches/bleeding_edge/src/objects.h?r=19048#5769" title="src/objects.h:v8::internal::Map"><code>Map</code></a></td> - <td>隐藏类的实现类。在 SpiderMonkey 中,属性名存在 <code>Shape</code> 上(因此带有 V8 的 <code>DescriptorArray</code> 的作用),JS 对象的原型存在 <code>TypeObject</code> 上,特殊属性的处理方法存在 <code>Class</code> 上(<code>Class</code> 对象不是 JS 堆里的对象,大部分都共用:<code>JSObject::class_</code>、<code>JSFunction::class_……</code>)。由于 V8 的 <code>Map</code> 有 SM 三个类的作用,因此占用内存也比较多:24 B(<code>Shape</code>)vs. 40 B(<code>Map</code>)。</td> - </tr> - </tbody> -</table> -<h3 id="内存布局与对象创建">内存布局与对象创建</h3> -<h3 id="运行时">运行时</h3> -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">SpiderMonkey</th> - <th scope="col">V8</th> - <th scope="col">备注</th> - </tr> - <tr> - <td><code>Interpret</code></td> - <td><code style="white-space: nowrap;">(无)</code></td> - <td>解释器的主回圈。V8 没有字节码与解释器。</td> - </tr> - </tbody> -</table> -<h3 id="堆与_GC">堆与 GC</h3> -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">SpiderMonkey</th> - <th scope="col">V8</th> - <th scope="col">备注</th> - </tr> - <tr> - <td><code>Nursery</code></td> - <td><code style="white-space: nowrap;">NewSpace</code></td> - <td> </td> - </tr> - </tbody> -</table> -<h2 id="调优">调优</h2> -<p>一个容易调优的 JS 引擎应该具备有以下条件(从重要的到不重要的):</p> -<ul> - <li>能透过 profiler 够找到应用的热点函数(当前内联过的函数是怎么处理的?)。</li> - <li>调整各个常量方便。</li> - <li>能(透过内置函数扩展等等)得到以下影响性能的数据: - <ul> - <li>内联缓存(inline cache)中缓存的隐藏类个数。</li> - <li>函数运行状态(哪个阶段的 JIT?)与机械码。</li> - <li>一个 JS 函数已内联的函数。</li> - <li>一个 JS 函数调用运行时 C++ 函数的个数。</li> - <li>一段时间中 CPU 运行的指令个数与种类(SpiderMonkey 里有个 <code>PerfMeasurement</code>,这个好用么?)。</li> - </ul> - </li> - <li>能得到 bailout 的原因。</li> - <li>代码易读,容易调试。</li> -</ul> -<h2 id="参见">参见</h2> -<ul> - <li><a href="http://arewefastyet.com/">ARE WE FAST YET</a> — 每天更新的 JS 引擎性能比较(使用 kraken、sunspider、octane 三个 benchmark)。</li> - <li><a href="http://openaphid.github.io/blog/2013/01/17/part-i-how-to-choose-a-javascript-engine-for-ios-and-android-apps/">How to Choose a JavaScript Engine for iOS and Android Development</a> — 不太具有技术分析的文章,不过有一个各类似 Phonegap 的产品用什么 JS 引擎的列表。</li> - <li><a href="http://hllvm.group.iteye.com/group/topic/37596">各JavaScript引擎的简介,及相关资料/博客收集帖</a> — R 大经典的整理帖,下面有一个比较高层级的各引擎比较表。</li> -</ul> -<p>跟 “JS 引擎” 比较无关,但是中文的 JS 引擎相关的博文也比较少,这里搜集一下:</p> -<ul> - <li><a href="http://hellocompiler.com/">编译路慢慢</a> — SpiderMonkey 相关的比较多。</li> -</ul> -<h2 id="代码美观">代码美观</h2> -<p><em>这件事实在</em><em>不应该是决定使用哪个 JS 引擎的因素,不过……</em></p> -<p>如果(不幸的)需要以 SpiderMonkey 作为基础调优则会碰到以下问题:</p> -<ol> - <li>C 与 C++ 代码混用。SpiderMonkey 原先是 C 写成的,后来大规模的以 C++ 改进,但是留下了很多残骸:宏、不是宏但是名称是大写的函数。(参见 <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_Reference/JS::Value"><code>JS::Value</code></a> 的说明。)</li> - <li>成员变量、方法命名缺乏规则<code>。ObjectImpl::slots</code> 与 <code>ObjectImpl::shape_</code> 同时存在(前面那个应该加底线)。这个或许是可以修复的 bug。</li> - <li>混入 JavaScriptCore、V8 代码。SpiderMonkey 的组译器是 JavaScriptCore 的,那些类的成员变量是 <code>m_buffer</code> 等等,又增加了成员变量命名的。另外还有 <code>WTF_*</code> 宏,真是 WTF。再批。妈的,<a href="http://hg.mozilla.org/mozilla-central/file/262e73a6b7cd/js/src/assembler/wtf/Platform.h#l344"><code>WTF_CPU_ARM_THUMB2</code> 跟本不可能为真</a>,这里有大量的死代码(所有代码完全没有用到 <code>JSC::</code><code>MacroAssembler</code>,用到的是 <code>js::jit::</code><code><code>MacroAssembler</code></code>)。另外,</li> - <li>混乱的名称空间。</li> - <li><code>struct</code>、<code>class</code> 混用。</li> - <li>文档命名缺少规则。C 时代的档名是 <code>jsobj.h</code>,C++ 时代的档名是 <code>Value.h</code> 。请自重。</li> - <li>过渡滥用宏。</li> -</ol> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/index.html b/files/zh-cn/mozilla/projects/spidermonkey/index.html deleted file mode 100644 index 468fafa0cb..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/index.html +++ /dev/null @@ -1,132 +0,0 @@ ---- -title: SpiderMonkey -slug: Mozilla/Projects/SpiderMonkey -tags: - - SpiderMonkey - - Update -translation_of: Mozilla/Projects/SpiderMonkey ---- -<p><strong>SpiderMonkey</strong> 是Mozilla使用C/C++编写的<a href="/zh-cn/JavaScript" title="zh-cn/JavaScript">JavaScript</a> 引擎。它被用于包括Firefox在内的多个Mozilla产品中,使用的<span class="st">是MPL 2授权协议.</span></p> - -<p>独立的源代码版本可以在<a href="https://developer.mozilla.org/zh-CN/docs/Mozilla/Projects/SpiderMonkey/Releases">发布页</a>上找到</p> - -<table class="topicpage-table"> - <tbody> - <tr> - <td> - <h3 id="Documentation" name="Documentation">文档</h3> - - <table> - <tbody> - <tr> - <td colspan="2"> - <h4 id="General">General</h4> - </td> - </tr> - <tr> - <td><a href="/zh-CN/docs/Mozilla/Projects/SpiderMonkey/Build_Documentation" title="zh-CN/docs/Mozilla/Projects/SpiderMonkey/Build_Documentation">SpiderMonkey Build Documentation</a></td> - <td>如何获取到SpiderMonkey源代码,编译,并运行测试套.</td> - </tr> - <tr> - <td><a href="/zh-cn/SpiderMonkey/Introduction_to_the_JavaScript_shell" title="zh-cn/Introduction_to_the_JavaScript_shell">Introduction to the JavaScript shell</a></td> - <td>如何获取,构建,并使用JavaScript shell.</td> - </tr> - <tr> - <td><a href="/zh-cn/SpiderMonkey/Running_Automated_JavaScript_Tests" title="zh-cn/SpiderMonkey/Running Automated JavaScript Tests">Running Automated JavaScript Tests</a></td> - <td>如何运行JavaScript测试套件.</td> - </tr> - <tr> - <td><a href="/zh-cn/SpiderMonkey/Creating_JavaScript_tests" title="zh-cn/SpiderMonkey/Creating JavaScript tests">Creating JavaScript tests</a></td> - <td>如何为JavaScript测试套件添加测试.</td> - </tr> - <tr> - <td><a class="link-https" href="https://wiki.mozilla.org/JavaScript:New_to_SpiderMonkey" title="https://wiki.mozilla.org/JavaScript:New_to_SpiderMonkey">New to SpiderMonkey</a></td> - <td>SpiderMonkey的hacking指南.</td> - </tr> - <tr> - <td><a href="/zh-cn/SpiderMonkey/Setting_up_CDT_to_work_on_SpiderMonkey" title="zh-cn/SpiderMonkey/Setting up CDT to work on SpiderMonkey">Setting up CDT to work on SpiderMonkey</a></td> - <td>如何配置CDT,使之在SpiderMonkey代码上工作.</td> - </tr> - <tr> - <td colspan="2"> - <h4 id="JSAPI">JSAPI</h4> - </td> - </tr> - <tr> - <td><a href="/zh-cn/SpiderMonkey/JSAPI_User_Guide" title="zh-cn/JSAPI_User_Guide">JSAPI User Guide</a></td> - <td>本指南简要介绍了SpiderMonkey,还介绍了如何可以将SpiderMonkey嵌入到你的应用程序中.</td> - </tr> - <tr> - <td><a href="/zh-cn/SpiderMonkey/JSAPI_Cookbook" title="zh-cn/SpiderMonkey/JSAPI_Phrasebook">JSAPI Phrasebook</a></td> - <td>一些常用的JavaScript表达式和语句的JSAPI翻译.</td> - </tr> - <tr> - <td><a href="/zh-cn/SpiderMonkey/JSAPI_Reference" title="zh-cn/SpiderMonkey/JSAPI_Reference">JSAPI Reference</a></td> - <td>SpiderMonkey API 参考.</td> - </tr> - <tr> - <td><a href="/zh-cn/SpiderMonkey/Bytecodes" title="zh-cn/SpiderMonkey/Bytecodes">Bytecode Reference</a></td> - <td>SpiderMonkey 字节码参考.</td> - </tr> - <tr> - <td><a href="/zh-cn/SpiderMonkey/JS_Debugger_API_Guide" title="zh-cn/SpiderMonkey/JS Debugger API Guide">JS Debugger API Guide</a></td> - <td>在Gecko 8.0中引入的新的JavaScript调试器API{{ geckoRelease("8.0") }}.</td> - </tr> - <tr> - <td><a href="/zh-cn/SpiderMonkey/JS_Debugger_API_Reference" title="zh-cn/SpiderMonkey/JS Debugger API Reference">JS Debugger API Reference</a></td> - <td>SpiderMonkey 1.8.6(Gecko 8.0 )中引入的<code>Debugger</code>对象的API参考, {{ geckoRelease("8.0") }}.</td> - </tr> - <tr> - <td><a href="/zh-cn/JSDBGAPI_Reference" title="zh-cn/JSDBGAPI_Reference">JSDBGAPI Reference</a></td> - <td> - <p>SpiderMonkey调试API参考;SpiderMonkey 1.8.5之前版本的调试API,<small> </small>虽然它并没有被删除.</p> - </td> - </tr> - <tr> - <td colspan="2"> - <h4 id="提示技巧和理念">提示,技巧和理念</h4> - </td> - </tr> - <tr> - <td><a href="/zh-cn/How_to_embed_the_JavaScript_engine" title="zh-cn/How_to_embed_the_JavaScript_engine">How to embed the JavaScript engine</a></td> - <td>如何嵌入SpiderMonkey的基础教程</td> - </tr> - <tr> - <td><a href="/zh-cn/SpiderMonkey_Garbage_Collection_Tips" title="zh-cn/SpiderMonkey_Garbage_Collection_Tips">SpiderMonkey Garbage Collection Tips</a></td> - <td>如何避免垃圾回收时出现的问题.</td> - </tr> - <tr> - <td><a href="/zh-cn/SpiderMonkey/Internals" title="zh-cn/SpiderMonkey_Internals">SpiderMonkey Internals</a></td> - <td><span class="short_text" id="result_box" lang="zh-CN"><span>设计</span><span>概况</span></span>和实现版本介绍</td> - </tr> - <tr> - <td><a href="/zh-cn/SpiderMonkey/Internals/Garbage_collection" title="zh-cn/SpiderMonkey/Internals/GC">SpiderMonkey Internals: GC</a></td> - <td>关于垃圾回收的独立的内部文章.</td> - </tr> - <tr> - <td><a href="/zh-cn/SpiderMonkey/Internals/Thread_Safety" title="zh-cn/SpiderMonkey_Internals/Thread_Safety">SpiderMonkey Internals: Thread Safety</a></td> - <td>SpiderMonkey的请求模型的内部工作原理.</td> - </tr> - </tbody> - </table> - </td> - <td> - <h3 id="Related_Topics" name="Related_Topics">相关链接</h3> - - <ul> - <li><a href="/zh-cn/JavaScript" title="zh-cn/JavaScript">JavaScript</a></li> - <li><a href="/zh-cn/SpiderMonkey/FOSS" title="zh-cn/SpiderMonkey/FOSS">FOSS projects using / based on Spidermonkey</a></li> - </ul> - - - <h3 id="Community" name="Community">社区</h3> - - <p>有问题? <a class="link-irc" href="irc://irc.mozilla.org/jsapi">在IRC上提问!</a></p> - - <p>查看 <a class="external" href="http://infomonkey.cdleary.com/" title="http://infomonkey.cdleary.com/">Infomonkey</a>.</p> - - <p>有bug? <a class="link-https" href="https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=JavaScript%20Engine" title="https://bugzilla.mozilla.org/enter_bug.cgi?product=Core&component=JavaScript Engine">提交bug</a> 到 <a class="link-https" href="https://bugzilla.mozilla.org/buglist.cgi?product=Core&component=JavaScript%20Engine&resolution=---&list_id=92318" title="https://bugzilla.mozilla.org/buglist.cgi?product=Core&component=JavaScript Engine&resolution=---&list_id=92318">Core -> JavaScript Engine</a></p> - </td> - </tr> - </tbody> -</table> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/internals/bytecodes/index.html b/files/zh-cn/mozilla/projects/spidermonkey/internals/bytecodes/index.html deleted file mode 100644 index 7c47ffb7ae..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/internals/bytecodes/index.html +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: 字节码 -slug: Mozilla/Projects/SpiderMonkey/Internals/Bytecodes -tags: - - SpiderMonkey -translation_of: Mozilla/Projects/SpiderMonkey/Internals/Bytecodes ---- -<div>{{SpiderMonkeySidebar("Internals")}}</div> - -<h2 id="背景知识">背景知识</h2> - -<p>SpiderMonkey字节码是JavaScript引擎使用的标准代码表示形式。JavaScript前端根据源文本构建AST,然后根据JSScript数据结构的一部分从AST生成基于堆栈的字节码。字节码可以引用原子和对象(通常通过数组索引),这些原子和对象也包含在JSScript数据结构中。</p> - -<p>在引擎内,所有字节码都在堆栈帧内执行。堆栈帧与全局(顶级)代码和<code>eval</code>代码相关联。堆栈上的框架为几个不同类别的JavaScript值(标记值格式)留出空间。单个JavaScript值空间称为“插槽”,类别为:</p> - -<ul> - <li>参数槽:保存传递给当前框架的实际参数。</li> - <li>本地插槽:保存当前代码中使用的本地变量。</li> - <li>表达式槽:保存在堆栈上计算表达式所需的临时空间。例如,<code>(a + b) + c</code>会压入a,然后压入b,再压入+,然后压入c,再压入+,依此类推。这需要最多两个表达槽的深度。</li> -</ul> - -<p>还有一些保留给专用功能的插槽,用于处理<code>this</code>和<code>callee</code>返回值。.</p> - -<p>总有一个“堆栈顶部”(TOS),它对应于推入表达式堆栈的最新值。所有字节码都根据该位置隐式运行。</p> - -<h2 id="字节码列表">字节码列表</h2> - -<p>所有操作码都用<code> [-popcount, +pushcount] </code>标注,以表示整个执行的堆栈效果。</p> - -<p>字节码列表已移至 <a href="/en-US/docs/Mozilla/Projects/SpiderMonkey/Internals/Bytecode" title="SpiderMonkey Internals: Bytecode Descriptions">SpiderMonkey Internals: Bytecode Descriptions</a> 页面。</p> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/internals/functions/index.html b/files/zh-cn/mozilla/projects/spidermonkey/internals/functions/index.html deleted file mode 100644 index 91d96b22eb..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/internals/functions/index.html +++ /dev/null @@ -1,73 +0,0 @@ ---- -title: Functions -slug: Mozilla/Projects/SpiderMonkey/Internals/Functions -translation_of: Mozilla/Projects/SpiderMonkey/Internals/Functions ---- -<div>{{SpiderMonkeySidebar("Internals")}}</div> - -<p>There are several flavors of JavaScript function. All are <code>JSObject</code>s of the same class, <code>js_FunctionClass</code>.</p> - -<p>这里有些Javscript函数,它们属于JSObjects</p> - -<p>(But note that objects of other classes can be callable and can even have <code>typeof obj == "function"</code>.)</p> - -<p>(也存在其他可被Call的对象)</p> - -<h2 id="Script_functions">Script functions</h2> - -<p>Functions written in JavaScript and compiled to bytecode. There are four variations that affect how NameExpressions are evaluated. (NameExpressions are basic expressions like <code>String</code> and <code>x</code> that would eat up a huge amount of run time if the engine weren't smart enough to avoid symbol table lookups.)</p> - -<p><strong>General closures</strong> are the base case. When the function object is created, its parent is set to the first object on the scope chain. When a name is evaluated that doesn't refer to a local variable, the interpreter consults the scope chain to find the variable. When <code>with</code> or <code>eval</code> are used, we have to do this for correctness.</p> - -<p>This is slow, not only because walking the scope chain is a drag, but also because we'd rather avoid actually creating the scope chain at all, if possible. General closures force the interpreter to verify the whole scope chain. So we optimize this when we can.</p> - -<p>These optimizations depend on being <em>sure</em> that we will never have to walk the scope chain, so <code>with</code> and <code>eval</code> inhibit them all.</p> - -<p><strong>Null closures.</strong> If we can prove at compile time that a function does not refer to any locals or arguments of enclosing functions, it is a null closure. Since it will never need to walk the scope chain, its parent is the global object. This is the best case. Barring <code>with</code> and <code>eval</code>, all outermost functions are null closures.</p> - -<p><strong>Null closures with upvars.</strong> A nested function is <em>algol-like</em> if it is only ever defined and called, and it isn't accessed in any other way (and it is not a generator-function). Such a function is guaranteed never to be called again after the enclosing function exits. An algol-like function may read the local variables and arguments of its immediate enclosing function from the stack, as if by magic. (<code>JSContext::display</code> caches the enclosing function's stack frame.) If that function is also algol-like, its child can read locals and variables from the next enclosing function, and so on. The compiler detects these cases and makes such functions null closures too.</p> - -<p><strong>Flat closures.</strong> Suppose a function reads some variables from enclosing functions but is not algol-like. If the function does not assign to any closed-on vars/args, and it only reads closed-on local variables and arguments that never change value after the function is created, then the function can be implemented as a flat closure. When a flat closure is created, all the closed-on values are copied from the stack into reserved slots of the function object. To evaluate a name, instead of walking the scope chain, we just take the value from the reserved slot. The function object's parent is the global object.</p> - -<p><strong>Flat closures </strong><strong>and Null closures have been <span id="summary_alias_container"><span id="short_desc_nonedit_display">removed</span></span></strong>:</p> - -<p><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=730497">https://bugzilla.mozilla.org/show_bug.cgi?id=730497</a></p> - -<p><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=739808">https://bugzilla.mozilla.org/show_bug.cgi?id=739808</a></p> - -<h2 id="Name_lookups">Name lookups</h2> - -<p>In order of speed, fastest to slowest.</p> - -<ol> - <li> - <p><code><strong>ARG</strong></code><strong> and <code>LOCAL</code> instructions.</strong> If a name definitely refers to an argument or local variable of the immediately enclosing function, it can be accessed using <code>JSOP_{GET,SET,CALL}</code><code>{ARG,LOCAL}</code> instructions. Some of these can even be fused with other operations into combo instructions like <code>JSOP_GETARGPROP</code>, <code>JSOP_FORLOCAL</code>, and <code>JSOP_INCLOCAL</code>. Because arguments and locals can't be deleted, this optimization is available to all functions, and <code>eval</code> does not interfere with it. But a <code>with</code> block can:</p> - - <pre>function f(s) { - eval(s); - print(s); // s can be loaded with GETARG - with (obj) { - print(s); // no GETARG here; s might refer to obj.s - } -} -</pre> - </li> - <li> - <p><code><strong>UPVAR</strong></code><strong> instructions.</strong> JSOP_{GET,CALL}UPVAR (in algol-like functions only, I think?) TODO</p> - </li> - <li> - <p><code><strong>DSLOT</strong></code><strong> instructions.</strong> JSOP_{GET,CALL}DSLOT (in flat closures only) TODO</p> - </li> - <li> - <p><code><strong>GVAR</strong></code><strong> instructions.</strong> Outside all functions, if a name definitely refers to a global for which we have seen a var, <code>const</code>, or <code>function</code> declaration, then we emit a JS_DEFVAR instruction in the script prelude and access the global using <code>JSOP_{GET,SET,CALL}GVAR</code>. This is fast if the global either doesn't exist before the script runs (the script creates it) or it's a non-configurable data property (which amounts to the same thing). Otherwise the <code>GVAR</code> instructions are as slow as <code>NAME</code> instructions.</p> - - <p>There are also combo instructions <code>JSOP_{INC,DEC}GVAR</code> and <code>JSOP_GVAR{INC,DEC}</code>.</p> - </li> - <li> - <p><code><strong>NAME</strong></code><strong> instructions.</strong> In the worst case we emit <code>JSOP_{,SET,CALL}NAME</code>. These are totally general. They can still be optimized via the property cache; in the worst case we walk the scope chain.</p> - - <p>In some cases, the JIT can optimize a <code>JSOP_NAME</code> instruction that refers to a variable in an enclosing scope to pull the value directly out of the <code>Call</code> object's <code>dslots</code>.</p> - - <p>For the expression <code>delete name</code> we always emit <code>JSOP_DELNAME</code>. It's not worth optimizing.</p> - </li> -</ol> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/internals/index.html b/files/zh-cn/mozilla/projects/spidermonkey/internals/index.html deleted file mode 100644 index 03228c312f..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/internals/index.html +++ /dev/null @@ -1,292 +0,0 @@ ---- -title: SpiderMonkey Internals -slug: Mozilla/Projects/SpiderMonkey/Internals -tags: - - Guide - - JavaScript - - NeedsMarkupWork - - NeedsTranslation - - SpiderMonkey - - TopicStub -translation_of: Mozilla/Projects/SpiderMonkey/Internals ---- -<h2 id="Design_walk-through" name="Design_walk-through">Design walk-through</h2> - -<p>At heart, SpiderMonkey is a fast interpreter that runs an untyped bytecode and operates on values of type <code><a href="/en-US/docs/SpiderMonkey/JSAPI_Reference/Jsval" title="SpiderMonkey/JSAPI_Reference/Jsval">jsval</a></code>—type-tagged double-sized values that represent the full range of JavaScript values. In addition to the interpreter, SpiderMonkey contains a Just-In-Time (JIT) compiler, a garbage collector, code implementing the basic behavior of JavaScript values, a standard library implementing <span class="pl-s1"><span class="pl-s">ECMA 262-3 §</span></span>15 with various extensions, and a few public APIs.</p> - -<h3 id="Interpreter">Interpreter</h3> - -<p>Like many portable interpreters, SpiderMonkey's interpreter is mainly a single, tremendously long function that steps through the bytecode one instruction at a time, using a <code>switch</code> statement (or faster alternative, depending on the compiler) to jump to the appropriate chunk of code for the current instruction. A JS-to-JS function call pushes a JavaScript stack frame without growing the C stack. But since JS-to-C-to-JS call stacks are common, the interpreter is reentrant.</p> - -<p>Some SpiderMonkey bytecode operations have many special cases, depending on the type of their arguments. Common cases are inlined in the interpreter loop, breaking any abstractions that stand in the way. So optimizations such as dense arrays and the property cache are, alas, <em>not</em> transparently tucked away in the <code>jsarray.*</code> and <code>jsobj.*</code> files. Both guest-star in <code>jsinterp.cpp</code> (to thunderous applause from Firefox users).</p> - -<p>All state associated with an interpreter instance is passed through formal parameters to the interpreter entry point; most implicit state is collected in a type named <code><a href="/en-US/docs/SpiderMonkey/JSAPI_Reference/JSRuntime" title="SpiderMonkey/JSAPI_Reference/JSRuntime">JSContext</a></code>. Therefore, almost all functions in SpiderMonkey, API or not, take a <code>JSContext</code> pointer as their first argument.</p> - -<h3 id="Compiler">Compiler</h3> - -<p>The compiler consumes JavaScript source code and produces a <em>script</em> which contains bytecode, source annotations, and a pool of string, number, and identifier literals. The script also contains objects, including any functions defined in the source code, each of which has its own, nested script.</p> - -<p>The compiler consists of: a random-logic rather than table-driven lexical scanner, a recursive-descent parser that produces an AST, and a tree-walking code generator. Semantic and lexical feedback are used to disambiguate hard cases such as missing semicolons, assignable expressions ("lvalues" in C parlance), and whether <code>/</code> is the division symbol or the start of a regular expression. The compiler attempts no error recovery; it bails out on the first error. The emitter does some constant folding and a few codegen optimizations; about the fanciest thing it does is to attach source notes to the script for the decompiler's benefit.</p> - -<p>The decompiler implements <code>Function.toSource()</code>, which reconstructs a function's source code. It translates postfix bytecode into infix source by consulting a separate byte-sized code, called <em>source notes</em>, to disambiguate bytecodes that result from more than one grammatical production.</p> - -<h3 id="Garbage_collector">Garbage collector</h3> - -<p>The GC is a mark-and-sweep, non-conservative (exact) collector. It is used to hold JS objects and string descriptors (but not property lists or string bytes), and double-precision floating point numbers. It runs automatically only when maxbytes (as passed to <code><a href="/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_NewRuntime" title="SpiderMonkey/JSAPI_Reference/JS_NewRuntime">JS_NewRuntime</a></code>) bytes of GC things have been allocated and another thing-allocation request is made. JS API users should call <code><a href="/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_GC" title="SpiderMonkey/JSAPI_Reference/JS_GC">JS_GC</a></code> or <code><a href="/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_MaybeGC" title="SpiderMonkey/JSAPI_Reference/JS_MaybeGC">JS_MaybeGC</a></code> between script executions or from the <a href="/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_SetBranchCallback" title="SpiderMonkey/JSAPI_Reference/JS_SetBranchCallback">branch callback</a>, as often as necessary.</p> - -<p>Because the GC is exact, C/C++ applications must ensure that all live objects, strings, and numbers are GC-reachable. Many techniques are available; see <a href="/en-US/docs/SpiderMonkey_Garbage_Collection_Tips" title="SpiderMonkey_Garbage_Collection_Tips">SpiderMonkey Garbage Collection Tips</a>.</p> - -<h3 id="JavaScript_values">JavaScript values</h3> - -<p>The type <code><a href="/en-US/docs/SpiderMonkey/JSAPI_Reference/Jsval" title="SpiderMonkey/JSAPI_Reference/Jsval">jsval</a></code> represents a JavaScript value.</p> - -<p>The representation is 64 bits and uses NaN-boxing on all platforms, although the exact NaN-boxing format depends on the platform. NaN-boxing is a technique based on the fact that in IEEE-754 there are 2**47 different bit patterns that all represent NaN. Hence, we can encode any floating-point value as a C++ <code>double </code>(noting that JavaScript NaN must be represented as one canonical NaN format). Other values are encoded as a value and a type tag:</p> - -<ul> - <li>On x86, ARM, and similar 32-bit platforms, we use what we call "nunboxing", in which non-<code>double </code>values are a 32-bit type tag and a 32-bit payload, which is normally either a pointer or a signed 32-bit integer. There are a few special values: <code><a href="/en-US/docs/SpiderMonkey/JSAPI_Reference/JSVAL_NULL" title="SpiderMonkey/JSAPI_Reference/JSVAL_NULL">JSVAL_NULL</a></code>, <code><a href="/en-US/docs/SpiderMonkey/JSAPI_Reference/JSVAL_VOID" title="SpiderMonkey/JSAPI_Reference/JSVAL_VOID">JSVAL_VOID</a></code> (<code>undefined</code>), <code><a href="/en-US/docs/SpiderMonkey/JSAPI_Reference/JSVAL_TRUE" title="SpiderMonkey/JSAPI_Reference/JSVAL_TRUE">JSVAL_TRUE</a></code>, and <code><a href="/en-US/docs/JSVAL_FALSE" title="JSVAL_FALSE">JSVAL_FALSE</a></code>. Another special value, <code><a href="/en-US/docs/JSVAL_HOLE" title="JSVAL_HOLE">JSVAL_HOLE</a></code>, is used internally only (to represent deleted <code>Array</code> elements, for example). This value is never exposed to scripts or even via the JSAPI.</li> - <li>On x64 and similar 64-bit platforms, pointers are longer than 32 bits, so we can't use the nunboxing format. Instead, we use "punboxing", which has 17 bits of tag and 47 bits of payload.</li> -</ul> - -<p>Only JIT code really depends on the layout--everything else in the engine interacts with values through functions like <code>JSVAL_IS_INT</code>. Most parts of the JIT also avoid depending directly on the layout: the files <code>PunboxAssembler.h</code> and <code>NunboxAssembler.h</code> are used to generate native code that depends on the value layout.</p> - -<p>Objects consist of a possibly shared structural description, called the map or scope; and unshared property values in a vector, called the slots. Each property has an <a href="/en-US/docs/SpiderMonkey/JSAPI_Reference/jsid" title="SpiderMonkey/JSAPI_Reference/jsid">id</a>, either a nonnegative integer or an atom (unique string), with the same tagged-pointer encoding as a <code>jsval</code>.</p> - -<p>The atom manager consists of a hash table associating strings uniquely with scanner/parser information such as keyword type, index in script or function literal pool, etc. Atoms play three roles: as literals referred to by unaligned 16-bit immediate bytecode operands, as unique string descriptors for efficient property name hashing, and as members of the root GC set for exact GC.</p> - -<h3 id="Standard_library">Standard library</h3> - -<p>The methods for arrays, booleans, dates, functions, numbers, and strings are implemented using the JS API. Most are <code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSNative" title="SpiderMonkey/JSAPI_Reference/JSFastNative">JSNative</a></code>s. Most string methods are customized to accept a primitive string as the <code>this</code> argument. (Otherwise, SpiderMonkey converts primitive values to objects before invoking their methods, per <span class="pl-s1"><span class="pl-s">ECMA 262-3 §</span></span>11.2.1.)</p> - -<h3 id="Error_handling">Error handling</h3> - -<p>SpiderMonkey has two interdependent error-handling systems: JavaScript exceptions (which are <em>not</em> implemented with, or even compatible with, any kind of native C/C++ exception handling) and error reporting. In general, both functions inside SpiderMonkey and JSAPI callback functions signal errors by calling <code><a href="/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_ReportError" title="SpiderMonkey/JSAPI_Reference/JS_ReportError">JS_ReportError</a></code> or one of its variants, or <code><a href="/en-US/docs/SpiderMonkey/JSAPI_Reference/JS_SetPendingException" title="SpiderMonkey/JSAPI_Reference/JS_SetPendingException">JS_SetPendingException</a></code>, and returning <code><a href="/en-US/docs/SpiderMonkey/JSAPI_Reference/JSBool" title="SpiderMonkey/JSAPI_Reference/JSBool">JS_FALSE</a></code> or <code>NULL</code>.</p> - -<h3 id="Public_APIs">Public APIs</h3> - -<p>The public C/C++ interface, called the JSAPI, is in most places a thin (but source-compatible across versions) layer over the implementation. See the <a href="/en-US/docs/SpiderMonkey/JSAPI_User_Guide" title="JSAPI_User_Guide">JSAPI User Guide</a>. There is an additional public API for JavaScript debuggers, <a href="/en-US/docs/JSDBGAPI_Reference" title="JSDBGAPI_Reference">JSDBGAPI</a>, but {{Source("js/jsd/jsdebug.h")}} might be a better API for debuggers. Another API, <a href="/en-US/docs/JSXDRAPI" title="JSXDRAPI">JSXDRAPI</a>, provides serialization for JavaScript scripts. (XUL Fastload uses this.)</p> - -<h3 id="Just-In-Time_compiler">Just-In-Time compiler</h3> - -<p>{{jsapi_minversion_inline("1.8.5")}} SpiderMonkey contains a just-in-time compiler, code-named <em>JägerMonkey</em>, that converts bytecode to machine code for faster execution. The JIT works by detecting commonly executed functions or functions containing hot loops and then compiling these methods into machine code.</p> - -<p>A second JIT, code-named <em>IonMonkey</em> was enabled in <a href="https://blog.mozilla.org/javascript/2012/09/12/ionmonkey-in-firefox-18/" title="https://blog.mozilla.org/javascript/2012/09/12/ionmonkey-in-firefox-18/">Firefox 18</a>.</p> - -<h3 id="Self-hosting_of_builtin_functions_in_JS">Self-hosting of builtin functions in JS</h3> - -<p>Starting with Firefox 17, SpiderMonkey has the ability to implement builtin functions in self-hosted JS code. This code is compiled in a special compilation mode that gives it access to functionality that's not normally exposed to JS code, but that's required for safe and specification-conformant implementation of builtin functions.</p> - -<p>All self-hosted code lives in <code>.js</code> files under <code>builtin/</code>. For details on implementing self-hosted builtins, see <a href="/en-US/docs/SpiderMonkey/Internals/self-hosting" title="SpiderMonkey/self-hosting">self-hosting</a>.</p> - -<h2 id="File_walkthrough" name="File_walkthrough">File walkthrough</h2> - -<h4 id="jsapi.cpp.2C_jsapi.h" name="jsapi.cpp.2C_jsapi.h">jsapi.cpp, jsapi.h</h4> - -<p>The public API to be used by almost all client code.</p> - -<h4 id="jspubtd.h.2C_jsprvtd.h" name="jspubtd.h.2C_jsprvtd.h">jspubtd.h, jsprvtd.h</h4> - -<p>These files exist to group struct and scalar typedefs so they can be used everywhere without dragging in struct definitions from N different files. The <code>jspubtd.h</code> file contains public typedefs, and is included automatically when needed. The <code>jsprvtd.h</code> file contains private typedefs and is included by various .h files that need type names, but not type sizes or declarations.</p> - -<h4 id="jsdbgapi.cpp.2C_jsdbgapi.h" name="jsdbgapi.cpp.2C_jsdbgapi.h">jsdbgapi.cpp, jsdbgapi.h</h4> - -<p>The debugging API. Provided so far:</p> - -<p><strong>Traps</strong>, with which breakpoints, single-stepping, step over, step out, and so on can be implemented. The debugger will have to consult jsopcode.def on its own to figure out where to plant trap instructions to implement functions like step out, but a future jsdbgapi.h will provide convenience interfaces to do these things. At most one trap per bytecode can be set. When a script (<code><a href="/en-US/docs/JSScript" title="JSScript">JSScript</a></code>) is destroyed, all traps set in its bytecode are cleared.</p> - -<p><strong>Watchpoints</strong>, for intercepting set operations on properties and running a debugger-supplied function that receives the old value and a pointer to the new one, which it can use to modify the new value being set.</p> - -<p><strong>Line number</strong> to PC and back mapping functions. The line-to-PC direction "rounds" toward the next bytecode generated from a line greater than or equal to the input line, and may return the PC of a for-loop update part, if given the line number of the loop body's closing brace. Any line after the last one in a script or function maps to a PC one byte beyond the last bytecode in the script. An example, from perfect.js:</p> - -<pre class="brush:js;first-line:14">function perfect(n) { - print("The perfect numbers up to " + n + " are:"); - // We build sumOfDivisors[i] to hold a string expression for - // the sum of the divisors of i, excluding i itself. - var sumOfDivisors = new ExprArray(n+1,1); - for (var divisor = 2; divisor <= n; divisor++) { - for (var j = divisor + divisor; j <= n; j += divisor) { - sumOfDivisors[j] += " + " + divisor; - } - // At this point everything up to 'divisor' has its sumOfDivisors - // expression calculated, so we can determine whether it's perfect - // already by evaluating. - if (eval(sumOfDivisors[divisor]) == divisor) { - print("" + divisor + " = " + sumOfDivisors[divisor]); - } - } - delete sumOfDivisors; - print("That's all."); -}</pre> - -<p>The line number to PC and back mappings can be tested using the js program with the following script:</p> - -<pre class="brush:js">load("perfect.js"); -print(perfect); -dis(perfect); -print(); -for (var ln = 0; ln <= 40; ln++) { - var pc = line2pc(perfect, ln); - var ln2 = pc2line(perfect, pc); - print("\tline " + ln + " => pc " + pc + " => line " + ln2); -} -</pre> - -<p>The result of the for loop over lines 0 to 40 inclusive is:</p> - -<pre>line 0 => pc 0 => line 16 -line 1 => pc 0 => line 16 -line 2 => pc 0 => line 16 -line 3 => pc 0 => line 16 -line 4 => pc 0 => line 16 -line 5 => pc 0 => line 16 -line 6 => pc 0 => line 16 -line 7 => pc 0 => line 16 -line 8 => pc 0 => line 16 -line 9 => pc 0 => line 16 -line 10 => pc 0 => line 16 -line 11 => pc 0 => line 16 -line 12 => pc 0 => line 16 -line 13 => pc 0 => line 16 -line 14 => pc 0 => line 16 -line 15 => pc 0 => line 16 -line 16 => pc 0 => line 16 -line 17 => pc 19 => line 20 -line 18 => pc 19 => line 20 -line 19 => pc 19 => line 20 -line 20 => pc 19 => line 20 -line 21 => pc 36 => line 21 -line 22 => pc 53 => line 22 -line 23 => pc 74 => line 23 -line 24 => pc 92 => line 22 -line 25 => pc 106 => line 28 -line 26 => pc 106 => line 28 -line 27 => pc 106 => line 28 -line 28 => pc 106 => line 28 -line 29 => pc 127 => line 29 -line 30 => pc 154 => line 21 -line 31 => pc 154 => line 21 -line 32 => pc 161 => line 32 -line 33 => pc 172 => line 33 -line 34 => pc 172 => line 33 -line 35 => pc 172 => line 33 -line 36 => pc 172 => line 33 -line 37 => pc 172 => line 33 -line 38 => pc 172 => line 33 -line 39 => pc 172 => line 33 -line 40 => pc 172 => line 33 -</pre> - -<h4 id="jsconfig.h" name="jsconfig.h">jsconfig.h</h4> - -<p>Various configuration macros defined as 0 or 1 depending on how <code><a href="/en-US/docs/JS_VERSION" title="JS_VERSION">JS_VERSION</a></code> is defined (as 10 for JavaScript 1.0, 11 for JavaScript 1.1, etc.). Not all macros are tested around related code yet. In particular, JS 1.0 support is missing from SpiderMonkey.</p> - -<h4 id="js.cpp.2C_jsshell.msg" name="js.cpp.2C_jsshell.msg">js.cpp, jsshell.msg</h4> - -<p>The "JS shell", a simple interpreter program that uses the JS API and more than a few internal interfaces (some of these internal interfaces could be replaced by <code>jsapi.h</code> calls). The js program built from this source provides a test vehicle for evaluating scripts and calling functions, trying out new debugger primitives, etc.</p> - -<p>A look at the places where <code>jsshell.msg</code> is used in <code>js.cpp</code> shows how error messages can be handled in JSAPI applications. These messages can be localized at compile time by replacing the <code>.msg</code> file; or, with a little modification to the source, at run time.</p> - -<p><a href="/en-US/docs/SpiderMonkey/Introduction_to_the_JavaScript_shell" title="https://developer.mozilla.org/en/introduction_to_the_javascript_shell">More information on the JavaScript shell</a>.</p> - -<h4 id="js.msg" name="js.msg">js.msg</h4> - -<p>SpiderMonkey error messages.</p> - -<h4 id="jsarray..2A.2C_jsbool..2A.2C_jdsdate..2A.2C_jsfun..2A.2C_jsmath..2A.2C_jsnum..2A.2C_jsstr..2A" name="jsarray..2A.2C_jsbool..2A.2C_jdsdate..2A.2C_jsfun..2A.2C_jsmath..2A.2C_jsnum..2A.2C_jsstr..2A">jsarray.*, jsbool.*, jsdate.*, jsfun.*, jsmath.*, jsnum.*, jsstr.*</h4> - -<p>These file pairs implement the standard classes and (where they exist) their underlying primitive types. They have similar structure, generally starting with class definitions and continuing with internal constructors, finalizers, and helper functions.</p> - -<h4 id="jsobj..2A.2C_jsscope..2A" name="jsobj..2A.2C_jsscope..2A">jsobj.*, jsscope.*</h4> - -<p>These two pairs declare and implement the JS object system. All of the following happen here:</p> - -<ul> - <li>creating objects by class and prototype, and finalizing objects;</li> - <li>defining, looking up, getting, setting, and deleting properties;</li> - <li>creating and destroying properties and binding names to them.</li> -</ul> - -<p>The details of a native object's map (scope) are mostly hidden in <code>jsscope.{{mediawiki.external('ch')}}</code>.</p> - -<h4 id="jsatom.cpp.2C_jsatom.h" name="jsatom.cpp.2C_jsatom.h">jsatom.cpp, jsatom.h</h4> - -<p>The atom manager. Contains well-known string constants, their atoms, the global atom hash table and related state, the js_Atomize() function that turns a counted string of bytes into an atom, and literal pool (<code>JSAtomMap</code>) methods.</p> - -<h4 id="jsarena.cpp.2C_jsarena.h" name="jsarena.cpp.2C_jsarena.h">jsarena.cpp, jsarena.h</h4> - -<p>Last-In-First-Out allocation macros that amortize malloc costs and allow for en-masse freeing. See the paper mentioned in <code>jsarena.h</code>'s major comment.</p> - -<h4 id="jsgc.cpp.2C_jsgc.h" name="jsgc.cpp.2C_jsgc.h">jsgc.cpp, jsgc.h</h4> - -<p>The garbage collector and tracing routines.</p> - -<h4 id="jsinterp..2A.2C_jscntxt..2A.2C_jsinvoke.cpp" name="jsinterp..2A.2C_jscntxt..2A.2C_jsinvoke.cpp">jsinterp.*, jscntxt.*, jsinvoke.cpp</h4> - -<p>The bytecode interpreter, and related functions such as Call and AllocStack, live in <em>jsinterp.cpp</em>. The JSContext constructor and destructor are factored out into <em>jscntxt.cpp</em> for minimal linking when the compiler part of JS is split from the interpreter part into a separate program.</p> - -<p><code>jsinvoke.cpp</code> is a build hack used on some platforms to build <code>js_Interpret</code> under different compiler options from the rest of <code>jsinterp.cpp</code>.</p> - -<h4 id="jstracer.*_nanojit*">jstracer.*, nanojit/*</h4> - -<p><a href="/en-US/docs/SpiderMonkey/Internals/Tracing_JIT" title="SpiderMonkey/Internals/Tracing JIT">The tracing JIT</a>. The interface between the JIT and the rest of SpiderMonkey is conceptually small—the interpreter calls into the trace recorder—but as with everything else, there are tendrils everywhere.</p> - -<h4 id="jsemit..2A.2C_jsopcode.tbl.2C_jsopcode..2A.2C_jsparse..2A.2C_jsscan..2A.2C_jsscript..2A" name="jsemit..2A.2C_jsopcode.tbl.2C_jsopcode..2A.2C_jsparse..2A.2C_jsscan..2A.2C_jsscript..2A">jsemit.*, jsopcode.tbl, jsopcode.*, jsparse.*, jsscan.*, jsscript.*</h4> - -<p>Compiler and decompiler modules. The <em>jsopcode.tbl</em> file is a C preprocessor source that defines almost everything there is to know about JS bytecodes. See its major comment for how to use it. For now, a debugger will use it and its dependents such as <em>jsopcode.h</em> directly, but over time we intend to extend <em>jsdbgapi.h</em> to hide uninteresting details and provide conveniences. The code generator is split across paragraphs of code in <em>jsparse.cpp</em>, and the utility methods called on <code>JSCodeGenerator</code> appear in <em>jsemit.cpp</em>. Source notes generated by <em>jsparse.cpp</em> and <em>jsemit.cpp</em> are used in <em>jsscript.cpp</em> to map line number to program counter and back.</p> - -<h4 id="jstypes.h" name="jstypes.h">jstypes.h</h4> - -<p>Fundamental representation types and utility macros. This file alone among all .h files in SpiderMonkey must be included first by .cpp files. It is not nested in .h files, as other prerequisite .h files generally are, since it is also a direct dependency of most .cpp files and would be over-included if nested in addition to being directly included.</p> - -<h4 id="jsbit.h.2C_jslog2.cpp" name="jsbit.h.2C_jslog2.cpp">jsbit.h, jslog2.cpp</h4> - -<p>Bit-twiddling routines. Most of the work here is selectively enabling compiler-specific intrinsics such as GCC's <code>__builtin_ctz</code>, which is useful in calculating base-2 logarithms of integers.</p> - -<h4 id="jsutil.cpp.2C_jsutil.h" name="jsutil.cpp.2C_jsutil.h">jsutil.cpp, jsutil.h</h4> - -<p>The <code>JS_ASSERT</code> macro is used throughout the source as a proof device to make invariants and preconditions clear to the reader, and to hold the line during maintenance and evolution against regressions or violations of assumptions that it would be too expensive to test unconditionally at run-time. Certain assertions are followed by run-time tests that cope with assertion failure, but only where I'm too smart or paranoid to believe the assertion will never fail...</p> - -<h4 id="jsclist.h" name="jsclist.h">jsclist.h</h4> - -<p>Doubly-linked circular list struct and macros.</p> - -<h4 id="jscpucfg.cpp" name="jscpucfg.cpp">jscpucfg.cpp</h4> - -<p>This standalone program generates <em>jscpucfg.h</em>, a header file containing bytes per word and other constants that depend on CPU architecture and C compiler type model. It tries to discover most of these constants by running its own experiments on the build host, so if you are cross-compiling, beware.</p> - -<h4 id="jsdtoa.cpp.2C_jsdtoa.h.2C_dtoa.c" name="jsdtoa.cpp.2C_jsdtoa.h.2C_dtoa.c">jsdtoa.cpp, jsdtoa.h, dtoa.c</h4> - -<p>dtoa.c contains David Gay's portable double-precision floating point to string conversion code, with Permission To Use notice included. jsdtoa.cpp <code>#include</code>s this file.</p> - -<h4 id="jshash.cpp.2C_jshash.h.2C_jsdhash.cpp.2C_jsdhash.h" name="jshash.cpp.2C_jshash.h.2C_jsdhash.cpp.2C_jsdhash.h">jshash.cpp, jshash.h, jsdhash.cpp, jsdhash.h</h4> - -<p>Portable, extensible hash tables. These use multiplicative hash for strength reduction over division hash, yet with very good key distribution over power of two table sizes. jshash resolves collisions via chaining, so each entry burns a malloc and can fragment the heap. jsdhash uses open addressing.</p> - -<h4 id="jslong.cpp.2C_jslong.h" name="jslong.cpp.2C_jslong.h">jslong.cpp, jslong.h</h4> - -<p>64-bit integer emulation, and compatible macros that use intrinsic C types, like <code>long long</code>, on platforms where they exist (most everywhere, these days).</p> - -<h4 id="jsprf..2A" name="jsprf..2A">jsprf.*</h4> - -<p>Portable, buffer-overrun-resistant sprintf and friends. For no good reason save lack of time, the %e, %f, and %g formats cause your system's native sprintf, rather than <code>JS_dtoa()</code>, to be used. This bug doesn't affect SpiderMonkey, because it uses its own <code>JS_dtoa()</code> call in <code>jsnum.cpp</code> to convert from double to string, but it's a bug that we'll fix later, and one you should be aware of if you intend to use a <code>JS_*printf()</code> function with your own floating type arguments - various vendor sprintf's mishandle NaN, +/-Inf, and some even print normal floating values inaccurately.</p> - -<h4 id="prmjtime.c.2C_prmjtime.h" name="prmjtime.c.2C_prmjtime.h">prmjtime.c, prmjtime.h</h4> - -<p>Time functions. These interfaces are named in a way that makes local vs. universal time confusion likely. Caveat emptor, and we're working on it. To make matters worse, Java (and therefore JavaScript) uses "local" time numbers (offsets from the epoch) in its Date class.</p> - -<h4 id="jsfile.cpp.2C_jsfile.h.2C_jsfile.msg" name="jsfile.cpp.2C_jsfile.h.2C_jsfile.msg">jsfile.cpp, jsfile.h, jsfile.msg</h4> - -<p>Obsolete. Do not use these files.</p> - -<h4 id="Makefile.in.2C_build.mk" name="Makefile.in.2C_build.mk">Makefile.in, build.mk</h4> - -<p>Mozilla makefiles. If you're building Gecko or Firefox, the larger build system will use these files. They are also used for current standalone builds.</p> - -<h4 id="Makefile.ref.2C_rules.mk.2C_config.mk.2C_config.2F.2A" name="Makefile.ref.2C_rules.mk.2C_config.mk.2C_config.2F.2A">Makefile.ref, rules.mk, config.mk, config/*</h4> - -<p>Obsolete SpiderMonkey standalone makefiles from 1.8 and earlier. See <a href="/en-US/docs/SpiderMonkey/Build_Documentation#Building_SpiderMonkey_1.8_or_earlier" title="SpiderMonkey/Build Documentation#Building SpiderMonkey 1.8 or earlier">SpiderMonkey Build Documentation</a>.</p> - -<h3 id="See_also">See also</h3> - -<ul> - <li><a href="/jsd" title="jsd">jsd</a></li> -</ul> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/introduction_to_the_javascript_shell/index.html b/files/zh-cn/mozilla/projects/spidermonkey/introduction_to_the_javascript_shell/index.html deleted file mode 100644 index b570b78d56..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/introduction_to_the_javascript_shell/index.html +++ /dev/null @@ -1,382 +0,0 @@ ---- -title: JavaScript shell 介绍 -slug: Mozilla/Projects/SpiderMonkey/Introduction_to_the_JavaScript_shell -tags: - - SpiderMonkey - - 蜘蛛猴 -translation_of: Mozilla/Projects/SpiderMonkey/Introduction_to_the_JavaScript_shell ---- -<div>{{SpiderMonkeySidebar("General")}}</div> - -<div class="summary"> -<p>JavaScript shell 是一个命令行程序,它被包含在<a href="/en-US/docs/Mozilla/Projects/SpiderMonkey" title="en/SpiderMonkey">SpiderMonkey</a>源代码中。它在 JavaScript 中类似于 Python 命令行、Lisp 读取执行循环和 Ruby 中的 <code>irb</code> 。这篇文章解释如何使用 shell 去测试 JavaScript 代码和执行 JavaScript 程序。</p> -</div> - -<p>要获取 SpiderMonkey JavaScript shell, 请参见 <a href="/en-US/docs/Mozilla/Projects/SpiderMonkey/Build_Documentation">SpiderMonkey 构建文档</a> 或根据你的平台从 <a class="external" href="https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/" title="http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/">Nightly Builds</a> 下载二进制文件。</p> - -<p>对于其他的 JavaScript shells, 参考 <a class="internal" href="/en-US/docs/Web/JavaScript/Shells" title="En/JavaScript shells">JavaScript shells</a>.</p> - -<div class="note"> -<p>注意: <span class="tlid-translation translation" lang="zh-CN"><span title="">从 SpiderMonkey 44 开始,默认情况下使用标准的、与 Web 兼容的 JavaScript 版本(不再使用JS1.7 +)。</span> <span title="">内置的</span></span> <code>version()</code> <span class="tlid-translation translation" lang="zh-CN"><span title=""> 内置函数仍然可以用来测试遗留功能。</span></span></p> -</div> - -<h2 id="Using_the_JavaScript_shell" name="Using_the_JavaScript_shell">执行JavaScript shell</h2> - -<p>jsshell 提供两种操作模式。你既可以交互式操作 shell, 在此模式你可以输入JavaScript 代码并执行。便于实验和测试新特性。你也可以在命令行参数指定一个 JavaScript 代码文件,此文件会自动运行。</p> - -<p>在安装 jsshell 之后,你可以执行以下命令打开交互式终端:</p> - -<pre class="eval notranslate">js -</pre> - -<div class="blockIndicator note"> -<p><strong>注意</strong>:如果你在预编译程序执行中遇到<br> - <code>"symbol lookup error: ./js: undefined symbol: PR_SetCurrentThreadName"</code><br> - 这样的错误, 请尝试用 run-mozilla.sh 文件执行它:<br> - <code>run-mozilla.sh ./js</code> <br> - ——我测试过有效</p> -</div> - -<p>如果运行 <code>foo.js</code> file中的JavaScript代码,你可以使用以下命令:</p> - -<pre class="eval notranslate">js foo.js -</pre> - -<p>如果想运行 <code>foo.js</code> 然后进入交互模式:</p> - -<pre class="eval notranslate">js -f foo.js -i -</pre> - -<h2 id="说明">说明</h2> - -<div class="note"><strong>注意:</strong> 因为JavaScript shell 用来给 JavaScript 引擎做测试环境, 可用的选项和内置函数可能改变。</div> - -<h3 id="Command_line_options" name="Command_line_options">命令行选项</h3> - -<p>有许多命令行选项可以控制shell,以下为总结。使用<strong>-h</strong>选项显示帮助</p> - -<dl> - <dt><code>-c, --compileonly</code></dt> - <dd>仅编译不执行代码,这是一种方便的检查语法错误的方式。</dd> - <dt><code>-e <em>script</em></code></dt> - <dd>运行指定脚本,<code><em>script</em></code> 是将要执行的代码字符串。</dd> - <dt><code>-f <em>filename</em></code></dt> - <dd>执行指定的代码文件。</dd> - <dt><code>-i</code></dt> - <dd>启用交互模式。(如果参数中没有文件名这个选项默认打开)</dd> - <dt><code>--no-ion</code></dt> - <dd>禁用优化的 JIT 编译器。</dd> - <dt><code>--no-baseline</code></dt> - <dd>禁用基准的 JIT 编译器。</dd> - <dt><code>-P</code></dt> - <dd>如果文件的第一行是 "/usr/bin/env js -P",文件内容将通过 JavaScript 引擎解释执行。</dd> - <dd>这将允许你在 unix 和 OS X 系统上执行 JavaScript 文件。</dd> - <dt><code>-s</code></dt> - <dd>启用严格警告模式.</dd> - <dt><code>-w, --warnings</code></dt> - <dd>显示警告消息.</dd> - <dt><code>-W</code>, --nowarnings</dt> - <dd>隐藏警告消息.</dd> -</dl> - -<h3 id="Environment_options" name="Environment_options">环境选项</h3> - -<p>如果设置了这些环境变量,它们将会影响 js shell 的行为。</p> - -<dl> - <dt><code>JS_STDOUT=<em>file</em></code></dt> - <dd>将标准输出重定向到文件<code><em>file</em></code>。</dd> - <dt><code>JS_STDERR=<em>file</em></code></dt> - <dd>将标准输入重定向到文件<code><em>file</em></code>。</dd> -</dl> - -<h3 id="Built-in_functions" name="Built-in_functions">内置函数</h3> - -<p>为了使 JavaScript shell 更加实用, 我们提供了一些内置的函数供 JavaScript 程序(包括交互模式下)使用。</p> - -<div class="warning"> -<p><strong>注意</strong>:这个列表是不完整的而且与 <a href="/en-US/docs/SpiderMonkey/Shell_global_objects">Shell 全局对象</a> 重复。请参见{{Source("js/src/shell/js.cpp")}} (在 <code>shell_functions</code> 附近) 以获取详细信息。</p> -</div> - -<h4 id="build.28.29" name="build.28.29"><code>build()</code></h4> - -<p>返回 JavaScript shell 构建的日期和时间.</p> - -<div class="note"><strong>Note:</strong> <code>clear()</code> 函数如果不带任何参数,将清除包括所有内置方法在内的所有东西。</div> - -<h4 id="clone.28function.2C_.5Bscope.5D.29" name="clone.28function.2C_.5Bscope.5D.29"><code>clone(<em>function, [scope]</em>)</code></h4> - -<p>克隆指定函数对象。如果未指定具体域,新对象的父本和原始对象的相同。否则,新对象被放置于指定域。</p> - -<h4 id="countHeap" name="countHeap"><code>countHeap(<em>[start[, kind]]</em>)</code></h4> - -<p>{{ jsapi_minversion_inline("1.8") }} <span class="tlid-translation translation" lang="zh-CN"><span title="">计算堆中活动的回收垃圾数量,或计算给定且不为 null 的可从 </span></span><code><em>start</em></code><span class="tlid-translation translation" lang="zh-CN"><span title=""> 到达的对象的数量。</span></span><code><em>kind</em></code><span class="tlid-translation translation" lang="zh-CN"><span title=""> 是“all”(默认)以计算所有事物,或者是“ object”,“ double”,“ string”,“ function”,“ qname”,“ namespace”,“ xml”之一以仅计算此类事物</span> <span title="">。</span></span></p> - -<h4 id="evalcx.28string.5B.2C_object.5D.29" name="evalcx.28string.5B.2C_object.5D.29"><code>dumpHeap(<em>[fileName[, start[, toFind[, maxDepth[, toIgnore]]]]]</em>)</code></h4> - -<p>{{ jsapi_minversion_inline("1.8") }} 转储所有现存对象的数据 (或有关联的子数据) 到文件。详情参见本函数的C/C++版本: <code>JS_DumpHeap</code>.</p> - -<h4 id="evalcx.28string.5B.2C_object.5D.29" name="evalcx.28string.5B.2C_object.5D.29"><code>evalcx(<em>string[, object]</em>)</code></h4> - -<p>执行 <code><em>string</em></code> 中的 JavaScript 代码。如果设置了参数 <code><em>object</em></code>,代码将在这个对象中执行,将其视为一个沙盒。</p> - -<p><code><em>string</em></code> 为空且没有设置 <code><em>object</em></code> 时,<code>evalcx()</code> 将会<span class="tlid-translation translation" lang="zh-CN"><span title="">返回一个具有“</span></span>eager”<span class="tlid-translation translation" lang="zh-CN"><span title=""> 标准类的新对象</span></span>。</p> - -<p><code><em>string</em></code> 为 "lazy" 且没有设置 <code><em>object</em></code> 时,<code>evalcx()</code> 将会<span class="tlid-translation translation" lang="zh-CN"><span title="">返回一个具有“</span></span>lazy”<span class="tlid-translation translation" lang="zh-CN"><span title=""> 标准类的新对象</span></span>。</p> - -<div class="note"><strong>注意:</strong> <code>evalcx()</code> 仅对进行 JavaScript 引擎极低层工作的开发者有用,用于在 shell 中测试类<code>evalInSandbox</code> 环境</div> - -<h4 id="gc.28.29" name="gc.28.29"><code>gc()</code></h4> - -<p>运行垃圾收集器释放内存。</p> - -<h4 id="gcparam.28.29" name="gcparam.28.29"><code>gcparam(<em>name[, value]</em>)</code></h4> - -<p>{{ jsapi_minversion_inline("1.8") }} 读取或配置垃圾收集器参数。</p> - -<p>名称必须是参数key之一 (例如 <code>'maxBytes'</code>, <code>'maxMallocBytes'</code> 或<code>'gcNumber</code>').</p> - -<p>如果value未指定,<code>gcparam()</code>返回与GC参数名name相关联的当前值</p> - -<p>如果value被指定,其必须可转换为uint32,<code>gcparam()</code>将GC参数名设置为value。</p> - -<p>For more information, see the C/C++ functions <a class="internal" href="/En/SpiderMonkey/JSAPI_Reference/JS_GetGCParameter" title="en/SpiderMonkey/JSAPI Reference/JS GetGCParameter"><code>JS_SetGCParameter</code></a> and <a class="internal" href="/En/SpiderMonkey/JSAPI_Reference/JS_SetGCParameter" title="en/SpiderMonkey/JSAPI Reference/JS SetGCParameter"><code>JS_SetGCParameter</code></a>.</p> - -<h4 id="gczeal.28.29" name="gczeal.28.29"><code>gczeal(level)</code></h4> - -<p>{{ jsapi_minversion_inline("1.8") }} <code>DEBUG</code> only. 设置GC zeal级别, 这是一个调试特性。0 是正常的周期性垃圾收集,1是频繁的GC, 2是及其频繁的GC. 除了0以外的都将使JavaScript运行极其缓慢但是可能有助于发现GC相关的 bug. For more information, see the C/C++ version of this function, <a class="internal" href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCZeal" title="en/SpiderMonkey/JSAPI Reference/JS SetGCZeal"><code>JS_SetGCZeal</code></a>.</p> - -<h4 id="getpda.28object.29" name="getpda.28object.29"><code>getpda(<em>object</em>)</code></h4> - -<p>返回指定对象的属性描述</p> - -<h4 id="getslx.28object.29" name="getslx.28object.29"><code>getslx(<em>object</em>)</code></h4> - -<p>返回脚本行范围,这是包含指定对象的代码行数</p> - -<h4 id="help.28.5Bcommand_....5D.29" name="help.28.5Bcommand_....5D.29"><code>help(<em>[command ...]</em>)</code></h4> - -<p><span class="tlid-translation translation" lang="zh-CN"><span title="">显示有关指定命令或所有可用功能的简要帮助信息(如果未指定命令将显示所有帮助信息)。</span></span></p> - -<h4 id="intern.28string.29" name="intern.28string.29"><code>intern(<em>string</em>)</code></h4> - -<p>将指定的字符串 内化到atom表中。每个字符串都有一个唯一的标识符,称为atom。这个系统使得对字符串进行比较变得更加容易。</p> - -<div class="note"><strong>Note:</strong> This function is intended only for use when testing the JavaScript engine.</div> - -<h4 id="line2pc.28.5Bfunction.2C_.5D_line.29" name="line2pc.28.5Bfunction.2C_.5D_line.29"><code>line2pc(<em>[function, ] line</em>)</code></h4> - -<p>返回对应于指定行的代码行的程序计数器值。如果指定了函数,那么行就是指定函数的偏移量.</p> - -<h4 id="load.28filename1_.5Bfilename.5D.29" name="load.28filename1_.5Bfilename.5D.29"><code>load(<em>filename1</em> <em>[filename]</em>)</code></h4> - -<p>加载带有指定名称的JavaScript文件.</p> - -<div class="note"><strong>Note:</strong> For loading non-JavaScript files, use <code>read()</code>.</div> - -<h4 id="options.28.5Boption_....5D.29" name="options.28.5Boption_....5D.29"><code>options(<em>[option ...]</em>)</code></h4> - -<p>让你设置或获取选项。如果您在命令行上指定选项,那么调用<code>options的</code>结果将指示您所请求的选项。您还可以传递新的选项来设置.</p> - -<p>The available options are:</p> - -<table class="standard-table"> - <tbody> - <tr> - <td class="header">Option Name</td> - <td class="header">Description</td> - </tr> - <tr> - <td><code>strict</code></td> - <td>严格模式 is enabled.</td> - </tr> - <tr> - <td><code>werror</code></td> - <td>Warnings should be treated as errors.</td> - </tr> - <tr> - <td><code>atline</code></td> - <td>When <code>atline</code> is enabled, 表单的注释 <code>//@line <em>num</em></code> set the number of the following line to <code><em>num</em></code>.</td> - </tr> - </tbody> -</table> - -<h4 id="pc2line.28function.2C_.5Bpc.5D.29" name="pc2line.28function.2C_.5Bpc.5D.29"><code>pc2line(<em>function, [pc]</em>)</code></h4> - -<p>返回对应于指定函数的第一行的JavaScript代码的行号. If you specify a program counter offset into the function, the line number of the line of code containing that offset is returned.</p> - -<h4 id="print.28.5Bexpression_....5D.29" name="print.28.5Bexpression_....5D.29"><code>print(<em>[expression ...]</em>)</code></h4> - -<p>Evaluates the <em>expression(s)</em> and displays the result(s) on <code>stdout</code>, 分隔 by spaces (" ") and 终止 by a newline ("\n").</p> - -<h4 id="print.28.5Bexpression_....5D.29" name="print.28.5Bexpression_....5D.29"><code>putstr(<em>expression</em>)</code></h4> - -<p>Evaluates the <em>expression</em> and displays the result on <code>stdout</code>.</p> - -<h4 id="quit.28.29" name="quit.28.29"><code>quit(<em>[status]</em>)</code></h4> - -<p>Exits the shell. 如果省略,状态默认为0。</p> - -<h4 id="load.28filename1_.5Bfilename.5D.29" name="load.28filename1_.5Bfilename.5D.29"><code>read(<em>filename[, type]</em>)</code></h4> - -<p>Reads and returns the contents of file. If type is "binary" returns an <code>Uint8Array</code>, otherwise returns an UTF-8 decoded string.</p> - -<h4 id="readline.28.29" name="readline.28.29"><code>readline()</code></h4> - -<p>Reads a single line of input from <code>stdin</code>, returning it to the caller. You can use this to create interactive shell programs in JavaScript.</p> - -<h4 id="scatter.28fnArray.29" name="scatter.28fnArray.29">Reflect.parse()</h4> - -<p>See <a href="/en/SpiderMonkey/Parser_API" title="en/SpiderMonkey/Parser_API">Parser API</a>.</p> - -<div class="note"><strong>Note:</strong> This function is intended only for use when testing the JavaScript engine.</div> - -<h4 id="seal.28object.5B.2C_deep.5D.29" name="seal.28object.5B.2C_deep.5D.29"><code>seal(<em>object[, deep]</em>)</code></h4> - -<p>密封指定的对象, or an object graph if <em>deep</em> is <code>true</code>. 通过封住对象或对象图,可以禁用这些对象的修改.</p> - -<h4 id="sleep.28dt.29" name="sleep.28dt.29"><code>sleep(dt)</code></h4> - -<p>{{ jsapi_minversion_inline("1.8") }} Only in <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_THREADSAFE" title="en/SpiderMonkey/JSAPI_Reference/JS_THREADSAFE">JS_THREADSAFE</a></code> builds. Sleep for <em>dt</em> seconds. Fractions of a second are supported. Returns <code>true</code> on success, <code>false</code> if the sleep was interrupted.</p> - -<h4 id="stackQuota" name="stackQuota"><code>stackQuota(<em>[number]</em>)</code> {{obsolete_inline}}</h4> - -<p>{{ jsapi_minversion_inline("1.8") }} 获取或设置脚本堆栈配额.</p> - -<h4 id="throwError.28.29" name="throwError.28.29"><code>throwError()</code></h4> - -<p>Throws an error from the <code>JS_ReportError()</code> function.</p> - -<div class="note"><strong>Note:</strong> This function is intended only for use when testing the JavaScript engine.</div> - -<h4 id="trap.28.5Bfunction.2C_.5Bpc.2C.5D.5D_expression.29" name="trap.28.5Bfunction.2C_.5Bpc.2C.5D.5D_expression.29"><code>trap(<em>[function, [pc,]] expression</em>)</code></h4> - -<p>在JavaScript代码的特定点设置trap. 当由pc在函数函数中指定的偏移量即将被执行时,表达式将被求值。</p> - -<p>这是一种强大的调试机制,与<code>line2pc()</code>一起使用. 例如, 如果你想在函数的第6行中显示一条消息, <code>doSomething()</code> 被执行, you can enter the following:</p> - -<pre class="notranslate">trap(doSomething, line2pc(doSomething, 6), "print('line 6!\n')"); -</pre> - -<div class="note"><strong>Note:</strong> 当设置陷阱时,程序中的相应字节码将被<code>trap</code>字节码替换,直到您使用<code>untrap()</code> 来移除陷阱。</div> - -<h4 id="untrap.28function_.5B.2C_pc.5D.29" name="untrap.28function_.5B.2C_pc.5D.29"><code>untrap(<em>function [, pc]</em>)</code></h4> - -<p>Removes a trap from the specified <em>function</em> at the offset <em>pc</em>. If <em>pc</em> isn't specified, the trap is removed from the function's entry point.</p> - -<p>This function has no effect if there is no trap at the specified location.</p> - -<h4 id="version.28.5Bnumber.5D.29" name="version.28.5Bnumber.5D.29"><code>version(<em>[number]</em>)</code></h4> - -<p>The <code>version()</code> function lets you get or set the JavaScript version number. This may be useful for gaining access to syntax only available in certain versions of JavaScript (for example, see <a href="/en/JavaScript/New_in_JavaScript/1.7#Using_JavaScript_1.7" title="en/New_in_JavaScript_1.7#Using_JavaScript_1.7">Using JavaScript 1.7</a>).</p> - -<h3 id="Debug_functions" name="Debug_functions">调试方法</h3> - -<p>These built-in functions are only available in <code>DEBUG</code> builds.</p> - -<h4 id="dis.28.5Bfunction.5D.29" name="dis.28.5Bfunction.5D.29"><code>dis(<em>[function]</em>)</code></h4> - -<p>为整个程序或指定的函数分解JavaScript字节码</p> - -<p>For example, if you enter the JavaScript function below:</p> - -<pre class="eval notranslate">function test() { - var i = 3; - print(i+2); -} -</pre> - -<p>Then run the command <code>dis(test);</code>, you get this output:</p> - -<pre class="notranslate">main: -00000: uint16 3 -00003: setvar 0 -00006: pop -00007: name "print" -00010: pushobj -00011: getvar 0 -00014: uint16 2 -00017: add -00018: call 1 -00021: pop -00022: stop - -Source notes: - 0: 0 [ 0] newline - 1: 3 [ 3] decl offset 0 - 2: 7 [ 4] newline - 3: 18 [ 11] xdelta - 4: 18 [ 0] pcbase offset 11 -</pre> - -<h4 id="dissrc.28.5Bfunction.5D.29" name="dissrc.28.5Bfunction.5D.29"><code>dissrc(<em>[function]</em>)</code></h4> - -<p>Disassembles the JavaScript bytecode for the entire program, or for the specified <em>function</em>, showing the source lines. This function only works with programs loaded from files, either using the <code>-f</code> flag on launching the shell, or by using the <code>load()</code> function.</p> - -<p>If your program includes a function, <code>doStuff()</code>, like this:</p> - -<pre class="notranslate">function doStuff(input) { - print("Enter a number: "); - var n1 = readline(); - print("Enter another one: "); - var n2 = readline(); - - print("You entered " + n1 + " and " + n2 + "\n"); -} -</pre> - -<p>Calling <code>dissrc(doStuff)</code> function would give this output:</p> - -<pre class="notranslate">;------------------------- 10: print("Enter a number: "); -00000: 10 name "print" -00003: 10 pushobj -00004: 10 string "Enter a number: " -00007: 10 call 1 -00010: 10 pop -;------------------------- 11: var n1 = readline(); -00011: 11 name "readline" -00014: 11 pushobj -00015: 11 call 0 -00018: 11 setvar 0 -00021: 11 pop -;------------------------- 12: print("Enter another one: "); -00022: 12 name "print" -00025: 12 pushobj -00026: 12 string "Enter another one: " -00029: 12 call 1 -00032: 12 pop -;------------------------- 13: var n2 = readline(); -00033: 13 name "readline" -00036: 13 pushobj -00037: 13 call 0 -00040: 13 setvar 1 -00043: 13 pop -;------------------------- 14: -;------------------------- 15: print("You entered " + n1 + " and " + n2 + "\n"); -00044: 15 name "print" -00047: 15 pushobj -00048: 15 string "You entered " -00051: 15 getvar 0 -00054: 15 add -00055: 15 string " and " -00058: 15 add -00059: 15 getvar 1 -00062: 15 add -00063: 15 string "\\n" -00066: 15 add -00067: 15 call 1 -00070: 15 pop -00071: 15 stop -</pre> - -<h4 id="dumpheap.28.28.5BfileName.5B.2C_start.5B.2C_toFind.5B.2C_maxDepth.5B.2C_toIgnore.5D.5D.5D.5D.5D.29" name="dumpheap.28.28.5BfileName.5B.2C_start.5B.2C_toFind.5B.2C_maxDepth.5B.2C_toIgnore.5D.5D.5D.5D.5D.29"><code>dumpheap((<em>[fileName[, start[, toFind[, maxDepth[, toIgnore]]]]]</em>)</code></h4> - -<p>Dump GC information. This is a thin wrapper for <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DumpHeap" title="en/SpiderMonkey/JSAPI_Reference/JS_DumpHeap">JS_DumpHeap</a></code>.</p> - -<h4 id="gczeal.28zeal.29" name="gczeal.28zeal.29"><code>gczeal(<em>zeal</em>)</code></h4> - -<p>Enable extra-frequent GC, to help find GC hazards. <em>zeal</em> is an integer. The meaning is the same as for the parameter to <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCZeal" title="en/SpiderMonkey/JSAPI_Reference/JS_SetGCZeal">JS_SetGCZeal</a></code>.</p> - -<h4 id="notes.28.5Bfunction.5D.29" name="notes.28.5Bfunction.5D.29"><code>notes(<em>[function]</em>)</code></h4> - -<p>Shows the source notes for the specified function. Source notes contain information that map the bytecode to the source code, which is used when decompiling the code, such as when using the <code>dissrc()</code> function.</p> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/javascript-c引擎嵌入开发指南/index.html b/files/zh-cn/mozilla/projects/spidermonkey/javascript-c引擎嵌入开发指南/index.html deleted file mode 100644 index 4752df82f3..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/javascript-c引擎嵌入开发指南/index.html +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: JavaScript-C引擎嵌入开发指南 -slug: Mozilla/Projects/SpiderMonkey/JavaScript-C引擎嵌入开发指南 -translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_User_Guide ---- -<p><a class="external" href="http://www.nirvanastudio.org/javascript/javascript-c-engine-embedders-guide.html">查看Nirvana Studio上的翻译</a> -</p><p><br> -</p> -<div class="noinclude"> -</div> -{{ languages( { "en": "en/JSAPI_User_Guide", "ja": "ja/Embedding_SpiderMonkey" } ) }} diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/boolean_to_jsval/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/boolean_to_jsval/index.html deleted file mode 100644 index 80747881fd..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/boolean_to_jsval/index.html +++ /dev/null @@ -1,53 +0,0 @@ ---- -title: BOOLEAN_TO_JSVAL -slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/BOOLEAN_TO_JSVAL -translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/BOOLEAN_TO_JSVAL ---- -<div>{{SpiderMonkeySidebar("JSAPI")}}</div> - -<div>{{ obsolete_header("jsapi42") }}</div> - -<div class="summary"> -<p>Cast a C integer to a boolean {{jsapixref("JS::Value")}} without any type checking or error handling.</p> -</div> - -<div class="note"> -<p>Please use {{jsapixref("JS::BooleanValue")}}/{{jsapixref("JS::TrueValue")}}/{{jsapixref("JS::FalseValue")}} instead in SpiderMonkey 45 or later.</p> -</div> - -<h2 id="Syntax" name="Syntax">Syntax</h2> - -<pre class="brush: cpp">jsval -BOOLEAN_TO_JSVAL(bool b); -</pre> - -<table class="fullwidth-table"> - <tbody> - <tr> - <th>Name</th> - <th>Type</th> - <th>Description</th> - </tr> - <tr> - <td><code>b</code></td> - <td><code>bool</code></td> - <td>C integer value to be converted to a boolean <code>jsval</code>.</td> - </tr> - </tbody> -</table> - -<h2 id="Description" name="Description">Description</h2> - -<p><strong><code>BOOLEAN_TO_JSVAL</code></strong> converts a <code>bool</code> argument, <code>b</code>, to a boolean <code>jsval</code>.</p> - -<p>If <code>b</code> is <code>false</code>, the result is <code>JSVAL_FALSE</code>.</p> - -<p>If <code>b</code> is <code>true</code>, the result is <code>JSVAL_TRUE</code>.</p> - -<h2 id="See_Also" name="See_Also">See Also</h2> - -<ul> - <li>{{ LXRSearch("ident", "i", "BOOLEAN_TO_JSVAL") }}</li> - <li>{{jsapixref("JS::BooleanValue")}}</li> - <li>{{bug(1177892)}} -- removed</li> -</ul> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/index.html deleted file mode 100644 index d076928fba..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/index.html +++ /dev/null @@ -1,646 +0,0 @@ ---- -title: JSAPI 参考 -slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference -translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference ---- -<p><strong>JSAPI</strong>是<strong> </strong><a href="/en/SpiderMonkey" title="en/SpiderMonkey">SpiderMonkey</a> JavaScript 引擎的C 语言应用程序接口(API)。要了解如何使用JSAPI ,请看 <a href="/En/SpiderMonkey/JSAPI_User_Guide" title="en/JSAPI_User_Guide">JSAPI User Guide</a> and the <a href="/En/SpiderMonkey/JSAPI_Phrasebook" title="en/JSAPI_Phrasebook">JSAPI Phrasebook</a>。</p> -<p><br> - <a href="/En/SpiderMonkey/JSAPI_Reference/Alphabetical_List" title="en/JSAPI_Reference/Alphabetical_List">Alphabetical List</a></p> -<h3 id="Runtimes_and_contexts" name="Runtimes_and_contexts">运行时和上下文</h3> -<ul> - <li>typedef <a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSRuntime</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewRuntime" title="en/JS_NewRuntime">JS_NewRuntime</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DestroyRuntime" title="en/JS_DestroyRuntime">JS_DestroyRuntime</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ShutDown" title="en/JS_ShutDown">JS_ShutDown</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetRuntimePrivate" title="en/JS_GetRuntimePrivate">JS_GetRuntimePrivate</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetRuntimePrivate" title="en/JS_GetRuntimePrivate">JS_SetRuntimePrivate</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_Init" title="en/JS_Init">JS_Init</a> {{ Deprecated_inline() }}</li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_Finish" title="en/JS_Finish">JS_Finish</a> {{ Deprecated_inline() }}</li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ContextIterator" title="en/JS_ContextIterator">JS_ContextIterator</a></li> -</ul> -<ul> - <li>typedef <a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewContext" title="en/JS_NewContext">JS_NewContext</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DestroyContext" title="en/JS_DestroyContext">JS_DestroyContext</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DestroyContext" title="en/JS_DestroyContext">JS_DestroyContextMaybeGC</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DestroyContext" title="en/JS_DestroyContext">JS_DestroyContextNoGC</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetRuntime" title="en/JS_GetRuntime">JS_GetRuntime</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetContextPrivate" title="en/JS_GetContextPrivate">JS_GetContextPrivate</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetContextPrivate" title="en/JS_GetContextPrivate">JS_SetContextPrivate</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetOptions" title="en/JS_GetOptions">JS_GetOptions</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOptions" title="en/JS_SetOptions">JS_SetOptions</a> – <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOptions" title="en/JS_SetOptions">JSOPTION_ATLINE</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOptions" title="en/JS_SetOptions">JSOPTION_COMPILE_N_GO</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOptions" title="en/JS_SetOptions">JSOPTION_DONT_REPORT_UNCAUGHT</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOptions" title="en/JS_SetOptions">JSOPTION_NATIVE_BRANCH_CALLBACK</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOptions" title="en/JSOPTION_RELIMIT">JSOPTION_RELIMIT</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOptions" title="en/JS_SetOptions">JSOPTION_STRICT</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOptions" title="en/JS_SetOptions">JSOPTION_VAROBJFIX</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOptions" title="en/JS_SetOptions">JSOPTION_WERROR</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOptions" title="en/JS_SetOptions">JSOPTION_XML</a></li> - <li><a href="/En/SpiderMonkey/JSAPI_Reference/JS_ToggleOptions" title="en/JS_ToggleOptions">JS_ToggleOptions</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetBranchCallback" title="en/JS_SetBranchCallback">JS_SetBranchCallback</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOperationCallback" title="en/JS_SetOperationCallback">JS_SetOperationCallback</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOperationCallback" title="en/JS_SetOperationCallback">JS_ClearOperationCallback</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOperationCallback" title="en/JS_SetOperationCallback">JS_GetOperationCallback</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOperationCallback" title="en/JS_SetOperationCallback">JS_GetOperationLimit</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOperationCallback" title="en/JS_SetOperationCallback">JS_SetOperationLimit</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOperationCallback" title="en/JS_SetOperationCallback">JS_MAX_OPERATION_LIMIT</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetOperationCallback" title="en/JS_SetOperationCallback">JS_OPERATION_WEIGHT_BASE</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetThreadStackLimit" title="en/JS_SetThreadStackLimit">JS_SetThreadStackLimit</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetScriptStackQuota" title="en/JS_SetScriptStackQuota">JS_SetScriptStackQuota</a></li> -</ul> -<ul> - <li>enum <a href="/en/SpiderMonkey/JSAPI_Reference/JSVersion" title="en/JSVersion">JSVersion</a>, <a href="/en/JSVERSION_ECMA_3" title="en/JSVERSION_ECMA_3">JSVERSION_ECMA_3</a>, <a href="/en/JSVERSION_DEFAULT" title="en/JSVERSION_DEFAULT">JSVERSION_DEFAULT</a>, <a href="/en/JSVERSION_LATEST" title="en/JSVERSION_LATEST">JSVERSION_LATEST</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetImplementationVersion" title="en/JS_GetImplementationVersion">JS_GetImplementationVersion</a></li> - <li><a class="internal" href="/cn/SpiderMonkey/JSAPI%20%E5%8F%82%E8%80%83/JS%20GetVersion" title="cn/SpiderMonkey/JSAPI 参考/JS GetVersion">JS_GetVersion</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetVersion" title="en/JS_SetVersion">JS_SetVersion</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_StringToVersion" title="en/JS_StringToVersion">JS_StringToVersion</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_VersionToString" title="en/JS_VersionToString">JS_VersionToString</a></li> -</ul> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetGlobalObject" title="en/JS_GetGlobalObject">JS_GetGlobalObject</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGlobalObject" title="en/JS_SetGlobalObject">JS_SetGlobalObject</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_InitClass" title="en/JS_InitClass">JS_InitClass</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_InitStandardClasses" title="en/JS_InitStandardClasses">JS_InitStandardClasses</a></li> - <li><a href="/en/JS_ResolveStandardClass" title="en/JS_ResolveStandardClass">JS_ResolveStandardClass</a></li> - <li><a href="/en/JS_EnumerateStandardClasses" title="en/JS_EnumerateStandardClasses">JS_EnumerateStandardClasses</a></li> - <li><a href="/en/JS_EnumerateResolvedStandardClasses" title="en/JS_EnumerateResolvedStandardClasses">JS_EnumerateResolvedStandardClasses</a></li> -</ul> -<ul> - <li><a href="/en/JS_IsAssigning" title="en/JS_IsAssigning">JS_IsAssigning</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_IsConstructing" title="en/JS_IsConstructing">JS_IsConstructing</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_IsRunning" title="en/JS_IsRunning">JS_IsRunning</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetScopeChain" title="en/JS_GetScopeChain">JS_GetScopeChain</a></li> - <li><a href="/en/JS_SaveFrameChain" title="en/JS_SaveFrameChain">JS_SaveFrameChain</a>, <a href="/en/JS_RestoreFrameChain" title="en/JS_RestoreFrameChain">JS_RestoreFrameChain</a></li> -</ul> -<p>Locale callbacks:</p> -<ul> - <li>struct <a href="/en/JSLocaleCallbacks" title="en/JSLocaleCallbacks">JSLocaleCallbacks</a></li> - <li><a href="/en/JS_GetLocaleCallbacks" title="en/JS_GetLocaleCallbacks">JS_GetLocaleCallbacks</a></li> - <li><a href="/en/JS_SetLocaleCallbacks" title="en/JS_SetLocaleCallbacks">JS_SetLocaleCallbacks</a></li> -</ul> -<p>Locale callback types:</p> -<ul> - <li><a href="/en/JSLocaleToUpperCase" title="en/JSLocaleToUpperCase">JSLocaleToUpperCase</a></li> - <li><a href="/en/JSLocaleToLowerCase" title="en/JSLocaleToLowerCase">JSLocaleToLowerCase</a></li> - <li><a href="/en/JSLocaleCompare" title="en/JSLocaleCompare">JSLocaleCompare</a></li> - <li><a href="/en/JSLocaleToUnicode" title="en/JSLocaleToUnicode">JSLocaleToUnicode</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ReportErrorNumber" title="en/JS_ReportErrorNumber">JSErrorCallback</a></li> -</ul> -<h3 id="Scripts" name="Scripts">脚本</h3> -<p>Just running some JavaScript code is straightforward:</p> -<p>只是运行一些JavaScript代码很简单:</p> -<ul> - <li><a class="internal" href="/Cn/SpiderMonkey/JSAPI_%E5%8F%82%E8%80%83/JS_EvaluateScript" title="cn/SpiderMonkey/JSAPI 参考/JS EvaluateScript">JS_EvaluateScript</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_EvaluateScript" title="en/JS_EvaluateScript">JS_EvaluateUCScript</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_EvaluateScriptForPrincipals" title="en/JS_EvaluateScriptForPrincipals">JS_EvaluateScriptForPrincipals</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_EvaluateScriptForPrincipals" title="en/JS_EvaluateScriptForPrincipals">JS_EvaluateUCScriptForPrincipals</a></li> -</ul> -<p>You can instead compile JavaScript code into a <code>JSScript</code> which you can then execute multiple times.</p> -<p>你可以将JavaScript代码编译后保存在<code>JSScript类型的变量中,这样就可以多次执行。</code></p> -<p>typedef <a href="/en/JSScript" title="en/JSScript">JSScript</a></p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CompileFile" title="en/JS_CompileFile">JS_CompileFile</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CompileFileHandle" title="en/JS_CompileFileHandle">JS_CompileFileHandle</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CompileFileHandle" title="en/JS_CompileFileHandle">JS_CompileFileHandleForPrincipals</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CompileScript" title="en/JS_CompileScript">JS_CompileScript</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CompileScript" title="en/JS_CompileScript">JS_CompileUCScript</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CompileScriptForPrincipals" title="en/JS_CompileScriptForPrincipals">JS_CompileScriptForPrincipals</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CompileScriptForPrincipals" title="en/JS_CompileScriptForPrincipals">JS_CompileUCScriptForPrincipals</a></li> - <li><a href="/en/JS_BufferIsCompilableUnit" title="en/JS_BufferIsCompilableUnit">JS_BufferIsCompilableUnit</a></li> - <li><a href="/en/JS_GetScriptObject" title="en/JS_GetScriptObject">JS_GetScriptObject</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewScriptObject" title="en/JS_NewScriptObject">JS_NewScriptObject</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ExecuteScript" title="en/JS_ExecuteScript">JS_ExecuteScript</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ExecuteScriptPart" title="en/JS_ExecuteScriptPart">JS_ExecuteScriptPart</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DecompileScript" title="en/JS_DecompileScript">JS_DecompileScript</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DestroyScript" title="en/JS_DestroyScript">JS_DestroyScript</a></li> -</ul> -<p>You can also compile JavaScript code into a function:</p> -<ul> - <li>typedef <a href="/en/JSFunction" title="en/JSFunction">JSFunction</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CompileFunction" title="en/JS_CompileFunction">JS_CompileFunction</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CompileFunctionForPrincipals" title="en/JS_CompileFunctionForPrincipals">JS_CompileFunctionForPrincipals</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CompileFunction" title="en/JS_CompileFunction">JS_CompileUCFunction</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CompileFunctionForPrincipals" title="en/JS_CompileFunctionForPrincipals">JS_CompileUCFunctionForPrincipals</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DecompileFunction" title="en/JS_DecompileFunction">JS_DecompileFunction</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DecompileFunctionBody" title="en/JS_DecompileFunctionBody">JS_DecompileFunctionBody</a></li> -</ul> -<p> </p> -<h3 id="Error_handling" name="Error_handling">错误处理</h3> -<ul> - <li>struct <a href="/en/SpiderMonkey/JSAPI_Reference/JSErrorReport" title="en/JSErrorReport">JSErrorReport</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ReportError" title="en/JS_ReportError">JS_ReportError</a></li> - <li><a href="/en/JS_ReportWarning" title="en/JS_ReportWarning">JS_ReportWarning</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ReportErrorNumber" title="en/JS_ReportErrorNumber">JS_ReportErrorNumber</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_ReportErrorNumber" title="en/JS_ReportErrorNumber">JS_ReportErrorNumberUC</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_ReportErrorNumber" title="en/JS_ReportErrorNumber">JS_ReportErrorFlagsAndNumber</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_ReportErrorNumber" title="en/JS_ReportErrorNumber">JS_ReportErrorFlagsAndNumberUC</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ReportOutOfMemory" title="en/JS_ReportOutOfMemory">JS_ReportOutOfMemory</a></li> - <li><a class="internal" href="/cn/SpiderMonkey/JSAPI%20%E5%8F%82%E8%80%83/JS_%20SetErrorReporter" title="cn/SpiderMonkey/JSAPI 参考/JS SetErrorReporter">JS_SetErrorReporter</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSREPORT_IS_EXCEPTION" title="en/JSREPORT_IS_EXCEPTION">JSREPORT_IS_EXCEPTION</a></li> - <li><a href="/en/JSREPORT_IS_STRICT" title="en/JSREPORT_IS_STRICT">JSREPORT_IS_STRICT</a></li> - <li><a href="/en/JSREPORT_IS_WARNING" title="en/JSREPORT_IS_WARNING">JSREPORT_IS_WARNING</a></li> -</ul> -<p>The following functions allow C/C++ functions to throw and catch JavaScript exceptions:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_IsExceptionPending" title="en/JS_IsExceptionPending">JS_IsExceptionPending</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPendingException" title="en/JS_GetPendingException">JS_GetPendingException</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetPendingException" title="en/JS_SetPendingException">JS_SetPendingException</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ClearPendingException" title="en/JS_ClearPendingException">JS_ClearPendingException</a></li> - <li><a href="/en/JS_ThrowStopIteration" title="en/JS_ThrowStopIteration">JS_ThrowStopIteration</a></li> -</ul> -<ul> - <li>typedef <a href="/en/SpiderMonkey/JSAPI_Reference/JSExceptionState" title="en/JSExceptionState">JSExceptionState</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SaveExceptionState" title="en/JS_SaveExceptionState">JS_SaveExceptionState</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_RestoreExceptionState" title="en/JS_RestoreExceptionState">JS_RestoreExceptionState</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DropExceptionState" title="en/JS_DropExceptionState">JS_DropExceptionState</a></li> -</ul> -<p>These functions translate errors into exceptions and vice versa:</p> -<ul> - <li><a href="/en/JS_ReportPendingException" title="en/JS_ReportPendingException">JS_ReportPendingException</a></li> - <li><a href="/en/JS_ErrorFromException" title="en/JS_ErrorFromException">JS_ErrorFromException</a></li> - <li><a href="/en/JS_ThrowReportedError" title="en/JS_ThrowReportedError">JS_ThrowReportedError</a></li> -</ul> -<h3 id="Values_and_types" name="Values_and_types">值和类型</h3> -<ul> - <li>typedef <a href="/En/SpiderMonkey/JSAPI_Reference/Jsval" title="en/jsval">jsval</a></li> -</ul> -<p><code>jsval</code> constants:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_NULL" title="en/JSVAL_NULL">JSVAL_NULL</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_VOID" title="en/JSVAL_VOID">JSVAL_VOID</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_TRUE" title="en/JSVAL_TRUE">JSVAL_TRUE</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_TRUE" title="en/JSVAL_TRUE">JSVAL_FALSE</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_ZERO" title="en/JSVAL_ZERO">JSVAL_ZERO</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_ONE" title="en/JSVAL_ONE">JSVAL_ONE</a></li> -</ul> -<p>Function and macros for checking the type of a <code>jsval</code>:</p> -<ul> - <li>enum <a href="/en/SpiderMonkey/JSAPI_Reference/JSType" title="en/JSType">JSType</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_TypeOfValue" title="en/JS_TypeOfValue">JS_TypeOfValue</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_IS_NULL" title="en/JSVAL_IS_NULL">JSVAL_IS_NULL</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_IS_VOID" title="en/JSVAL_IS_VOID">JSVAL_IS_VOID</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_IS_BOOLEAN" title="en/JSVAL_IS_BOOLEAN">JSVAL_IS_BOOLEAN</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_IS_NUMBER" title="en/JSVAL_IS_NUMBER">JSVAL_IS_NUMBER</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_IS_INT" title="en/JSVAL_IS_INT">JSVAL_IS_INT</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_IS_DOUBLE" title="en/JSVAL_IS_DOUBLE">JSVAL_IS_DOUBLE</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_IS_STRING" title="en/JSVAL_IS_STRING">JSVAL_IS_STRING</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_IS_OBJECT" title="en/JSVAL_IS_OBJECT">JSVAL_IS_OBJECT</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_IS_PRIMITIVE" title="en/JSVAL_IS_PRIMITIVE">JSVAL_IS_PRIMITIVE</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_IS_GCTHING" title="en/JSVAL_IS_GCTHING">JSVAL_IS_GCTHING</a></li> -</ul> -<p>High-level type-conversion routines for packing and unpacking function arguments.</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_PushArguments" title="en/JS_PushArguments">JS_PushArguments</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_PushArguments" title="en/JS_PushArguments">JS_PushArgumentsVA</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_PopArguments" title="en/JS_PopArguments">JS_PopArguments</a></li> -</ul> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ConvertArguments" title="en/JS_ConvertArguments">JS_ConvertArguments</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ConvertArgumentsVA" title="en/JS_ConvertArgumentsVA">JS_ConvertArgumentsVA</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_AddArgumentFormatter" title="en/JS_AddArgumentFormatter">JS_AddArgumentFormatter</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_AddArgumentFormatter" title="en/JS_AddArgumentFormatter">JS_RemoveArgumentFormatter</a></li> -</ul> -<p>The following functions convert JS values to various types. They can be safely applied to <code>jsval</code>s of any type. They may return new objects. For example, <code>JS_ValueToObject(cx, s)</code> where <code>s</code> is a string creates a new <code>String</code> wrapper object. These functions may call JavaScript methods. For example, <code>JS_ValueToString(cx, obj)</code> may call <code>obj.toString()</code>.</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ValueToBoolean" title="en/JS_ValueToBoolean">JS_ValueToBoolean</a></li> - <li><a href="/en/JS_ValueToConstructor" title="en/JS_ValueToConstructor">JS_ValueToConstructor</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ValueToECMAInt32" title="en/JS_ValueToECMAInt32">JS_ValueToECMAInt32</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ValueToECMAInt32" title="en/JS_ValueToECMAInt32">JS_ValueToECMAUint32</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ValueToFunction" title="en/JS_ValueToFunction">JS_ValueToFunction</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ValueToInt32" title="en/JS_ValueToInt32">JS_ValueToInt32</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ValueToNumber" title="en/JS_ValueToNumber">JS_ValueToNumber</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ValueToObject" title="en/JS_ValueToObject">JS_ValueToObject</a></li> - <li><a class="internal" href="/cn/SpiderMonkey/JSAPI%20%E5%8F%82%E8%80%83/JS%20ValueToString" title="cn/SpiderMonkey/JSAPI 参考/JS ValueToString">JS_ValueToString</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ValueToECMAInt32" title="en/JS_ValueToECMAInt32">JS_ValueToUint16</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ConvertValue" title="en/JS_ConvertValue">JS_ConvertValue</a></li> -</ul> -<p>Fast, unchecked type-casting macros. These macros must not be applied to values that are not known to be the right type. Like C casts, they may cause crashes if applied to incorrect values. They never create new objects or call into JavaScript code.</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_TO_BOOLEAN" title="en/JSVAL_TO_BOOLEAN">JSVAL_TO_BOOLEAN</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/BOOLEAN_TO_JSVAL" title="en/BOOLEAN_TO_JSVAL">BOOLEAN_TO_JSVAL</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_TO_INT" title="en/JSVAL_TO_INT">JSVAL_TO_INT</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/INT_TO_JSVAL" title="en/INT_TO_JSVAL">INT_TO_JSVAL</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/INT_FITS_IN_JSVAL" title="en/INT_FITS_IN_JSVAL">INT_FITS_IN_JSVAL</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_TO_DOUBLE" title="en/JSVAL_TO_DOUBLE">JSVAL_TO_DOUBLE</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/DOUBLE_TO_JSVAL" title="en/DOUBLE_TO_JSVAL">DOUBLE_TO_JSVAL</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_TO_OBJECT" title="en/JSVAL_TO_OBJECT">JSVAL_TO_OBJECT</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/OBJECT_TO_JSVAL" title="en/OBJECT_TO_JSVAL">OBJECT_TO_JSVAL</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_TO_STRING" title="en/JSVAL_TO_STRING">JSVAL_TO_STRING</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/STRING_TO_JSVAL" title="en/STRING_TO_JSVAL">STRING_TO_JSVAL</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_TO_GCTHING" title="en/JSVAL_TO_GCTHING">JSVAL_TO_GCTHING</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/PRIVATE_TO_JSVAL" title="en/PRIVATE_TO_JSVAL">JSVAL_TO_PRIVATE</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/PRIVATE_TO_JSVAL" title="en/PRIVATE_TO_JSVAL">PRIVATE_TO_JSVAL</a></li> -</ul> -<p>And:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetTypeName" title="en/JS_GetTypeName">JS_GetTypeName</a></li> -</ul> -<h3 id="Memory_management" name="Memory_management">Memory management</h3> -<p>These functions act like the Standard C <code>malloc</code> family of functions, except that errors are reported using the SpiderMonkey error APIs rather than <code>errno</code>. These functions also allow SpiderMonkey to account the number of bytes allocated:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_malloc" title="en/JS_malloc">JS_malloc</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_free" title="en/JS_free">JS_free</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_realloc" title="en/JS_realloc">JS_realloc</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_strdup" title="en/JS_strdup">JS_strdup</a></li> -</ul> -<p>JavaScript objects, strings, and floating-point numbers are garbage collected. These functions provide access to the garbage collector:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GC" title="en/JS_GC">JS_GC</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_MaybeGC" title="en/JS_MaybeGC">JS_MaybeGC</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCParameter" title="en/JS_SetGCParameter">JS_SetGCParameter</a>, enum <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCParameter" title="en/JS_SetGCParameter">JSGCParamKey</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCParameter" title="en/JS_SetGCParameter">JSGC_MAX_BYTES</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCParameter" title="en/JS_SetGCParameter">JSGC_MAX_MALLOC_BYTES</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCParameter" title="en/JS_SetGCParameter">JSGC_STACKPOOL_LIFESPAN</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCCallback" title="en/JS_SetGCCallback">JS_SetGCCallback</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCCallback" title="en/JS_SetGCCallback">JS_SetGCCallbackRT</a>, enum <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCCallback" title="en/JS_SetGCCallback">JSGCStatus</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCCallback" title="en/JS_SetGCCallback">JSGC_BEGIN</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCCallback" title="en/JS_SetGCCallback">JSGC_MARK_END</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCCallback" title="en/JS_SetGCCallback">JSGC_FINALIZE_END</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCCallback" title="en/JS_SetGCCallback">JSGC_END</a></li> - <li><a href="/en/JS_MarkGCThing" title="en/JS_MarkGCThing">JS_MarkGCThing</a></li> - <li><a href="/en/JS_IsAboutToBeFinalized" title="en/JS_IsAboutToBeFinalized">JS_IsAboutToBeFinalized</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ClearNewbornRoots" title="en/JS_ClearNewbornRoots">JS_ClearNewbornRoots</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCZeal" title="en/JS_SetGCZeal">JS_SetGCZeal</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DumpHeap" title="en/JS_DumpHeap">JS_DumpHeap</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> -</ul> -<p>The rest of these APIs help protect objects from being destroyed by the garbage collector before the application is done using them.</p> -<p>If a variable is a <em>root</em>, then anything it points to will not be freed by the garbage collector. Failure to root objects is a very common cause of mysterious crashes.</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_AddRoot" title="en/JS_AddRoot">JS_AddRoot</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_AddRoot" title="en/JS_AddRoot">JS_AddNamedRoot</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_AddRoot" title="en/JS_AddRoot">JS_AddNamedRootRT</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_RemoveRoot" title="en/JS_RemoveRoot">JS_RemoveRoot</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_RemoveRootRT" title="en/JS_RemoveRootRT">JS_RemoveRootRT</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_MapGCRoots" title="en/JS_MapGCRoots">JS_MapGCRoots</a>, <a href="/en/JSGCMapRootFun" title="en/JSGCMapRootFun">JSGCMapRootFun</a> – <a href="/en/JS_MAP_GCROOT_NEXT" title="en/JS_MAP_GCROOT_NEXT">JS_MAP_GCROOT_NEXT</a>, <a href="/en/JS_MAP_GCROOT_REMOVE" title="en/JS_MAP_GCROOT_REMOVE">JS_MAP_GCROOT_REMOVE</a>, <a href="/en/JS_MAP_GCROOT_STOP" title="en/JS_MAP_GCROOT_STOP">JS_MAP_GCROOT_STOP</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DumpNamedRoots" title="en/JS_DumpNamedRoots">JS_DumpNamedRoots</a></li> -</ul> -<p>Local root scopes are another way of protecting objects from the garbage collector.</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_EnterLocalRootScope" title="en/JS_EnterLocalRootScope">JS_EnterLocalRootScope</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_LeaveLocalRootScope" title="en/JS_LeaveLocalRootScope">JS_LeaveLocalRootScope</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_LeaveLocalRootScopeWithResult" title="en/JS_LeaveLocalRootScopeWithResult">JS_LeaveLocalRootScopeWithResult</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ForgetLocalRoot" title="en/JS_ForgetLocalRoot">JS_ForgetLocalRoot</a></li> -</ul> -<p>{{ Jsapi_minversion_inline("1.8 (not yet released)") }} If an object contains references to other GC things that are not stored in SpiderMonkey data structures ("slots"), it must implement the <code><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.mark" title="en/JSClass.mark">JSTraceOp</a></code> hook to enable the garbage collector to traverse those references. Otherwise the garbage collector will not find all reachable objects and may collect objects that are still reachable, leading to a crash. (In SpiderMonkey 1.7 and earlier, the <code>JSMarkOp</code> hook is used instead. This will be deprecated when SpiderMonkey 1.8 is released.)</p> -<p>The tracing APIs are used by the garbage collector and <code>JSTraceOp</code> hooks. JSAPI applications may also use them to examine the object graph. (For example, these APIs support very smooth integration between the JS garbage collector and other garbage collectors.)</p> -<ul> - <li><a href="/en/JSVAL_IS_TRACEABLE" title="en/JSVAL_IS_TRACEABLE">JSVAL_IS_TRACEABLE</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/JSVAL_TO_TRACEABLE" title="en/JSVAL_TO_TRACEABLE">JSVAL_TO_TRACEABLE</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/JSVAL_TRACE_KIND" title="en/JSVAL_TRACE_KIND">JSVAL_TRACE_KIND</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li>struct <a href="/en/JSTracer" title="en/JSTracer">JSTracer</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_TRACER_INIT" title="en/JS_TRACER_INIT">JS_TRACER_INIT</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/JS_CallTracer" title="en/JS_CallTracer">JS_CallTracer</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SET_TRACING_DETAILS" title="en/JS_SET_TRACING_DETAILS">JS_SET_TRACING_DETAILS</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/JS_SET_TRACING_INDEX" title="en/JS_SET_TRACING_INDEX">JS_SET_TRACING_INDEX</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/JS_SET_TRACING_NAME" title="en/JS_SET_TRACING_NAME">JS_SET_TRACING_NAME</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/JS_CALL_TRACER" title="en/JS_CALL_TRACER">JS_CALL_TRACER</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/JS_CALL_VALUE_TRACER" title="en/JS_CALL_VALUE_TRACER">JS_CALL_VALUE_TRACER</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/JS_CALL_OBJECT_TRACER" title="en/JS_CALL_OBJECT_TRACER">JS_CALL_OBJECT_TRACER</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/JS_CALL_STRING_TRACER" title="en/JS_CALL_STRING_TRACER">JS_CALL_STRING_TRACER</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/JS_CALL_DOUBLE_TRACER" title="en/JS_CALL_DOUBLE_TRACER">JS_CALL_DOUBLE_TRACER</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/JS_TraceChildren" title="en/JS_TraceChildren">JS_TraceChildren</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/JS_TraceRuntime" title="en/JS_TraceRuntime">JS_TraceRuntime</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/JS_PrintTraceThingInfo" title="en/JS_PrintTraceThingInfo">JS_PrintTraceThingInfo</a> (DEBUG-only) {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> -</ul> -<p>Miscellaneous GC APIs:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_LOCK" title="en/JSVAL_LOCK">JSVAL_LOCK</a> {{ Deprecated_inline() }}</li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSVAL_UNLOCK" title="en/JSVAL_UNLOCK">JSVAL_UNLOCK</a> {{ Deprecated_inline() }}</li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_LockGCThing" title="en/JS_LockGCThing">JS_LockGCThing</a> {{ Deprecated_inline() }}</li> - <li><a href="/en/JS_LockGCThingRT" title="en/JS_LockGCThingRT">JS_LockGCThingRT</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_LockGCThing" title="en/JS_LockGCThing">JS_UnlockGCThing</a> {{ Deprecated_inline() }}</li> - <li><a href="/en/JS_UnlockGCThingRT" title="en/JS_UnlockGCThingRT">JS_UnlockGCThingRT</a></li> -</ul> -<h3 id="Numbers" name="Numbers">Numbers</h3> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewNumberValue" title="en/JS_NewNumberValue">JS_NewNumberValue</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewDoubleValue" title="en/JS_NewDoubleValue">JS_NewDoubleValue</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewDouble" title="en/JS_NewDouble">JS_NewDouble</a></li> - <li>struct <a href="/en/SpiderMonkey/JSAPI_Reference/JSConstDoubleSpec" title="en/JSConstDoubleSpec">JSConstDoubleSpec</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DefineConstDoubles" title="en/JS_DefineConstDoubles">JS_DefineConstDoubles</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetNaNValue" title="en/JS_GetNaNValue">JS_GetNaNValue</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPositiveInfinityValue" title="en/JS_GetPositiveInfinityValue">JS_GetNegativeInfinityValue</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPositiveInfinityValue" title="en/JS_GetPositiveInfinityValue">JS_GetPositiveInfinityValue</a></li> -</ul> -<h3 id="Strings" name="Strings">字符串</h3> -<ul> - <li>typedef <a href="/en/SpiderMonkey/JSAPI_Reference/JSString" title="en/JSString">JSString</a></li> - <li>typedef <a href="/en/SpiderMonkey/JSAPI_Reference/jschar" title="en/jschar">jschar</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewString" title="en/JS_NewString">JS_NewString</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewStringCopyN" title="en/JS_NewStringCopyN">JS_NewStringCopyN</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewStringCopyZ" title="en/JS_NewStringCopyZ">JS_NewStringCopyZ</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewString" title="en/JS_NewString">JS_NewUCString</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewStringCopyN" title="en/JS_NewStringCopyN">JS_NewUCStringCopyN</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewStringCopyZ" title="en/JS_NewStringCopyZ">JS_NewUCStringCopyZ</a></li> - <li><a href="/en/JS_NewGrowableString" title="en/JS_NewGrowableString">JS_NewGrowableString</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewDependentString" title="en/JS_NewDependentString">JS_NewDependentString</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetEmptyStringValue" title="en/JS_GetEmptyStringValue">JS_GetEmptyStringValue</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CompareStrings" title="en/JS_CompareStrings">JS_CompareStrings</a></li> - <li><a href="/en/JS_ConcatStrings" title="en/JS_ConcatStrings">JS_ConcatStrings</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetStringBytes" title="en/JS_GetStringBytes">JS_GetStringBytes</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetStringChars" title="en/JS_GetStringChars">JS_GetStringChars</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetStringLength" title="en/JS_GetStringLength">JS_GetStringLength</a></li> - <li><a href="/en/JS_MakeStringImmutable" title="en/JS_MakeStringImmutable">JS_MakeStringImmutable</a></li> - <li><a href="/en/JS_UndependString" title="en/JS_UndependString">JS_UndependString</a></li> -</ul> -<ul> - <li><a href="/en/JS_CStringsAreUTF8" title="en/JS_CStringsAreUTF8">JS_CStringsAreUTF8</a></li> - <li><a href="/en/JS_SetCStringsAreUTF8" title="en/JS_SetCStringsAreUTF8">JS_SetCStringsAreUTF8</a></li> - <li><a href="/en/JS_DecodeBytes" title="en/JS_DecodeBytes">JS_DecodeBytes</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_EncodeCharacters" title="en/JS_EncodeCharacters">JS_EncodeCharacters</a></li> - <li><a href="/en/JS_EncodeString" title="en/JS_EncodeString">JS_EncodeString</a></li> -</ul> -<p><em>Interning</em> strings tells the SpiderMonkey engine to reuse existing string objects when possible.</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_InternString" title="en/JS_InternString">JS_InternString</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_InternString" title="en/JS_InternString">JS_InternUCString</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_InternString" title="en/JS_InternString">JS_InternUCStringN</a></li> -</ul> -<p>The character data for <em>external strings</em> is stored in memory provided by the application. Applications can use this to avoid copying data back and forth between SpiderMonkey's heap and application memory.</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_AddExternalStringFinalizer" title="en/JS_AddExternalStringFinalizer">JS_AddExternalStringFinalizer</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_RemoveExternalStringFinalizer" title="en/JS_RemoveExternalStringFinalizer">JS_RemoveExternalStringFinalizer</a></li> - <li><a href="/en/JS_GetExternalStringGCType" title="en/JS_GetExternalStringGCType">JS_GetExternalStringGCType</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewExternalString" title="en/JS_NewExternalString">JS_NewExternalString</a></li> -</ul> -<h3 id="Objects" name="Objects">对象</h3> -<ul> - <li>typedef <a href="/en/SpiderMonkey/JSAPI_Reference/JSObject" title="en/JSObject">JSObject</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ConstructObject" title="en/JS_ConstructObject">JS_ConstructObject</a></li> - <li><a href="/en/JS_ConstructObjectWithArguments" title="en/JS_ConstructObjectWithArguments">JS_ConstructObjectWithArguments</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DefineObject" title="en/JS_DefineObject">JS_DefineObject</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewObject" title="en/JS_NewObject">JS_NewObject</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewObject" title="en/JS_NewObject">JS_NewObjectWithGivenProto</a></li> -</ul> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GET_CLASS" title="en/JS_GET_CLASS">JS_GET_CLASS</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GET_CLASS" title="en/JS_GET_CLASS">JS_GetClass</a></li> - <li><a href="/en/JS_GetClassObject" title="en/JS_GetClassObject">JS_GetClassObject</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetConstructor" title="en/JS_GetConstructor">JS_GetConstructor</a></li> - <li><a href="/en/JS_GetGlobalForObject" title="en/JS_GetGlobalForObject">JS_GetGlobalForObject</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetInstancePrivate" title="en/JS_GetInstancePrivate">JS_GetInstancePrivate</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetParent" title="en/JS_GetParent">JS_GetParent</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetParent" title="en/JS_SetParent">JS_SetParent</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPrivate" title="en/JS_GetPrivate">JS_GetPrivate</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetPrivate" title="en/JS_SetPrivate">JS_SetPrivate</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPrototype" title="en/JS_GetPrototype">JS_GetPrototype</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetPrototype" title="en/JS_SetPrototype">JS_SetPrototype</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetReservedSlot" title="en/JS_GetReservedSlot">JS_GetReservedSlot</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetReservedSlot" title="en/JS_GetReservedSlot">JS_SetReservedSlot</a></li> - <li><a href="/en/JS_HasInstance" title="en/JS_HasInstance">JS_HasInstance</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_InstanceOf" title="en/JS_InstanceOf">JS_InstanceOf</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SealObject" title="en/JS_SealObject">JS_SealObject</a></li> -</ul> -<h3 id="Properties" name="Properties">属性</h3> -<p>These functions correspond directly to the ways scripts access object properties:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetProperty" title="en/JS_GetProperty">JS_GetProperty</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetProperty" title="en/JS_GetProperty">JS_GetUCProperty</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetProperty" title="en/JS_SetProperty">JS_SetProperty</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetProperty" title="en/JS_SetProperty">JS_SetUCProperty</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_HasProperty" title="en/JS_HasProperty">JS_HasProperty</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_HasProperty" title="en/JS_HasProperty">JS_HasUCProperty</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DeleteProperty" title="en/JS_DeleteProperty">JS_DeleteProperty</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_DeleteProperty2" title="en/JS_DeleteProperty2">JS_DeleteProperty2</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_DeleteProperty2" title="en/JS_DeleteProperty2">JS_DeleteUCProperty2</a></li> -</ul> -<p>The following functions are lower-level, allowing the JSAPI application more access to details of how properties are implemented. "Define" is a lower-level version of "set" that provides access to extra settings and does not call setters. Similarly, "lookup" is a lower-level version of "get" that offers extra options and does not call getters.</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_AlreadyHasOwnProperty" title="en/JS_AlreadyHasOwnElement">JS_AlreadyHasOwnElement</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_AlreadyHasOwnProperty" title="en/JS_AlreadyHasOwnProperty">JS_AlreadyHasOwnProperty</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_AlreadyHasOwnProperty" title="en/JS_AlreadyHasOwnProperty">JS_AlreadyHasOwnUCProperty</a> {{ Jsapi_minversion_inline("1.8 (not yet released)") }}</li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ClearScope" title="en/JS_ClearScope">JS_ClearScope</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DefineProperties" title="en/JS_DefineProperties">JS_DefineProperties</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DefineProperty" title="en/JS_DefineProperty">JS_DefineProperty</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_DefineProperty" title="en/JS_DefineProperty">JS_DefineUCProperty</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DefinePropertyWithTinyId" title="en/JS_DefinePropertyWithTinyId">JS_DefinePropertyWithTinyId</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_DefinePropertyWithTinyId" title="en/JS_DefinePropertyWithTinyId">JS_DefineUCPropertyWithTinyId</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_Enumerate" title="en/JS_Enumerate">JS_Enumerate</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPropertyAttributes" title="en/JS_GetPropertyAttributes">JS_GetPropertyAttributes</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPropertyAttributes" title="en/JS_GetPropertyAttributes">JS_GetUCPropertyAttributes</a> – <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPropertyAttributes" title="en/JS_GetPropertyAttributes">JSPROP_ENUMERATE</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPropertyAttributes" title="en/JS_GetPropertyAttributes">JSPROP_EXPORTED</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPropertyAttributes" title="en/JS_GetPropertyAttributes">JSPROP_GETTER</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPropertyAttributes" title="en/JS_GetPropertyAttributes">JSPROP_INDEX</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPropertyAttributes" title="en/JS_GetPropertyAttributes">JSPROP_PERMANENT</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPropertyAttributes" title="en/JS_GetPropertyAttributes">JSPROP_READONLY</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPropertyAttributes" title="en/JS_GetPropertyAttributes">JSPROP_SETTER</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPropertyAttributes" title="en/JS_GetPropertyAttributes">JSPROP_SHARED</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPropertyAttrsGetterAndSetter" title="en/JS_GetPropertyAttrsGetterAndSetter">JS_GetPropertyAttrsGetterAndSetter</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetPropertyAttrsGetterAndSetter" title="en/JS_GetPropertyAttrsGetterAndSetter">JS_GetUCPropertyAttrsGetterAndSetter</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_LookupProperty" title="en/JS_LookupProperty">JS_LookupProperty</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_LookupProperty" title="en/JS_LookupProperty">JS_LookupUCProperty</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_LookupProperty" title="en/JS_LookupProperty">JS_LookupPropertyWithFlags</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewPropertyIterator" title="en/JS_NewPropertyIterator">JS_NewPropertyIterator</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NextProperty" title="en/JS_NextProperty">JS_NextProperty</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetPropertyAttributes" title="en/JS_SetPropertyAttributes">JS_SetPropertyAttributes</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetPropertyAttributes" title="en/JS_SetPropertyAttributes">JS_SetUCPropertyAttributes</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_AliasProperty" title="en/JS_AliasProperty">JS_AliasProperty</a> {{ Deprecated_inline() }}</li> -</ul> -<p>The following functions behave like <code>JS_GetProperty</code> except when operating on E4X XML objects.</p> -<ul> - <li><a href="/en/JS_GetMethod" title="en/JS_GetMethod">JS_GetMethod</a>, <a href="/en/JS_GetMethodById" title="en/JS_GetMethodById">JS_GetMethodById</a></li> -</ul> -<p>A SpiderMonkey extension allows a native function to return an lvalue—that is, a reference to a property of an object:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetCallReturnValue2" title="en/JS_SetCallReturnValue2">JS_SetCallReturnValue2</a></li> -</ul> -<p>A <code><a href="/en/SpiderMonkey/JSAPI_Reference/jsid" title="en/jsid">jsid</a></code> is kind of like a <code>jsval</code>, only different. A handful of APIs use <code>jsid</code>s instead of <code>jsval</code>s for property names: <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CheckAccess" title="en/JS_CheckAccess">JS_CheckAccess</a></code>, <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_Enumerate" title="en/JS_Enumerate">JS_Enumerate</a></code>, <code><a href="/en/JS_GetMethodById" title="en/JS_GetMethodById">JS_GetMethodById</a></code>, and <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NextProperty" title="en/JS_NextProperty">JS_NextProperty</a></code>.</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_IdToValue" title="en/JS_IdToValue">JS_IdToValue</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_ValueToId" title="en/JS_ValueToId">JS_ValueToId</a></li> - <li><a href="/en/JS_GetObjectId" title="en/JS_GetObjectId">JS_GetObjectId</a></li> - <li>struct <a href="/en/SpiderMonkey/JSAPI_Reference/JSIdArray" title="en/JSIdArray">JSIdArray</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DestroyIdArray" title="en/JS_DestroyIdArray">JS_DestroyIdArray</a></li> -</ul> -<h3 id="Classes" name="Classes">Classes</h3> -<p>These API features are used to define custom classes—object types that are implemented in C/C++ code but accessible from JavaScript.</p> -<ul> - <li>struct <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass" title="en/JSClass">JSClass</a></li> - <li>struct <a href="/en/SpiderMonkey/JSAPI_Reference/JSExtendedClass" title="en/JSExtendedClass">JSExtendedClass</a></li> - <li>struct <a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps" title="en/JSObjectOps">JSObjectOps</a></li> - <li>struct <a href="/en/SpiderMonkey/JSAPI_Reference/JSXMLObjectOps" title="en/JSXMLObjectOps">JSXMLObjectOps</a></li> - <li>struct <a href="/en/JSFunctionSpec" title="en/JSFunctionSpec">JSFunctionSpec</a></li> - <li>struct <a href="/en/SpiderMonkey/JSAPI_Reference/JSProperty" title="en/JSProperty">JSProperty</a></li> - <li>struct <a href="/en/SpiderMonkey/JSAPI_Reference/JSPropertySpec" title="en/JSPropertySpec">JSPropertySpec</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_InitClass" title="en/JS_InitClass">JS_InitClass</a></li> -</ul> -<p>Adding native properties and methods to classes:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSNative" title="en/JSNative">JSNative</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSFastNative" title="en/JSFastNative">JSFastNative</a></li> - <li>struct <a href="/en/JSFunctionSpec" title="en/JSFunctionSpec">JSFunctionSpec</a></li> - <li><a href="/en/JS_FS" title="en/JS_FS">JS_FS</a></li> - <li><a href="/en/JS_FN" title="en/JS_FN">JS_FN</a></li> - <li><a href="/en/JS_FS_END" title="en/JS_FS_END">JS_FS_END</a></li> - <li>struct <a href="/en/SpiderMonkey/JSAPI_Reference/JSPropertySpec" title="en/JSPropertySpec">JSPropertySpec</a></li> -</ul> -<p><code>JSFastNative</code> methods use these macros:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSFastNative" title="en/JSFastNative">JS_CALLEE</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSFastNative" title="en/JSFastNative">JS_THIS</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSFastNative" title="en/JSFastNative">JS_THIS_OBJECT</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSFastNative" title="en/JSFastNative">JS_ARGV</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSFastNative" title="en/JSFastNative">JS_RVAL</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSFastNative" title="en/JSFastNative">JS_SET_RVAL</a></li> -</ul> -<p>The behavior of a <code>JSClass</code> and its instances can be customized in many ways using callback functions.</p> -<p><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass" title="en/JSClass">JSClass</a> method types:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.addProperty" title="en/JSClass.addProperty">JSPropertyOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSEnumerateOp" title="en/JSEnumerateOp">JSEnumerateOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.enumerate" title="en/JSClass.enumerate">JSNewEnumerateOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.resolve" title="en/JSClass.resolve">JSResolveOp</a></li> - <li><a href="/En/SpiderMonkey/JSAPI_Reference/JSNewResolveOp" title="en/JSNewResolveOp">JSNewResolveOp</a> – <a href="/En/SpiderMonkey/JSAPI_Reference/JSNewResolveOp" title="en/JSNewResolveOp">JSRESOLVE_ASSIGNING</a>, <a href="/En/SpiderMonkey/JSAPI_Reference/JSNewResolveOp" title="en/JSNewResolveOp">JSRESOLVE_CLASSNAME</a>, <a href="/En/SpiderMonkey/JSAPI_Reference/JSNewResolveOp" title="en/JSNewResolveOp">JSRESOLVE_DECLARING</a>, <a href="/En/SpiderMonkey/JSAPI_Reference/JSNewResolveOp" title="en/JSNewResolveOp">JSRESOLVE_DETECTING</a>, <a href="/En/SpiderMonkey/JSAPI_Reference/JSNewResolveOp" title="en/JSNewResolveOp">JSRESOLVE_QUALIFIED</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps.defaultValue" title="en/JSObjectOps.defaultValue">JSConvertOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.finalize" title="en/JSClass.finalize">JSFinalizeOp</a></li> - <li><a href="/en/JSClass.getObjectOps" title="en/JSClass.getObjectOps">JSGetObjectOps</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.checkAccess" title="en/JSClass.checkAccess">JSCheckAccessOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.xdrObject" title="en/JSClass.xdrObject">JSXDRObjectOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.hasInstance" title="en/JSClass.hasInstance">JSHasInstanceOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.mark" title="en/JSClass.mark">JSMarkOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSTraceOp" title="en/JSTraceOp">JSTraceOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.reserveSlots" title="en/JSClass.reserveSlots">JSReserveSlotsOp</a></li> -</ul> -<p><a href="/en/SpiderMonkey/JSAPI_Reference/JSExtendedClass" title="en/JSExtendedClass">JSExtendedClass</a> method types:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSExtendedClass.iteratorObject" title="en/JSExtendedClass.iteratorObject">JSIteratorOp</a></li> - <li><a href="/en/JSEqualityOp" title="en/JSEqualityOp">JSEqualityOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOp" title="en/JSObjectOp">JSObjectOp</a></li> -</ul> -<p><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps" title="en/JSObjectOps">JSObjectOps</a> method types:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps.newObjectMap" title="en/JSObjectOps.newObjectMap">JSNewObjectMapOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps.destroyObjectMap" title="en/JSObjectOps.destroyObjectMap">JSObjectMapOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps.lookupProperty" title="en/JSObjectOps.lookupProperty">JSLookupPropOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps.defineProperty" title="en/JSObjectOps.defineProperty">JSDefinePropOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps.getProperty" title="en/JSObjectOps.getProperty">JSPropertyIdOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps.getAttributes" title="en/JSObjectOps.getAttributes">JSAttributesOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps.defaultValue" title="en/JSObjectOps.defaultValue">JSConvertOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.enumerate" title="en/JSClass.enumerate">JSNewEnumerateOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps.checkAccess" title="en/JSObjectOps.checkAccess">JSCheckAccessIdOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOp" title="en/JSObjectOp">JSObjectOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps.dropProperty" title="en/JSObjectOps.dropProperty">JSPropertyRefOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.xdrObject" title="en/JSClass.xdrObject">JSXDRObjectOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.hasInstance" title="en/JSClass.hasInstance">JSHasInstanceOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps.setProto" title="en/JSObjectOps.setProto">JSSetObjectSlotOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSTraceOp" title="en/JSTraceOp">JSTraceOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.finalize" title="en/JSClass.finalize">JSFinalizeOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps.getRequiredSlot" title="en/JSObjectOps.getRequiredSlot">JSGetRequiredSlotOp</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps.getRequiredSlot" title="en/JSObjectOps.getRequiredSlot">JSSetRequiredSlotOp</a></li> -</ul> -<p><a href="/en/SpiderMonkey/JSAPI_Reference/JSXMLObjectOps" title="en/JSXMLObjectOps">JSXMLObjectOps</a> method types:</p> -<ul> - <li><a href="/en/JSGetMethodOp" title="en/JSGetMethodOp">JSGetMethodOp</a></li> - <li><a href="/en/JSSetMethodOp" title="en/JSSetMethodOp">JSSetMethodOp</a></li> - <li><a href="/en/JSEnumerateValuesOp" title="en/JSEnumerateValuesOp">JSEnumerateValuesOp</a></li> - <li><a href="/en/JSEqualityOp" title="en/JSEqualityOp">JSEqualityOp</a></li> - <li><a href="/en/JSConcatenateOp" title="en/JSConcatenateOp">JSConcatenateOp</a></li> -</ul> -<p>These stub functions can be used when creating a custom <code>JSClass</code>:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_PropertyStub" title="en/JS_PropertyStub">JS_ConvertStub</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_PropertyStub" title="en/JS_PropertyStub">JS_EnumerateStub</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_PropertyStub" title="en/JS_PropertyStub">JS_FinalizeStub</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_PropertyStub" title="en/JS_PropertyStub">JS_PropertyStub</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_PropertyStub" title="en/JS_PropertyStub">JS_ResolveStub</a></li> -</ul> -<p>The behavior of a <code>JSClass</code> can be customized using these flags:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.flags" title="en/JSClass.flags">JSClass.flags</a> – <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.flags" title="en/JSClass.flags">JSCLASS_CONSTUCT_PROTOTYPE</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.flags" title="en/JSClass.flags">JSCLASS_GLOBAL_FLAGS</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.flags" title="en/JSClass.flags">JSCLASS_HAS_PRIVATE</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.flags" title="en/JSClass.flags">JSCLASS_HAS_RESERVED_SLOTS</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.flags" title="en/JSClass.flags">JSCLASS_IS_EXTENDED</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.flags" title="en/JSClass.flags">JSCLASS_MARK_IS_TRACE</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.flags" title="en/JSClass.flags">JSCLASS_NEW_ENUMERATE</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.flags" title="en/JSClass.flags">JSCLASS_NEW_RESOLVE</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.flags" title="en/JSClass.flags">JSCLASS_NEW_RESOLVE_GETS_START</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.flags" title="en/JSClass.flags">JSCLASS_PRIVATE_IS_NSISUPPORTS</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.flags" title="en/JSClass.flags">JSCLASS_SHARE_ALL_PROPERTIES</a></li> -</ul> -<h3 id="Arrays" name="Arrays">Arrays</h3> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewArrayObject" title="en/JS_NewArrayObject">JS_NewArrayObject</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_IsArrayObject" title="en/JS_IsArrayObject">JS_IsArrayObject</a></li> -</ul> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_HasArrayLength" title="en/JS_HasArrayLength">JS_HasArrayLength</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetArrayLength" title="en/JS_GetArrayLength">JS_GetArrayLength</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetArrayLength" title="en/JS_SetArrayLength">JS_SetArrayLength</a></li> -</ul> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_AliasElement" title="en/JS_AliasElement">JS_AliasElement</a> {{ Deprecated_inline() }}</li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DefineElement" title="en/JS_DefineElement">JS_DefineElement</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DeleteElement" title="en/JS_DeleteElement">JS_DeleteElement</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DeleteElement2" title="en/JS_DeleteElement2">JS_DeleteElement2</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetElement" title="en/JS_GetElement">JS_GetElement</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_LookupElement" title="en/JS_LookupElement">JS_LookupElement</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetElement" title="en/JS_SetElement">JS_SetElement</a></li> -</ul> -<h3 id="Functions" name="Functions">Functions</h3> -<p>Calling a function or a method of an object:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CallFunction" title="en/JS_CallFunction">JS_CallFunction</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CallFunctionName" title="en/JS_CallFunctionName">JS_CallFunctionName</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CallFunctionValue" title="en/JS_CallFunctionValue">JS_CallFunctionValue</a></li> -</ul> -<p>Function accessors:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ObjectIsFunction" title="en/JS_ObjectIsFunction">JS_ObjectIsFunction</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetFunctionArity" title="en/JS_GetFunctionArity">JS_GetFunctionArity</a></li> - <li><a href="/en/JS_GetFunctionFlags" title="en/JS_GetFunctionFlags">JS_GetFunctionFlags</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetFunctionId" title="en/JS_GetFunctionId">JS_GetFunctionId</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetFunctionName" title="en/JS_GetFunctionName">JS_GetFunctionName</a> {{ Deprecated_inline() }}</li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetFunctionObject" title="en/JS_GetFunctionObject">JS_GetFunctionObject</a></li> -</ul> -<p>Creating functions:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CloneFunctionObject" title="en/JS_CloneFunctionObject">JS_CloneFunctionObject</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DefineFunction" title="en/JS_DefineFunction">JS_DefineFunction</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_DefineFunction" title="en/JS_DefineFunction">JS_DefineUCFunction</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_DefineFunctions" title="en/JS_DefineFunctions">JS_DefineFunctions</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_NewFunction" title="en/JS_NewFunction">JS_NewFunction</a></li> -</ul> -<h3 id="RegExps" name="RegExps">RegExps</h3> -<ul> - <li><a href="/En/SpiderMonkey/JSAPI_Reference/JS_NewRegExpObject" title="En/SpiderMonkey/JSAPI_Reference/JS_NewRegExpObject">JS_NewRegExpObject</a></li> - <li><a href="/En/SpiderMonkey/JSAPI_Reference/JS_NewRegExpObject" title="En/SpiderMonkey/JSAPI_Reference/JS_NewRegExpObject">JS_NewUCRegExpObject</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetRegExpInput" title="en/SpiderMonkey/JSAPI_Reference/JS_SetRegExpInput">JS_SetRegExpInput</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ClearRegExpRoots" title="en/SpiderMonkey/JSAPI_Reference/JS_ClearRegExpRoots">JS_ClearRegExpRoots</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ClearRegExpStatics" title="en/SpiderMonkey/JSAPI_Reference/JS_ClearRegExpStatics">JS_ClearRegExpStatics</a></li> -</ul> -<h3 id="Security" name="Security">Security</h3> -<ul> - <li>struct <a href="/en/SpiderMonkey/JSAPI_Reference/JSPrincipals" title="en/JSPrincipals">JSPrincipals</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSPRINCIPALS_HOLD" title="en/JSPRINCIPALS_HOLD">JSPRINCIPALS_HOLD</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JSPRINCIPALS_HOLD" title="en/JSPRINCIPALS_HOLD">JSPRINCIPALS_DROP</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetObjectPrincipalsFinder" title="en/JS_SetObjectPrincipalsFinder">JS_SetObjectPrincipalsFinder</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetPrincipalsTranscoder" title="en/JS_SetPrincipalsTranscoder">JS_SetPrincipalsTranscoder</a></li> -</ul> -<ul> - <li>enum <a href="/en/SpiderMonkey/JSAPI_Reference/JS_CheckAccess" title="en/JS_CheckAccess">JSAccessMode</a> – <a href="/en/SpiderMonkey/JSAPI_Reference/JS_CheckAccess" title="en/JS_CheckAccess">JSACC_PROTO</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_CheckAccess" title="en/JS_CheckAccess">JSACC_PARENT</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_CheckAccess" title="en/JS_CheckAccess">JSACC_IMPORT</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_CheckAccess" title="en/JS_CheckAccess">JSACC_WATCH</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_CheckAccess" title="en/JS_CheckAccess">JSACC_READ</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_CheckAccess" title="en/JS_CheckAccess">JSACC_WRITE</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CheckAccess" title="en/JS_CheckAccess">JS_CheckAccess</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps.checkAccess" title="en/JSObjectOps.checkAccess">JSObjectOps.checkAccess</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass.checkAccess" title="en/JSClass.checkAccess">JSClass.checkAccess</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetCheckObjectAccessCallback" title="en/JS_SetCheckObjectAccessCallback">JS_SetCheckObjectAccessCallback</a></li> -</ul> -<h3 id="Threading" name="Threading">Threading</h3> -<p>The following functions support the SpiderMonkey threading model. They are only available in <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_THREADSAFE" title="en/JS_THREADSAFE">JS_THREADSAFE</a></code> builds.</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_BeginRequest" title="en/JS_BeginRequest">JS_BeginRequest</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_BeginRequest" title="en/JS_BeginRequest">JS_EndRequest</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_YieldRequest" title="en/JS_YieldRequest">JS_YieldRequest</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SuspendRequest" title="en/JS_SuspendRequest">JS_SuspendRequest</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SuspendRequest" title="en/JS_SuspendRequest">JS_ResumeRequest</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetContextThread" title="en/JS_GetContextThread">JS_GetContextThread</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ClearContextThread" title="en/JS_ClearContextThread">JS_SetContextThread</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ClearContextThread" title="en/JS_ClearContextThread">JS_ClearContextThread</a></li> -</ul> -<p>The following functions exist in all builds, but in non-<code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_THREADSAFE" title="en/JS_THREADSAFE">JS_THREADSAFE</a></code> builds, they do nothing:</p> -<ul> - <li><a href="/en/JS_LockRuntime" title="en/JS_LockRuntime">JS_LockRuntime</a></li> - <li><a href="/en/JS_UnlockRuntime" title="en/JS_UnlockRuntime">JS_UnlockRuntime</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_Lock" title="en/JS_Lock">JS_Lock</a> {{ Deprecated_inline() }}</li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_Unlock" title="en/JS_Unlock">JS_Unlock</a> {{ Deprecated_inline() }}</li> -</ul> -<h3 id="Time" name="Time">Time</h3> -<ul> - <li><a href="/en/JS_Now" title="en/JS_Now">JS_Now</a></li> -</ul> -<h3 id="Callback_Types" name="Callback_Types">Callback Types</h3> -<p>Native function types:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSNative" title="en/JSNative">JSNative</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSFastNative" title="en/JSFastNative">JSFastNative</a></li> -</ul> -<p>Other callback types:</p> -<ul> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_AddExternalStringFinalizer" title="en/JS_AddExternalStringFinalizer">JSStringFinalizeOp</a> - used by <a href="/en/SpiderMonkey/JSAPI_Reference/JS_AddExternalStringFinalizer" title="en/JS_AddExternalStringFinalizer">JS_AddExternalStringFinalizer</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_TRACER_INIT" title="en/JS_TRACER_INIT">JSTraceCallback</a> - used by <a href="/en/SpiderMonkey/JSAPI_Reference/JS_TRACER_INIT" title="en/JS_TRACER_INIT">JS_TRACER_INIT</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SET_TRACING_DETAILS" title="en/JS_SET_TRACING_DETAILS">JSTraceNamePrinter</a> - used by <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SET_TRACING_DETAILS" title="en/JS_SET_TRACING_DETAILS">JS_SET_TRACING_DETAILS</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetContextCallback" title="en/JS_SetContextCallback">JSContextCallback</a> - used by <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetContextCallback" title="en/JS_SetContextCallback">JS_SetContextCallback</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCCallback" title="en/JS_SetGCCallback">JSGCCallback</a> - used by <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetGCCallback" title="en/JS_SetGCCallback">JS_SetGCCallback</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetExtraGCRoots" title="en/JS_SetExtraGCRoots">JSTraceDataOp</a> - used by <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetExtraGCRoots" title="en/JS_SetExtraGCRoots">JS_SetExtraGCRoots</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetBranchCallback" title="en/JS_SetBranchCallback">JSBranchCallback</a> - used by <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetBranchCallback" title="en/JS_SetBranchCallback">JS_SetBranchCallback</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetErrorReporter" title="en/JS_SetErrorReporter">JSErrorReporter</a> - used by <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetErrorReporter" title="en/JS_SetErrorReporter">JS_SetErrorReporter</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ReportErrorNumber" title="en/JS_ReportErrorNumber">JSErrorCallback</a> - used by <a href="/en/SpiderMonkey/JSAPI_Reference/JS_ReportErrorNumber" title="en/JS_ReportErrorNumber">JS_ReportErrorNumber</a> and friends</li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_AddArgumentFormatter" title="en/JS_AddArgumentFormatter">JSArgumentFormatter</a> - used by <a href="/en/SpiderMonkey/JSAPI_Reference/JS_AddArgumentFormatter" title="en/JS_AddArgumentFormatter">JS_AddArgumentFormatter</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetPrincipalsTranscoder" title="en/JS_SetPrincipalsTranscoder">JSPrincipalsTranscoder</a> - used by <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetPrincipalsTranscoder" title="en/JS_SetPrincipalsTranscoder">JS_SetPrincipalsTranscoder</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetObjectPrincipalsFinder" title="en/JS_SetObjectPrincipalsFinder">JSObjectPrincipalsFinder</a> - used by <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetObjectPrincipalsFinder" title="en/JS_SetObjectPrincipalsFinder">JS_SetObjectPrincipalsFinder</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_MapGCRoots" title="en/JS_MapGCRoots">JSGCRootMapFun</a> - used by <a href="/en/SpiderMonkey/JSAPI_Reference/JS_MapGCRoots" title="en/JS_MapGCRoots">JS_MapGCRoots</a></li> -</ul> -<p>See also <a href="#Classes">Classes</a>, above.</p> -<h3 id="Macros" name="Macros">Macros</h3> -<ul> - <li><a href="/en/JS_DEFAULT_XML_NAMESPACE_ID" title="en/JS_DEFAULT_XML_NAMESPACE_ID">JS_DEFAULT_XML_NAMESPACE_ID</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSFUN_BOUND_METHOD" title="en/JSFUN_BOUND_METHOD">JSFUN_BOUND_METHOD</a> {{ Deprecated_inline() }}</li> - <li><a href="/en/JSFUN_GETTER" title="en/JSFUN_GETTER">JSFUN_GETTER</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JSFUN_GLOBAL_PARENT" title="en/JSFUN_GLOBAL_PARENT">JSFUN_GLOBAL_PARENT</a> {{ Deprecated_inline() }}</li> - <li><a href="/en/JSFUN_HEAVYWEIGHT" title="en/JSFUN_HEAVYWEIGHT">JSFUN_HEAVYWEIGHT</a></li> - <li><a href="/en/JSFUN_LAMBDA" title="en/JSFUN_LAMBDA">JSFUN_LAMBDA</a></li> - <li><a href="/en/JSFUN_SETTER" title="en/JSFUN_SETTER">JSFUN_SETTER</a></li> - <li><a href="/en/JSREG_GLOB" title="en/JSREG_GLOB">JSREG_GLOB</a></li> - <li><a href="/en/JSREG_FOLD" title="en/JSREG_FOLD">JSREG_FOLD</a></li> - <li><a href="/en/JSREG_MULTILINE" title="en/JSREG_MULTILINE">JSREG_MULTILINE</a></li> -</ul> -<h3 id="Preprocessor_conditionals" name="Preprocessor_conditionals">Preprocessor conditionals</h3> -<ul> - <li><a href="/en/BUILD_OPT" title="en/BUILD_OPT">BUILD_OPT</a></li> - <li><a href="/en/GC_MARK_DEBUG" title="en/GC_MARK_DEBUG">GC_MARK_DEBUG</a></li> - <li><a href="/en/SpiderMonkey/JSAPI_Reference/JS_THREADSAFE" title="en/JS_THREADSAFE">JS_THREADSAFE</a></li> -</ul> -<p>These defines are useful for tuning SpiderMonkey performance:</p> -<ul> - <li><a href="/en/JS_ARENAMETER" title="en/JS_ARENAMETER">JS_ARENAMETER</a> - Arena package instrumentation.</li> - <li><a href="/en/JS_GCMETER" title="en/JS_GCMETER">JS_GCMETER</a> - GC instrumentation.</li> - <li><a href="/en/JS_HASHMETER" title="en/JS_HASHMETER">JS_HASHMETER</a> - Hash table package instrumentation.</li> -</ul> -<h3 id="C.2B.2B_features" name="C.2B.2B_features">C++ features</h3> -<ul> - <li>class <a href="/en/JSAutoRequest" title="en/JSAutoRequest">JSAutoRequest</a></li> - <li>class <a href="/en/JSAutoLocalRootScope" title="en/JSAutoLocalRootScope">JSAutoLocalRootScope</a></li> -</ul> -<p>{{ languages( { "ja": "ja/JSAPI_Reference", "pl": "pl/Dokumentacja_JSAPI" } ) }}</p> -<h1 id="JSAPI_参考">JSAPI 参考</h1> -<p> </p> -<h3 id=".E6.95.B0.E6.8D.AE.E7.BB.93.E6.9E.84" name=".E6.95.B0.E6.8D.AE.E7.BB.93.E6.9E.84">数据结构</h3> -<ul> - <li><a href="/cn/JSClass" title="cn/JSClass">JS类</a></li> - <li><a href="/cn/JSConstDoubleSpec" title="cn/JSConstDoubleSpec">JSConstDoubleSpec</a></li> - <li><a href="/cn/JSErrorReport" title="cn/JSErrorReport">JS错误报告</a></li> - <li><a href="/cn/JSFunctionSpec" title="cn/JSFunctionSpec">JS函数规范</a></li> - <li><a href="/cn/JSIdArray" title="cn/JSIdArray">JSIdArray</a></li> - <li><a href="/cn/JSObjectOps" title="cn/JSObjectOps">JS对象操作</a></li> - <li><a href="/cn/JSPrincipals" title="cn/JSPrincipals">JSPrincipals</a></li> - <li><a href="/cn/JSProperty" title="cn/JSProperty">JS属性</a></li> - <li><a href="/cn/JSPropertySpec" title="cn/JSPropertySpec">JS属性规范</a></li> -</ul> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_defineconstdoubles/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_defineconstdoubles/index.html deleted file mode 100644 index 82835b714d..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_defineconstdoubles/index.html +++ /dev/null @@ -1,59 +0,0 @@ ---- -title: JS DefineConstDoubles -slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_DefineConstDoubles -translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_DefineConstDoubles ---- -<h3 id=".E6.91.98.E8.A6.81" name=".E6.91.98.E8.A6.81">摘要</h3> -<p>为对象创建一个或多个包含双浮点值的属性。</p> -<h3 id=".E8.AF.AD.E6.B3.95" name=".E8.AF.AD.E6.B3.95">语法</h3> -<pre> JSBool JS_DefineConstDoubles(JSContext *cx, JSObject *obj, - JSConstDoubleSpec *cds); -</pre> -<table class="fullwidth-table"> - <tbody> - <tr> - <th>名称</th> - <th>类型</th> - <th>描述</th> - </tr> - <tr> - <td>cx</td> - <td>JSContext *</td> - <td>指向JS运行时信息内容的指针。</td> - </tr> - <tr> - <td>obj</td> - <td>JSObject *</td> - <td>指向新建的属性的对象指针。</td> - </tr> - <tr> - <td>cds</td> - <td>JSConstDoubleSpec *</td> - <td>指向创建的包含双浮点属性值和属性名的结构化数组的指针。最后一个数组元素必须包含一个为零值的成员。</td> - </tr> - </tbody> -</table> -<h3 id=".E6.8F.8F.E8.BF.B0" name=".E6.8F.8F.E8.BF.B0">描述</h3> -<p><code>JS_DefineConstDoubles</code>为特定的对象创建一个或多个成员变量,<code>obj</code>, 每个成员变量包含一个双浮点类型的值。每个成员变量在<code>JSConstDoubleSpec</code>结构中的<code>flags</code>字段被自动声名并由<code>cds</code>传递指针。 如果<code>flags</code>被设为<code>0</code>值, 成员变量的属性会自动被设为<code>JSPROP_PERMANENT 或 JSPROP_READONLY</code>。</p> -<p><code>cds</code> 是一个指向具有<code>JSConstDoubleSpec</code>结构的数组的第一个元素的指针。每个数组元素定义独立的变量名和变量值。数组的最后一个元素的<code>name</code>字段必须是0。<code>JS_DefineConstDoubles</code>为数组中的每一个名称字段不为零的元素建立一个成员变量。</p> -<p>通常情况下, <code>JS_DefineConstDoubles</code> 返回 <code>JS_TRUE</code>, 表明它在数组中已经建立了所有的属性列表。除此之外的情况下它返回<code>JS_FALSE</code>。</p> -<h2 id=".E6.9B.B4.E5.A4.9A.E5.8F.82.E8.80.83" name=".E6.9B.B4.E5.A4.9A.E5.8F.82.E8.80.83">更多参考</h2> -<table class="fullwidth-table"> - <tbody> - <tr> - <td>新闻组</td> - <td><a href="cn/JSAPI_%e5%8f%82%e8%80%83#Functions">Functions</a></td> - </tr> - <tr> - <td>文档</td> - <td><a class="external" href="http://lxr.mozilla.org/mozilla/ident?i=JS_DefineConstDoubles">LXRSearch</a></td> - </tr> - <tr> - <td>章节</td> - <td> - <p><a href="cn/JSConstDoubleSpec">JSConstDoubleSpec</a>, <a href="cn/JS_DefineElement">JS_DefineElement</a>, <a href="cn/JS_DefineFunction">JS_DefineFunction</a>, <a href="cn/JS_DefineFunctions">JS_DefineFunctions</a>, <a href="cn/JS_DefineObject">JS_DefineObject</a>, <a href="cn/JS_DefineProperties">JS_DefineProperties</a>, <a href="cn/JS_DefineProperty">JS_DefineProperty</a>, <a href="cn/JS_DefinePropertyWithTinyId">JS_DefinePropertyWithTinyId</a></p> - </td> - </tr> - </tbody> -</table> -<p> </p> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_doublecolon_call/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_doublecolon_call/index.html deleted file mode 100644 index a0c3d1239a..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_doublecolon_call/index.html +++ /dev/null @@ -1,92 +0,0 @@ ---- -title: 'JS::Call' -slug: 'Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS::Call' -translation_of: 'Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS::Call' ---- -<div>{{SpiderMonkeySidebar("JSAPI")}}</div> - -<div>{{ jsapi_minversion_header("17") }}</div> - - -<div class="summary"> -<p><font><font>调用指定的JS函数。</font></font></p> -</div> - -<h2 id="Syntax" name="Syntax"><font><font>句法</font></font></h2> - -<pre class="brush: cpp notranslate">bool -JS::Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleFunction fun, - const JS::HandleValueArray &args, JS::MutableHandleValue rval); - -bool -JS::Call(JSContext *cx, JS::HandleObject thisObj, const char *name, - const JS::HandleValueArray& args, JS::MutableHandleValue rval); - -bool -JS::Call(JSContext *cx, JS::HandleObject thisObj, JS::HandleValue fun, - const JS::HandleValueArray& args, JS::MutableHandleValue rval); - -bool -JS::Call(JSContext *cx, JS::HandleValue thisv, JS::HandleValue fun, - const JS::HandleValueArray& args, JS::MutableHandleValue rval); - -bool -JS::Call(JSContext *cx, JS::HandleValue thisv, JS::HandleObject funObj, - const JS::HandleValueArray& args, JS::MutableHandleValue rval); -</pre> - -<table class="fullwidth-table"> - <tbody> - <tr> - <th><font><font>名称</font></font></th> - <th><font><font>类型</font></font></th> - <th><font><font>描述</font></font></th> - </tr> - <tr> - <td><code>cx</code></td> - <td>{{jsapixref("JSRuntime", "JSContext *")}}</td> - <td><font><font>指向JS上下文的指针,从中可以派生运行时信息。</font><font>{{Jsapi-requires-request()}}</font></font></td> - </tr> - <tr> - <td><code>thisObj</code></td> - <td>{{jsapixref("JSObject", "JS::HandleObject")}} / {{jsapixref("JS::Value", "JS::HandleValue")}}</td> - <td>The "current" object on which the function operates; the object specified here is "this" when the function executes.</td> - </tr> - <tr> - <td><code>fun</code> / <code>funObj</code></td> - <td>{{jsapixref("JSFunction", "JS::HandleFunction")}} / {{jsapixref("JS::Value", "JS::HandleValue")}} / {{jsapixref("JSObject", "JS::HandleObject")}}</td> - <td>Pointer to the function to call. <strong>Should be a native function or JSAPI-compiled function.</strong></td> - </tr> - <tr> - <td><code>name</code></td> - <td><code>const char *</code></td> - <td>Pointer to the function name to call.</td> - </tr> - <tr> - <td><code>args</code></td> - <td>{{jsapixref("JS::HandleValueArray", "JS::HandleValueArray &")}}</td> - <td>Arguments to pass to the function.</td> - </tr> - <tr> - <td><code>rval</code></td> - <td>{{jsapixref("JS::Value", "JS::MutableHandleValue")}}</td> - <td>Out parameter. On success, <code>*rval</code> receives the return value from the function call.</td> - </tr> - </tbody> -</table> - -<h2 id="Description" name="Description">Description</h2> - -<p><code>JS::Call</code><code>fun</code><font><font>在对象上</font><font>调用指定的函数</font></font><code>thisObj</code><font><font>。</font><font>在函数执行方面,该对象被视为</font></font><code>this</code><font><font>。</font></font></p> - -<p><font><font>有关更多详细信息,请参阅{{jsapixref("JS_CallFunction")}},{{jsapixref("JS_CallFunctionName")}}和{{jsapixref("JS_CallFunctionValue")}}。</font></font></p> - -<h2 id="See_Also" name="See_Also"><font><font>也可以看看</font></font></h2> - -<ul> - <li>{{ LXRSearch("ident", "i", "JS::Call") }}</li> - <li>{{jsapixref("JS_CallFunction")}}</li> - <li>{{jsapixref("JS_CallFunctionName")}}</li> - <li>{{jsapixref("JS_CallFunctionValue")}}</li> - <li>{{bug(601168)}}</li> -</ul> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_doublecolon_ordinarytoprimitive/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_doublecolon_ordinarytoprimitive/index.html deleted file mode 100644 index b09164ee56..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_doublecolon_ordinarytoprimitive/index.html +++ /dev/null @@ -1,66 +0,0 @@ ---- -title: 'JS::OrdinaryToPrimitive' -slug: 'Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS::OrdinaryToPrimitive' -translation_of: 'Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS::OrdinaryToPrimitive' ---- -<div>{{SpiderMonkeySidebar("JSAPI")}}</div> - -<p>{{ jsapi_minversion_header("38") }}</p> - -<div class="summary"> -<p>将普通对象转换为原始值</p> -</div> - -<h2 id="语法说明">语法说明</h2> - -<pre class="brush: cpp">bool -JS::OrdinaryToPrimitive(JSContext *cx, JS::HandleObject obj, JSType type, - JS::MutableHandleValue vp);</pre> - -<table class="fullwidth-table"> - <tbody> - <tr> - <th>名称</th> - <th>类型</th> - <th>描述</th> - </tr> - <tr> - <td><code>cx</code></td> - <td>{{jsapixref("JSRuntime", "JSContext *")}}</td> - <td>执行转换的上下文. {{ Jsapi-requires-request() }}</td> - </tr> - <tr> - <td><code>obj</code></td> - <td>{{jsapixref("JSObject", "JS::HandleObject")}}</td> - <td>要转换的对象。</td> - </tr> - <tr> - <td><code>type</code></td> - <td>{{jsapixref("JSType")}}</td> - <td>转换后值的类型。</td> - </tr> - <tr> - <td><code>vp</code></td> - <td>{{jsapixref("JS::Value", "JS::MutableHandleValue")}}</td> - <td>输出参数. 成功, <code>*vp 收到转换后的值</code></td> - </tr> - </tbody> -</table> - -<h2 id="描述">描述</h2> - -<p><code>JS::OrdinaryToPrimitive</code> 通过ES6 draft rev 28(2014年10月14日)7.1.1第二算法中指定的算法将JavaScript对象转换为指定的类型值。</p> - -<p>Most users should not call this -- use {{jsapixref("JS::ToNumber")}}, {{jsapixref("JS::ToBoolean")}}, or {{jsapixref("JS::ToString")}} instead. This should only be called from custom convert hooks. It implements the default conversion behavior shared by most objects in JS, so it's useful as a fallback.</p> - -<p>On success, <code>JS::OrdinaryToPrimitive</code> stores the converted value in <code>*vp</code> and returns <code>true</code>. On error or exception, it returns <code>false</code>, and the value left in <code>*vp</code> is undefined.</p> - -<h2 id="See_Also" name="See_Also">了解其他</h2> - -<ul> - <li>{{ LXRSearch("ident", "i", "JS::OrdinaryToPrimitive") }}</li> - <li>{{jsapixref("JS::ToNumber")}}</li> - <li>{{jsapixref("JS::ToBoolean")}}</li> - <li>{{jsapixref("JS::ToString")}}</li> - <li>{{bug(1103152)}}</li> -</ul> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_evaluatescript/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_evaluatescript/index.html deleted file mode 100644 index 94454ee794..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_evaluatescript/index.html +++ /dev/null @@ -1,69 +0,0 @@ ---- -title: SpiderMonkey/JSAPI_参考/JS_EvaluateScript -slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_EvaluateScript -translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_EvaluateScript ---- -<p>编译并执行一个脚本。</p> -<h2 id="Syntax" name="Syntax">语法</h2> -<pre class="eval"><a href="/En/SpiderMonkey/JSAPI_Reference/JSBool" title="en/JSBool">JSBool</a> <strong>JS_EvaluateScript</strong>(<a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, <a href="/en/SpiderMonkey/JSAPI_Reference/JSObject" title="en/JSObject">JSObject</a> *obj, - const char *src, <a href="/en/SpiderMonkey/JSAPI_Reference/jsint" title="en/jsint">uintN</a> length, const char *filename, - <a href="/en/SpiderMonkey/JSAPI_Reference/jsint" title="en/jsint">uintN</a> lineno, <a href="/En/SpiderMonkey/JSAPI_Reference/Jsval" title="en/jsval">jsval</a> *rval); - -<a href="/En/SpiderMonkey/JSAPI_Reference/JSBool" title="en/JSBool">JSBool</a> <strong>JS_EvaluateUCScript</strong>(<a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, <a href="/en/SpiderMonkey/JSAPI_Reference/JSObject" title="en/JSObject">JSObject</a> *obj, - const <a href="/en/SpiderMonkey/JSAPI_Reference/jschar" title="en/jschar">jschar</a> *src, <a href="/en/SpiderMonkey/JSAPI_Reference/jsint" title="en/jsint">uintN</a> length, const char *filename, - <a href="/en/SpiderMonkey/JSAPI_Reference/jsint" title="en/jsint">uintN</a> lineno, <a href="/En/SpiderMonkey/JSAPI_Reference/Jsval" title="en/jsval">jsval</a> *rval); -</pre> -<table class="fullwidth-table"> - <tbody> - <tr> - <th>名称</th> - <th>数据类型</th> - <th>描述</th> - </tr> - <tr> - <td><code>cx</code></td> - <td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *</code></td> - <td>脚本运行的上下文. {{ Jsapi-requires-request() }}</td> - </tr> - <tr> - <td><code>obj</code></td> - <td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JSObject" title="en/JSObject">JSObject</a> *</code></td> - <td>The scope in which to execute the script. This parameter is documented in detail at <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ExecuteScript" title="en/JS_ExecuteScript">JS_ExecuteScript</a></code>.</td> - </tr> - <tr> - <td><code>src</code></td> - <td><code>const char *</code> <em>or</em> <code>const <a href="/en/SpiderMonkey/JSAPI_Reference/jschar" title="en/jschar">jschar</a> *</code></td> - <td>包含要编译和执行的脚本的字符串.</td> - </tr> - <tr> - <td><code>length</code></td> - <td><code><a href="/en/SpiderMonkey/JSAPI_Reference/jsint" title="en/jsint">uintN</a></code></td> - <td><code>src的长度</code>, in characters.</td> - </tr> - <tr> - <td><code>filename</code></td> - <td><code>const char *</code></td> - <td>Name of file or URL containing the script. Used to report filename or URL in error messages.</td> - </tr> - <tr> - <td><code>lineno</code></td> - <td><code><a href="/en/SpiderMonkey/JSAPI_Reference/jsint" title="en/jsint">uintN</a></code></td> - <td>Line number. Used to report the offending line in the file or URL if an error occurs.</td> - </tr> - <tr> - <td><code>rval</code></td> - <td><code><a href="/En/SpiderMonkey/JSAPI_Reference/Jsval" title="en/jsval">jsval</a> *</code></td> - <td>Out parameter. On success, <code>*rval</code> receives the value of the last-executed expression statement processed in the script.</td> - </tr> - </tbody> -</table> -<h2 id="Description" name="Description">描述</h2> -<p><code>JS_EvaluateScript</code> compiles and executes a script in the specified scope, <code>obj</code>. On successful completion, <code>rval</code> is a pointer to a variable that holds the value from the last executed expression statement processed in the script. <code>JS_EvaluateUCScript</code> is the Unicode version of the function.</p> -<p><code>src</code> is the string containing the text of the script. <code>length</code> indicates the size of the text version of the script in characters.</p> -<p><code>filename</code> is the name of the file (or URL) containing the script. This information is used in messages if an error occurs during compilation. Similarly, <code>lineno</code> is used to report the line number of the script or file where an error occurred during compilation.</p> -<p>If a script compiles and executes successfully, <code>*rval</code> receives the value from the last-executed expression statement in the script, and <code>JS_EvaluateScript</code> or <code>JS_EvaluateUCScript</code> returns <code>JS_TRUE</code>. Otherwise it returns <code>JS_FALSE</code> and the value left in <code>*rval</code> is undefined.</p> -<h2 id="See_Also" name="See_Also">See Also</h2> -<p>{{ LXRSearch("ident", "i", "JS_EvaluateScript") }}<br> - {{ LXRSearch("ident", "i", "JS_EvaluateUCScript") }}</p> -<p><a href="/en/SpiderMonkey/JSAPI_Reference/JS_CompileFile" title="en/JS_CompileFile">JS_CompileFile</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_CompileScript" title="en/JS_CompileScript">JS_CompileScript</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_DecompileScript" title="en/JS_DecompileScript">JS_DecompileScript</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_DestroyScript" title="en/JS_DestroyScript">JS_DestroyScript</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_EvaluateScriptForPrincipals" title="en/JS_EvaluateScriptForPrincipals">JS_EvaluateScriptForPrincipals</a></p> -<p>{{ languages( { "ja": "ja/JS_EvaluateScript" } ) }}</p> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_getversion/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_getversion/index.html deleted file mode 100644 index a2b2888958..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_getversion/index.html +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: SpiderMonkey/JSAPI_参考/JS_GetVersion -slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_GetVersion -translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_GetVersion ---- -<p>Retrieves the JavaScript version number used within a specified executable script context.</p> -<h2 id="Syntax" name="Syntax">语法</h2> -<pre class="eval"><a href="/en/SpiderMonkey/JSAPI_Reference/JSVersion" title="en/JSVersion">JSVersion</a> <strong>JS_GetVersion</strong>(<a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *cx); -</pre> -<table class="fullwidth-table"> - <tbody> - <tr> - <th>参数名称</th> - <th>类型</th> - <th>描述</th> - </tr> - <tr> - <td><code>cx</code></td> - <td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *</code></td> - <td>要查询的上下文.</td> - </tr> - </tbody> -</table> -<h2 id="Description" name="Description">描述</h2> -<p><code>JS_GetVersion</code> returns the JavaScript version currently used by the given <code>JSContext</code>, <code>cx</code>. The result is one of the <code><a href="/en/SpiderMonkey/JSAPI_Reference/JSVersion" title="en/JSVersion">JSVersion</a></code> constants.</p> -<p>When a context is created, its version is initially <code>JSVERSION_DEFAULT</code>. Scripts are compiled using the latest version of the JavaScript language. To configure a context to run scripts using a specific version of JavaScript, use <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetVersion" title="en/JS_SetVersion">JS_SetVersion</a></code>.</p> -<h2 id="See_Also" name="See_Also">请参阅</h2> -<p>{{ LXRSearch("ident", "i", "JS_GetVersion") }}</p> -<p><a href="/en/SpiderMonkey/JSAPI_Reference/JS_VersionToString" title="en/JS_VersionToString">JS_VersionToString</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_StringToVersion" title="en/JS_StringToVersion">JS_StringToVersion</a></p> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_hasownproperty/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_hasownproperty/index.html deleted file mode 100644 index ed6e760796..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_hasownproperty/index.html +++ /dev/null @@ -1,73 +0,0 @@ ---- -title: JS_HasOwnProperty -slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_HasOwnProperty -tags: - - 中文 -translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_HasOwnProperty ---- -<div>{{SpiderMonkeySidebar("JSAPI")}}</div> - -<p>{{ jsapi_minversion_header("45") }}</p> - -<div class="summary"> -<p>Determine whether a JavaScript object has a specified own property.</p> -</div> - -<h2 id="Syntax" name="Syntax">Syntax</h2> - -<pre class="brush: cpp notranslate">bool -JS_HasOwnProperty(JSContext* cx, HandleObject obj, const char* name, - bool* foundp) - -bool -JS_HasOwnPropertyById(JSContext* cx, HandleObject obj, HandleId id, - bool* foundp) -</pre> - -<table class="fullwidth-table"> - <tbody> - <tr> - <th>Name</th> - <th>Type</th> - <th>Description</th> - </tr> - <tr> - <td><code>cx</code></td> - <td>{{jsapixref("JSRuntime", "JSContext *")}}</td> - <td>A context. {{ Jsapi-requires-request() }}</td> - </tr> - <tr> - <td><code>obj</code></td> - <td>{{jsapixref("JSObject", "JS::HandleObject")}}</td> - <td>Object to search on for the property.</td> - </tr> - <tr> - <td><code>name</code> <em>or<em> <code>id</code></em></em></td> - <td><code>const char *</code> <em>or</em> {{jsapixref("jsid", "JS::HandleId")}}</td> - <td>Name of the property to look up.</td> - </tr> - <tr> - <td><code>foundp</code></td> - <td><code>bool *</code></td> - <td>Non-null pointer to a variable of type <code>bool</code>. On success, <code>JS_HasOwnProperty</code> stores <code>true</code> in this variable if <code>obj</code> has an own property with the given <code>name</code>, and <code>false</code> if not.</td> - </tr> - </tbody> -</table> - -<h2 id="Description" name="Description">Description</h2> - -<p><strong><code>JS_HasOwnProperty</code></strong> searches an object, <code>obj</code>, for an own property with the specified <code>name</code>. It behaves like the JavaScript expression <code>Object.hasOwnProperty(obj, name)</code>. <strong><code>JS_HasOwnPropertyById</code></strong> is the same but takes a {{jsapixref("jsid", "JS::HandleId")}} for the property name.</p> - -<p>If the property exists, this function sets <code>*foundp</code> to <code>true</code> and returns <code>true</code>.</p> - -<p>If the object <code>obj</code> has no such property, the function sets <code>*foundp</code> to <code>false</code> and returns <code>true</code> (to indicate that no error occurred).</p> - -<p>If an error occurs during the search, the function returns <code>false</code>, and the value of <code>*foundp</code> is undefined.</p> - -<h2 id="See_Also" name="See_Also">See Also</h2> - -<ul> - <li>{{ LXRSearch("ident", "i", "JS_HasOwnProperty") }}</li> - <li>{{ LXRSearch("ident", "i", "JS_HasOwnPropertyById") }}</li> - <li>{{bug(1163423)}}</li> -</ul> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_newruntime/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_newruntime/index.html deleted file mode 100644 index 885bb3dd6e..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_newruntime/index.html +++ /dev/null @@ -1,33 +0,0 @@ ---- -title: JS_NewRuntime -slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_NewRuntime -tags: - - JSAPI_Reference - - SpiderMonkey -translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_NewRuntime ---- -<p>Initializes the JavaScript runtime.</p> -<h2 id="Syntax" name="Syntax">Syntax</h2> -<pre class="eval"><a href="/zh-CN/SpiderMonkey/JSAPI_Reference/JSRuntime" title="zh-CN/JSRuntime">JSRuntime</a> * <strong>JS_NewRuntime</strong>(uint32 maxbytes); -</pre> -<table class="fullwidth-table"> - <tbody> - <tr> - <th>Name</th> - <th>Type</th> - <th>Description</th> - </tr> - <tr> - <td><code>maxbytes</code></td> - <td><code>uint32</code></td> - <td>Maximum number of allocated bytes after which garbage collection is run.</td> - </tr> - </tbody> -</table> -<h2 id="Description" name="Description">Description</h2> -<p><code>JS_NewRuntime</code> initializes the JavaScript runtime environment. Call <code>JS_NewRuntime</code> before making any other API calls. <code>JS_NewRuntime</code> allocates memory for the <code>JSRuntime</code> and initializes certain internal runtime structures. <code>maxbytes</code> specifies the number of allocated bytes after which garbage collection is run.</p> -<p>Generally speaking, most applications need only one <code><a href="/zh-CN/SpiderMonkey/JSAPI_Reference/JSRuntime" title="zh-CN/JSRuntime">JSRuntime</a></code>. In a <code><a href="/zh-CN/SpiderMonkey/JSAPI_Reference/JS_THREADSAFE" title="zh-CN/JS_THREADSAFE">JS_THREADSAFE</a></code> build, each runtime is capable of handling multiple execution threads, using one <code><a href="/zh-CN/SpiderMonkey/JSAPI_Reference/JSRuntime" title="zh-CN/JSRuntime">JSContext</a></code> per thread, sharing the same <code>JSRuntime</code>. You only need multiple runtimes if your application requires completely separate JS engines that cannot share values, objects, and functions.</p> -<p>On success, <code>JS_NewRuntime</code> returns a pointer to the newly created runtime, which the caller must later destroy using <code><a href="/zh-CN/SpiderMonkey/JSAPI_Reference/JS_DestroyRuntime" title="zh-CN/JS_DestroyRuntime">JS_DestroyRuntime</a></code>. Otherwise it returns <code>NULL</code>.</p> -<h3 id="Notes" name="Notes">Notes</h3> -<p>Ordinarily, <code>JS_NewRuntime</code> should be the first JSAPI call in an application, and <code><a href="/zh-CN/SpiderMonkey/JSAPI_Reference/JS_DestroyRuntime" title="zh-CN/JS_DestroyRuntime">JS_DestroyRuntime</a></code> and <code><a href="/zh-CN/SpiderMonkey/JSAPI_Reference/JS_ShutDown" title="zh-CN/JS_ShutDown">JS_ShutDown</a></code> should be the last ones.</p> -<p>{{ LXRSearch("ident", "i", "JS_NewRuntime") }}</p> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_seterrorreporter/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_seterrorreporter/index.html deleted file mode 100644 index e04127a541..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_seterrorreporter/index.html +++ /dev/null @@ -1,61 +0,0 @@ ---- -title: SpiderMonkey/JSAPI_参考/JS_SetErrorReporter -slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_SetErrorReporter -translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_SetErrorReporter ---- -<p>指定一个程序的错误报告途径.</p> -<h2 id="Syntax" name="Syntax">语法</h2> -<pre class="eval"><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetErrorReporter" title="en/JS_SetErrorReporter">JSErrorReporter</a> <strong>JS_SetErrorReporter</strong>(<a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetErrorReporter" title="en/JS_SetErrorReporter">JSErrorReporter</a> er); -</pre> -<table class="fullwidth-table"> - <tbody> - <tr> - <th>形式参数</th> - <th>类型</th> - <th>描述</th> - </tr> - <tr> - <td><code>cx</code></td> - <td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *</code></td> - <td>Pointer to a JS context from which to derive runtime information.</td> - </tr> - <tr> - <td><code>er</code></td> - <td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetErrorReporter" title="en/JS_SetErrorReporter">JSErrorReporter</a></code></td> - <td>在你的程序中用于报告错误的自定义函数, 见下面的描述.</td> - </tr> - </tbody> -</table> -<h3 id="Callback_Syntax" name="Callback_Syntax"> 回调函数语法</h3> -<pre class="eval">typedef void (*<strong>JSErrorReporter</strong>)( - <a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, const char *message, <a href="/en/SpiderMonkey/JSAPI_Reference/JSErrorReport" title="en/JSErrorReport">JSErrorReport</a> *report); -</pre> -<table class="fullwidth-table"> - <tbody> - <tr> - <th>形式参数</th> - <th>类型</th> - <th>描述</th> - </tr> - <tr> - <td><code>cx</code></td> - <td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *</code></td> - <td>错误发生的上下文。</td> - </tr> - <tr> - <td><code>message</code></td> - <td><code>const char *</code></td> - <td>一个错误信息。</td> - </tr> - <tr> - <td><code>report</code></td> - <td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JSErrorReport" title="en/JSErrorReport">JSErrorReport</a> *</code></td> - <td>一个包含错误额外的详细资料报告记录。</td> - </tr> - </tbody> -</table> -<h2 id="Description" name="Description">描述</h2> -<p><code>JS_SetErrorReporter</code> enables you to define and use your own error reporting mechanism in your applications. The reporter you define is automatically passed a <code><a href="/en/SpiderMonkey/JSAPI_Reference/JSErrorReport" title="en/JSErrorReport">JSErrorReport</a></code> structure when an error occurs and has been parsed by <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ReportError" title="en/JS_ReportError">JS_ReportError</a></code>.</p> -<p>Typically, the error reporting mechanism you define should log the error where appropriate (such as to a log file), and display an error to the user of your application. The error you log and display can make use of the information passed about the error condition in the <code>JSErrorReport</code> structure.</p> -<p>Like all other SpiderMonkey callbacks, the error reporter callback must not throw a C++ exception.</p> -<p>{{ LXRSearch("ident", "i", "JS_SetErrorReporter") }}</p> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_valuetostring/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_valuetostring/index.html deleted file mode 100644 index ab0e6654a4..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_valuetostring/index.html +++ /dev/null @@ -1,45 +0,0 @@ ---- -title: SpiderMonkey/JSAPI_参考/JS_ValueToString -slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_ValueToString -translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_ValueToString ---- -<p>把一个<code>jsval值</code> 转换成一个 <code>JSString</code>.</p> - -<p> </p> - -<h2 id="Syntax" name="Syntax">语法</h2> - -<pre class="eval"><a href="/en/SpiderMonkey/JSAPI_Reference/JSString" title="en/JSString">JSString</a> * <strong>JS_ValueToString</strong>(<a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *cx, <a href="/En/SpiderMonkey/JSAPI_Reference/Jsval" title="en/jsval">jsval</a> v); -</pre> - -<table class="fullwidth-table"> - <tbody> - <tr> - <th>Name</th> - <th>Type</th> - <th>Description</th> - </tr> - <tr> - <td><code>cx</code></td> - <td><code><a href="/en/SpiderMonkey/JSAPI_Reference/JSRuntime" title="en/JSRuntime">JSContext</a> *</code></td> - <td>The context in which to perform the conversion. {{ Jsapi-requires-request() }}</td> - </tr> - <tr> - <td><code>v</code></td> - <td><code><a href="/En/SpiderMonkey/JSAPI_Reference/Jsval" title="en/jsval">jsval</a></code></td> - <td>转换的jsval值.</td> - </tr> - </tbody> -</table> - -<h2 id="Description" name="Description">描述</h2> - -<p><code>JS_ValueToString</code> converts a specified JS value, <code>v</code>, to a JS string. It implements the ToString operator specified in <span class="pl-s1"><span class="pl-s">ECMA 262-3 §</span></span>9. If <code>v</code> is an object, the actual conversion is performed by its <code><a href="/en/SpiderMonkey/JSAPI_Reference/JSObjectOps.defaultValue" title="en/JSObjectOps.defaultValue">JSClass.convert</a></code> callback, which may call the JavaScript methods <code>v.toString()</code> and/or <code>v.valueOf()</code>. On success, <code>JS_ValueToString</code> returns a pointer to a string. On error or exception, it returns <code>NULL</code>. This happens, for example, if <code>v</code> is an object and <code>v.toString()</code> throws an exception.</p> - -<p>The resulting <code>JSString</code> is subject to garbage collection unless you protect it using a local root, an object property, or the <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_AddRoot" title="en/JS_AddRoot">JS_AddRoot</a></code> function.</p> - -<h2 id="See_Also" name="See_Also">See Also</h2> - -<p>{{ LXRSearch("ident", "i", "JS_ValueToString") }}</p> - -<p><a href="/en/SpiderMonkey/JSAPI_Reference/JS_ConvertArguments" title="en/JS_ConvertArguments">JS_ConvertArguments</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_ConvertValue" title="en/JS_ConvertValue">JS_ConvertValue</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetTypeName" title="en/JS_GetTypeName">JS_GetTypeName</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_TypeOfValue" title="en/JS_TypeOfValue">JS_TypeOfValue</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_ValueToBoolean" title="en/JS_ValueToBoolean">JS_ValueToBoolean</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_ValueToFunction" title="en/JS_ValueToFunction">JS_ValueToFunction</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_ValueToInt32" title="en/JS_ValueToInt32">JS_ValueToInt32</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_ValueToNumber" title="en/JS_ValueToNumber">JS_ValueToNumber</a>, <a href="/en/SpiderMonkey/JSAPI_Reference/JS_ValueToObject" title="en/JS_ValueToObject">JS_ValueToObject</a></p> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jsclass/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jsclass/index.html deleted file mode 100644 index dd119aba3f..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jsclass/index.html +++ /dev/null @@ -1,137 +0,0 @@ ---- -title: JSClass -slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSClass -translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSClass ---- -<h3 id=".E6.91.98.E8.A6.81" name=".E6.91.98.E8.A6.81">摘要</h3> -<p><b>数据结构</b> 定义一个基本类用于建立和维护JS对象。</p> -<h3 id=".E8.AF.AD.E6.B3.95" name=".E8.AF.AD.E6.B3.95">语法</h3> -<pre>struct JSClass { - char *name; - uint32 flags; - /* Mandatory non-null function pointer members. */ - JSPropertyOp addProperty; - JSPropertyOp delProperty; - JSPropertyOp getProperty; - JSPropertyOp setProperty; - JSEnumerateOp enumerate; - JSResolveOp resolve; - JSConvertOp convert; - JSFinalizeOp finalize; - /* Optionally non-null members start here. */ - JSGetObjectOps getObjectOps; - JSCheckAccessOp checkAccess; - JSNative call; - JSNative construct; - JSXDRObjectOp xdrObject; - JSHasInstanceOp hasInstance; - JSMarkOp mark; - JSReserveSlotsOp reserveSlots; -}; -</pre> -<table class="fullwidth-table"> - <tbody> - <tr> - <th>名称</th> - <th>类型</th> - <th>描述</th> - </tr> - <tr> - <td><code>name</code></td> - <td><code>char *</code></td> - <td>类名</td> - </tr> - <tr> - <td><code>flags</code></td> - <td><code>uint32</code></td> - <td>类的属性(成员变量)。0表明属性不是一个集合. 属性值可以是下面这些值中的一个或多个: - <ul> - <li><code><a href="cn/JSAPI_Reference/JSCLASS_HAS_PRIVATE">JSCLASS_HAS_PRIVATE</a></code>: 类可以使用私有数据。</li> - <li><code><a href="cn/JSAPI_Reference/JSCLASS_NEW_ENUMERATE">JSCLASS_NEW_ENUMERATE</a></code>: 返回由类定义的<code>getObjectOps</code>方法获取所有属性的一个新方法。</li> - <li><code><a href="cn/JSAPI_Reference/JSCLASS_NEW_RESOLVE">JSCLASS_NEW_RESOLVE</a></code>: 返回由类定义的<code>getObjectOps</code>方法获取属性值的一个新方法。</li> - </ul> - </td> - </tr> - <tr> - <td><code>addProperty</code></td> - <td><code>JSPropertyOp</code></td> - <td>为类增加属性的函数。</td> - </tr> - <tr> - <td><code>delProperty</code></td> - <td><code>JSPropertyOp</code></td> - <td>从类中删除属性的函数。</td> - </tr> - <tr> - <td><code>getProperty</code></td> - <td><code>JSPropertyOp</code></td> - <td>获取属性值的函数。</td> - </tr> - <tr> - <td><code>setProperty</code></td> - <td><code>JSPropertyOp</code></td> - <td>设置属性值的函数</td> - </tr> - <tr> - <td><code>enumerate</code></td> - <td><code>JSEnumerateOp</code></td> - <td>枚举类所有属性的函数。</td> - </tr> - <tr> - <td><code>resolve</code></td> - <td><code>JSResolveOp</code></td> - <td>Method for resolving property ambiguities.</td> - </tr> - <tr> - <td><code>convert</code></td> - <td><code>JSConvertOp</code></td> - <td>进行属性值转换的函数。</td> - </tr> - <tr> - <td><code>finalize</code></td> - <td><code>JSFinalizeOp</code></td> - <td>将类设为不可修改(finalizing)的函数。</td> - </tr> - <tr> - <td><code>getObjectOps</code></td> - <td><code>JSGetObjectOps</code></td> - <td>为类定义重载方法指向一个可选的结构。如果你不想重载类的默认方法,可以将<code>getObjectOps</code> 设为 <code>NULL</code>。</td> - </tr> - <tr> - <td><code>checkAccess</code></td> - <td><code>JSCheckAccessOp</code></td> - <td>为类或对象操作结构指定可选的自定义请求控制方法。如果你不想提供自定义的请求控制,设置此值为<code>NULL</code>。</td> - </tr> - <tr> - <td><code>call</code></td> - <td><code>JSNative</code></td> - <td>为对象提供替换这个类的方法。</td> - </tr> - <tr> - <td><code>construct</code></td> - <td><code>JSNative</code></td> - <td>为对象提供方法去替换这个类的构造器。</td> - </tr> - <tr> - <td><code>xdrObject</code></td> - <td><code>JSXDRObjectOp</code></td> - <td>指向一个可选的XDR对象和它的方法。如果你不想使用XDR, 设置这个值为 <code>NULL</code>。</td> - </tr> - <tr> - <td><code>hasInstance</code></td> - <td><code>JSHasInstanceOp</code></td> - <td>Pointer to an optional <code>hasInstance</code> method for this object. If you do not provide a method for <code>hasInstance</code>, set this pointer to <code>NULL</code>.</td> - </tr> - <tr> - <td><code>mark</code></td> - <td><code>JSMarkOp</code></td> - <td>Pointer to an optional <code>mark</code> method for this object. If you do not provide a method for <code>mark</code>, set this pointer to <code>NULL</code>.</td> - </tr> - <tr> - <td><code>reserveSlots</code></td> - <td><code>JSReserveSlotsOp</code></td> - <td>Pointer to an optional <code>reserveSlots</code> method for this object. If you do not provide a method for <code>reserveSlots</code>, set this pointer to <code>NULL</code>.</td> - </tr> - </tbody> -</table> -<p> </p> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jsconstdoublespec/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jsconstdoublespec/index.html deleted file mode 100644 index 509d3b12ed..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jsconstdoublespec/index.html +++ /dev/null @@ -1,56 +0,0 @@ ---- -title: JSConstDoubleSpec -slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSConstDoubleSpec -translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSConstDoubleSpec ---- -<h3 id=".E6.91.98.E8.A6.81" name=".E6.91.98.E8.A6.81">摘要</h3> -<p><b>数据结构</b></p> -<p>定义一个双浮点类型的变量并进行赋值。</p> -<h3 id=".E8.AF.AD.E6.B3.95" name=".E8.AF.AD.E6.B3.95">语法</h3> -<pre>struct JSConstDoubleSpec { - jsdouble dval; - const char *name; - uint8 flags; - uint8 spare[3]; -}; -</pre> -<table class="fullwidth-table"> - <tbody> - <tr> - <th>名称</th> - <th>类型</th> - <th>描述</th> - </tr> - <tr> - <td><code>dval</code></td> - <td><code>jsdouble</code></td> - <td>双浮点类型的值。</td> - </tr> - <tr> - <td><code>name</code></td> - <td><code>const char *</code></td> - <td>给双浮点类型定义的名称。</td> - </tr> - <tr> - <td><code>flags</code></td> - <td><code>uint8</code></td> - <td>双浮点类型的属性。这里可以是0或者是下面这些值之中的一个: - <ul> - <li><code><a href="cn/JSPROP_ENUMERATE">JSPROP_ENUMERATE</a></code>: 在for循环中的可用性。</li> - <li><code><a href="cn/JSPROP_READONLY">JSPROP_READONLY</a></code>: 只读性。</li> - <li><code><a href="cn/JSPROP_PERMANENT">JSPROP_PERMANENT</a></code>: 非删除性。</li> - <li><code><a href="cn/JSPROP_EXPORTED">JSPROP_EXPORTED</a></code>: 可导出性。(property can be exported outside its object.)</li> - <li><code><a href="cn/JSPROP_INDEX">JSPROP_INDEX</a></code>: 数组(array)元素的当前索引。</li> - </ul> - </td> - </tr> - <tr> - <td><code>spare</code></td> - <td><code>uint8{{ mediawiki.external(3) }}</code></td> - <td>为以后的扩展保留的属性。</td> - </tr> - </tbody> -</table> -<h3 id=".E6.8F.8F.E8.BF.B0" name=".E6.8F.8F.E8.BF.B0">描述</h3> -<p><code>JS双浮点型的构造规范</code> 典型应用于定义一个双浮点值集合,并使用<code><a href="cn/JS_DefineConstDoubles">JS_DefineConstDoubles</a></code>对生成的对象进行赋值。使用<code>JS_DefineConstDouble</code>为指定的对象创建一个或多个双浮点类型属性。</p> -<p><code>JS_DefineConstDoubles</code>为一类由<code>JSConstDoubleSpecs</code>定义的数组提供证明。为每个数据元素定义独立的属性名和设置独立的属性值。数组的最后一个元素必须包括0值(zero-valued)的属性。<code>JS_DefineConstDoubles</code> 为数组中每个非0值(non-zero)元素创建一个属性值。</p> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jserrorreport/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jserrorreport/index.html deleted file mode 100644 index 7246c3c416..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jserrorreport/index.html +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: JSErrorReport -slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSErrorReport -translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSErrorReport ---- -<p><a>Media:Example.ogg</a></p> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jsproperty/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jsproperty/index.html deleted file mode 100644 index 16f0cca090..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jsproperty/index.html +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: JSProperty -slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSProperty -translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSProperty ---- -<div>{{SpiderMonkeySidebar("JSAPI")}}</div> - -<p>{{deprecated_header("jsapi16")}}</p> - -<div class="summary"> -<p>限内部使用。{{jsapixref("JSObjectOps")}}层使用的JavaScript对象属性的类型。</p> -</div> - -<h3 id="Syntax" name="Syntax">语法</h3> - -<pre class="eval">struct JSProperty { - jsid id; -}; -</pre> - -<h3 id="Description" name="Description">Description</h3> - -<p><code>JSProperty</code> 是所有对象属性的抽象基类。 它在 {{jsapixref("JSObjectOps.lookupProperty")}}, {{jsapixref("JSObjectOps.getAttributes", "getAttributes")}}, {{jsapixref("JSObjectOps.getAttributes", "setAttributes")}}, 和 {{jsapixref("JSObjectOps.dropProperty", "dropProperty")}}中内部使用。</p> - -<h2 id="See_Also" name="See_Also">See Also</h2> - -<ul> - <li>{{bug(483473)}}</li> -</ul> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jspropertydescriptor/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jspropertydescriptor/index.html deleted file mode 100644 index 9f35d49fdb..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jspropertydescriptor/index.html +++ /dev/null @@ -1,69 +0,0 @@ ---- -title: JSPropertyDescriptor -slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSPropertyDescriptor -translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSPropertyDescriptor ---- -<div>{{SpiderMonkeySidebar("JSAPI")}}</div> - -<div class="summary">描述符是一个用于声明一个属性是否可以被修改,是否可以被删除,是否可以被枚举的一个对象</div> - -<h2 id="内容">内容</h2> - -<p>每一个属性只拥有一个描述符对象,但是这个对象中拥有多个键值,用来描述这个属性,下表说明了描述符中可以拥有的键值.</p> - -<table class="fullwidth-table"> - <tbody> - <tr> - <td class="header">Field Name</td> - <td class="header">Description</td> - </tr> - <tr> - <td><code>getter</code></td> - <td><code>get</code> 语法为属性绑定一个函数,每当查询该属性时便调用对应的函数,查询的结构为该函数的返回值</td> - </tr> - <tr> - <td><code>setter</code></td> - <td>如果试着改变一个属性的值,那么对应的 <em>setter</em> 函数将被执行</td> - </tr> - <tr> - <td><code>value</code></td> - <td>描述指定属性的值 , 可以是任何有效的 <em>Javascript</em> 值(函数 , 对象 , 字符串 ...).</td> - </tr> - <tr> - <td><code>configurable</code></td> - <td>当且仅当该属性的 <em>configurable</em> 为 true 时,该属性 <code>描述符</code> 才能够被改变, 同时该属性也能从对应的对象上被删除.</td> - </tr> - <tr> - <td><code>enumerable</code></td> - <td>描述指定的属性是否是 <a href="https://www.yuque.com/hardtoname/ur9xy2/rwbt5g#o93qms">可枚举</a> 的.</td> - </tr> - <tr> - <td><code>writable</code></td> - <td>当且仅当该属性的 <em>writable</em> 为 <code>true</code> 时, <em>value</em> 才能被赋值运算符改变。</td> - </tr> - </tbody> -</table> - -<h2 id="Description" name="Description">描述</h2> - -<p><em>描述符</em> 是描述对象属性的属性 , 对象里目前存在的属性描述符有两种主要形式:<strong>数据描述符 </strong>和 <strong>存取描述符</strong>. 可以通过 <em>Object.getOwnPropertyDescriptor()</em> 函数来获取某个对象下指定属性的对应的 <em>描述符</em> .</p> - -<h2 id="示例">示例</h2> - -<p>下面将演示通过 <em>Object.defineProperty()</em> 函数定义一个对象的属性.</p> - -<pre class="brush: js">var language = {}; // 定义一个空对象 language - -Object.defineProperty(language, 'log', { // 定义 language 对象下的 log 属性 - value : ['CN','EN'], - writable : true, - enumerable : true, - configurable : true -})</pre> - -<p>此时这是一个可读可写可枚举的属性 此时我们将这三个值都设为了 true 此时上面这段代码等价于:</p> - -<pre class="brush: js">var language = {}; // 定义一个空对象 language - -languange.log = ['CN','EN']; // 定义 language 对象下的 log 属性 -</pre> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jsruntime/index.html b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jsruntime/index.html deleted file mode 100644 index daabc3f876..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/jsruntime/index.html +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: JSRuntime -slug: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSRuntime -translation_of: Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSRuntime ---- -<div>{{SpiderMonkeySidebar("JSAPI")}}</div> - -<div> -<p><font><font>在JSAPI中,</font></font><code><strong>JSRuntime</strong></code><font><font>是代表JavaScript引擎实例的顶级对象。</font><font>一个程序通常只有一个</font></font><code>JSRuntime</code><font><font>,即使它有很多线程。</font><font>这</font></font><code>JSRuntime</code><font><font>是JavaScript对象所居住的世界;</font><font>他们不能去其他人</font></font><code>JSRuntime</code><font><font>。</font></font></p> - -<p><font><font>所有JavaScript代码和大多数JSAPI调用都在内运行</font></font><code><strong>JSContext</strong></code><font><font>。</font><font>该</font></font><code>JSContext</code><font><font>是对一个孩子</font></font><code>JSRuntime</code><font><font>。</font><font>上下文可以运行脚本。</font><font>它包含</font></font><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_GetGlobalObject" title="该函数已过时:请改用JS_GetGlobalForObject或JS_GetGlobalForScopeChain。 属于上下文的全局对象的概念可能会在以后的SpiderMonkey版本中逐步淘汰。"><font><font>全局对象</font></font></a><font><font>和执行堆栈。</font></font><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_SetPendingException" title="JS_SetPendingException设置在上下文中引发的当前异常。 如果已经引发异常,则将其替换为给定的新异常。"><font><font>异常处理</font></font></a><font><font>,</font></font><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_SetErrorReporter" title="JS_SetErrorReporter使您可以在应用程序中定义和使用自己的错误报告机制。 发生错误并由JS_ReportError解析后,您定义的报告程序会自动传递JSErrorReport结构。 JS_SetErrorReporter"><font><font>错误报告</font></font></a><font><font>和某些</font></font><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_SetOptions" title="JS_SetOptions设置给定JS上下文cx的选项标志。 此函数返回包含标志的先前值的uint32值。"><font><font>语言选项</font></font></a><font><font>是基于Per-的</font></font><code>JSContext</code><font><font>。</font><font>创建上下文后,可以将上下文多次用于不同的脚本或JSAPI查询。</font><font>例如,浏览器可能会为每个HTML页面创建一个单独的上下文。</font><font>页面中的每个脚本都可以使用相同的上下文。</font></font></p> - -<p><font><font>对象</font></font><code>在同一个</code><font><font> </font></font><code>JSRuntime</code><font><font>内</font></font><code>JSContext</code><font><font>之间可以共享。对象与创建对象的上下文之间没有固定的关联。</font></font></p> - -<p><font><font>设置和拆卸a </font></font><code>JSRuntime</code><font><font>和a的</font><font>示例代码</font></font><code>JSContext</code><font><font>在</font></font><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_User_Guide" title="JSAPI用户指南"><font><font>JSAPI用户指南中</font></font></a><font><font>。</font></font></p> -</div> - -<h3 id="Threads" name="Threads">线程</h3> - -<p><font><font>只有一个线程可以使用</font></font><code>JSContext </code><font><font>或</font></font><code>JSRuntime</code><font><font>。</font><font>较早的版本允许使用 </font></font><code>JS_ClearContextThread</code><font><font> 和其他功能将a </font></font><code>JSContext</code><font><font> 从一个线程</font><font>移动 </font><font>到另一个线程。</font><font>此功能已被删除。</font></font></p> - -<h2 id="相关文档"><font><font>相关文档</font></font></h2> - -<ul> - <li>{{jsapixref("JS_NewRuntime")}}</li> - <li>{{jsapixref("JS_DestroyRuntime")}}</li> - <li>{{jsapixref("JS_NewContext")}}</li> - <li>{{jsapixref("JS_DestroyContext")}}</li> -</ul> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/parser_api/index.html b/files/zh-cn/mozilla/projects/spidermonkey/parser_api/index.html deleted file mode 100644 index 03b00c9b00..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/parser_api/index.html +++ /dev/null @@ -1,1625 +0,0 @@ ---- -title: Parser API -slug: Mozilla/Projects/SpiderMonkey/Parser_API -translation_of: Mozilla/Projects/SpiderMonkey/Parser_API ---- -<p>{{ jsapi_minversion_header("1.8.5") }}</p> - -<p>最近构建的<a href="/En/SpiderMonkey/Build_Documentation" title="https://developer.mozilla.org/en/SpiderMonkey/Build_Documentation">独立的SpiderMonkey shell</a>包含了SpiderMonkey解析器的反射,可以通过JavaScript API来访问. 这使得我们更容易的用JavaScript写出处理JavaScript源代码的工具, 比如语法高亮工具,静态分析工具, 翻译器,编译器,混淆器等等.</p> - -<p>例子:</p> - -<pre>> var expr = Reflect.parse("obj.foo + 42").body[0].expression -> expr.left.property -({loc:null, type:"Identifier", name:"foo"}) -> expr.right -({loc:{source:null, start:{line:1, column:10}, end:{line:1, column:12}}, type:"Literal", value:42}) -</pre> - -<p>Reflect也可以使用在Firefox 7及以上版本中,但必须要导入一个模块:</p> - -<pre>Components.utils.import("resource://gre/modules/reflect.jsm") -</pre> - -<p>如果不想用<code>Reflect</code>全局对象,也可以指定一个对象名称:</p> - -<pre>Components.utils.import("resource://gre/modules/reflect.jsm", obj) -</pre> - -<h2 id="内置对象">内置对象</h2> - -<p>无论是SpiderMonkey shell还是Firefox (导入模块之后),全局对象<code>Reflect</code>目前都只有一个<code>parse</code>方法.</p> - -<h2 id="Reflect对象的属性"><code>Reflect</code>对象的属性</h2> - -<p><code>Reflect</code>对象目前只有一个方法.</p> - -<h4 id="Reflect.parse(src_options)"><code>Reflect.parse(src[, options])</code></h4> - -<p>将SRC强制转为字符串,并将结果作为javascript程序进行分析。默认情况下,解析返回一个表示被解析的抽象语法树(AST)的程序对象(见下文)</p> - -<p>可通过<strong>options</strong>对象提供其他选项, 可以使用的属性如下:</p> - -<table style="border: 1px solid #edf2f7; width: 67%;"> - <tbody> - <tr style="background-color: rgb(241, 246, 251);"> - <td><strong><span style="font-family: Courier New;">loc</span></strong></td> - <td>Boolean</td> - <td>Default: <span style="font-family: Courier New;">true</span></td> - </tr> - <tr> - <td colspan="3">如果<strong><span style="font-family: Courier New;">loc</span></strong>为<span style="font-family: Courier New;">true</span>,则解析器会在返回的AST节点中包含上源码的位置信息.</td> - </tr> - <tr style="background-color: rgb(241, 246, 251);"> - <td><strong><span style="font-family: Courier New;">source</span></strong></td> - <td>String</td> - <td>Default: <span style="font-family: Courier New;">null</span></td> - </tr> - <tr> - <td colspan="3">A description of the input source; typically a filename, path, or URL. This string is not meaningful to the parsing process, but is produced as part of the source location information in the returned AST nodes.</td> - </tr> - <tr style="background-color: rgb(241, 246, 251);"> - <td><strong><span style="font-family: Courier New;">line</span></strong></td> - <td>Number</td> - <td>Default: <span style="font-family: Courier New;">1</span></td> - </tr> - <tr> - <td colspan="3">初始行号,用在源码位置信息上.</td> - </tr> - <tr style="background-color: rgb(241, 246, 251);"> - <td><strong><span style="font-family: Courier New;">builder</span></strong></td> - <td>Builder</td> - <td>Default: <span style="font-family: Courier New;">null</span></td> - </tr> - <tr> - <td colspan="3"> - <p>A builder object, which can be used to produce AST nodes in custom data formats. The expected callback methods are described under <a href="/en/SpiderMonkey/Parser_API#Builder_objects" title="en/SpiderMonkey/Parser API#Builder objects">Builder Objects</a>.</p> - </td> - </tr> - </tbody> -</table> - -<p>If parsing fails due to a syntax error, an instance of <code>SyntaxError</code> is thrown. The syntax error object thrown by <code>Reflect.parse()</code> has the same <code>message</code> property as the syntax error that would be thrown by <code>eval(src)</code>. The <code>lineNumber</code> and <code>fileName</code> properties of the syntax error object indicate the source location of the syntax error.</p> - -<h2 id="节点对象">节点对象</h2> - -<p>默认情况下, <code>Reflect.parse()</code> 生成Node对象, 即普通的JavaScript对象 (i.e., 它们的原型来自标准的<code>Object原型</code>). 所有的节点类型都实现了以下的接口:</p> - -<pre>interface Node { - type: string; - loc: SourceLocation | null; -} -</pre> - -<p><code>type</code> 字段是一个字符串,代表AST变量类型.节点的每个子类型在下面的文档中都用其 <code>type</code> 字段特定的字符串标注出来了. 你可以使用这个字段去决定一个节点要实现的接口.</p> - -<p><code>loc</code> 字段代表节点的源位置信息. 如果解析器未生成有关节点的源位置信息, <code>null</code> 字段为空;否则它是一个对象, 包括一个起始位置 (the position of the first character of the parsed source region) 和一个结束位置 (the position of the first character <em>after</em> the parsed source region):ss</p> - -<pre>interface SourceLocation { - source: string | null; - start: Position; - end: Position; -} -</pre> - -<p>每个 <code>Position</code> 包括一个 <code>line</code> 数字 (1-indexed) 和 <code>column</code> 数字 (0-indexed):</p> - -<pre>interface Position { - line: uint32 >= 1; - column: uint32 >= 0; -}</pre> - -<h3 id="Programs">Programs</h3> - -<pre>interface Program <: Node { - type: "Program"; - body: [ Statement ]; -} -</pre> - -<p>A complete program source tree.</p> - -<h3 id="函数">函数</h3> - -<pre>interface Function <: Node { - id: Identifier | null; - params: [ Pattern ]; - defaults: [ Expression ]; - rest: Identifier | null; - body: BlockStatement | Expression; - generator: boolean; - expression: boolean; -} -</pre> - -<p>A function declaration or expression. The <code>body</code> of the function may be a block statement, or in the case of an <a href="/en/JavaScript/New_in_JavaScript/1.8#Expression_closures_%28Merge_into_own_page.2fsection%29" title="https://developer.mozilla.org/en/new_in_javascript_1.8#Expression_closures_(Merge_into_own_page.2fsection)">expression closure</a>, an expression.</p> - -<div class="note"><strong>注:</strong> Expression closures 是SpiderMonkey特有的.</div> - -<p>If the <code>generator</code> flag is <code>true</code>, the function is a <a href="/en/JavaScript/Guide/Iterators_and_Generators" title="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Iterators_and_Generators">generator function</a>, i.e., contains a <code>yield</code> expression in its body (other than in a nested function).</p> - -<div class="note"><strong>注:</strong> Generators 是SpiderMonkey特有的.</div> - -<p>If the <code>expression</code> flag is <code>true</code>, the function is an expression closure and the <code>body</code> field is an expression.</p> - -<h3 id="语句">语句</h3> - -<pre>interface Statement <: Node { } -</pre> - -<p>任意语句.</p> - -<pre>interface EmptyStatement <: Statement { - type: "EmptyStatement"; -} -</pre> - -<p>一个空语句,也就是,一个孤立的分号.</p> - -<pre>interface BlockStatement <: Statement { - type: "BlockStatement"; - body: [ Statement ]; -} -</pre> - -<p>一个语句块,也就是由大括号包围的语句序列.</p> - -<pre>interface ExpressionStatement <: Statement { - type: "ExpressionStatement"; - expression: Expression; -} -</pre> - -<p>一个表达式语句,也就是,仅有一个表达式组成的语句.</p> - -<pre>interface IfStatement <: Statement { - type: "IfStatement"; - test: Expression; - consequent: Statement; - alternate: Statement | null; -} -</pre> - -<p>一个<code>if</code>语句.</p> - -<pre>interface LabeledStatement <: Statement { - type: "LabeledStatement"; - label: Identifier; - body: Statement; -} -</pre> - -<p>一个标签语句,也就是, a statement prefixed by a <code>break</code>/<code>continue</code> label.</p> - -<pre>interface BreakStatement <: Statement { - type: "BreakStatement"; - label: Identifier | null; -} -</pre> - -<p>一个<code>break</code>语句.</p> - -<pre>interface ContinueStatement <: Statement { - type: "ContinueStatement"; - label: Identifier | null; -} -</pre> - -<p>一个<code>continue语句</code>.</p> - -<pre>interface WithStatement <: Statement { - type: "WithStatement"; - object: Expression; - body: Statement; -} -</pre> - -<p>A <code>with</code> statement.</p> - -<pre>interface SwitchStatement <: Statement { - type: "SwitchStatement"; - discriminant: Expression; - cases: [ SwitchCase ]; - lexical: boolean; -} -</pre> - -<p>一个<code>switch</code>语句. The lexical flag is metadata indicating whether the <code>switch</code> statement contains any unnested <code>let</code> declarations (and therefore introduces a new lexical scope).</p> - -<pre>interface ReturnStatement <: Statement { - type: "ReturnStatement"; - argument: Expression | null; -} -</pre> - -<p>一个<code>return</code>语句.</p> - -<pre>interface ThrowStatement <: Statement { - type: "ThrowStatement"; - argument: Expression; -} -</pre> - -<p>一个<code>throw</code>语句.</p> - -<pre>interface TryStatement <: Statement { - type: "TryStatement"; - block: BlockStatement; - handlers: [ CatchClause ]; - finalizer: BlockStatement | null; -} -</pre> - -<p>一个<code>try</code>语句.</p> - -<div class="note"><strong>注:</strong> 多个<code>catch</code>子句是SpiderMonkey特有的.</div> - -<pre>interface WhileStatement <: Statement { - type: "WhileStatement"; - test: Expression; - body: Statement; -} -</pre> - -<p>一个<code>while</code>语句.</p> - -<pre>interface DoWhileStatement <: Statement { - type: "DoWhileStatement"; - body: Statement; - test: Expression; -} -</pre> - -<p>一个<code>do</code>/<code>while</code>语句.</p> - -<pre>interface ForStatement <: Statement { - type: "ForStatement"; - init: VariableDeclaration | Expression | null; - test: Expression | null; - update: Expression | null; - body: Statement; -} -</pre> - -<p>一个<code>for</code>语句.</p> - -<pre>interface ForInStatement <: Statement { - type: "ForInStatement"; - left: VariableDeclaration | Expression; - right: Expression; - body: Statement; - each: boolean; -} -</pre> - -<p>一个<code>for</code>/<code>in</code>语句, or, if <code>each</code> is <code>true</code>, a <code>for each</code>/<code>in</code> statement.</p> - -<div class="note"><strong>注:</strong> <code>for each</code>语法是SpiderMonkey特有的.</div> - -<pre>interface LetStatement <: Statement { - type: "LetStatement"; - head: [ { id: Pattern, init: Expression | null } ]; - body: Statement; -} -</pre> - -<p>一个<code>let语句</code>.</p> - -<div class="note"><strong>注:</strong> <code>let</code>语句形式是SpiderMonkey特有的.</div> - -<pre>interface DebuggerStatement <: Statement { - type: "DebuggerStatement"; -} -</pre> - -<p>一个<code>debugger</code>语句.</p> - -<div class="note"><strong>注:</strong> <code>debugger</code>语句是ECMAScript 5中的新语法,尽管SpiderMonkey已经支持它很多年了.</div> - -<h3 id="声明">声明</h3> - -<pre>interface Declaration <: Statement { } -</pre> - -<p>Any declaration node. Note that declarations are considered statements; this is because declarations can appear in any statement context in the language recognized by the SpiderMonkey parser.</p> - -<div class="note"><strong>注:</strong> 任意嵌套作用域下的声明是SpiderMonkey特有的.</div> - -<pre>interface FunctionDeclaration <: Function, Declaration { - type: "FunctionDeclaration"; - id: Identifier; - params: [ Pattern ]; - defaults: [ Expression ]; - rest: Identifier | null; - body: BlockStatement | Expression; - generator: boolean; - expression: boolean; -} -</pre> - -<p>一个函数声明.</p> - -<div class="note"><strong>注:</strong> <code>id</code>字段不能为<code>null</code>.</div> - -<pre>interface VariableDeclaration <: Declaration { - type: "VariableDeclaration"; - declarations: [ VariableDeclarator ]; - kind: "var" | "let" | "const"; -} -</pre> - -<p>一个变量声明,可以通过<code>var</code>, <code>let</code>, 或<code>const</code>.</p> - -<pre>interface VariableDeclarator <: Node { - type: "VariableDeclarator"; - id: Pattern; - init: Expression | null; -} -</pre> - -<p>一个变量<span class="st">声明符</span>.</p> - -<div class="note"><strong>注:</strong> <code>id</code>字段不能为<code>null</code>.</div> - -<div class="note"><strong>注:</strong> <code>let</code>和<code>const是</code>SpiderMonkey特有的.</div> - -<h3 id="表达式">表达式</h3> - -<pre>interface Expression <: Node, Pattern { }</pre> - -<p>任意表达式节点. Since the left-hand side of an assignment may be any expression in general, an expression can also be a pattern.</p> - -<pre>interface ThisExpression <: Expression { - type: "ThisExpression"; -} -</pre> - -<p>一个<code>this</code>表达式.</p> - -<pre>interface ArrayExpression <: Expression { - type: "ArrayExpression"; - elements: [ Expression | null ]; -}</pre> - -<p>一个数组表达式.</p> - -<pre>interface ObjectExpression <: Expression { - type: "ObjectExpression"; - properties: [ { key: Literal | Identifier, - value: Expression, - kind: "init" | "get" | "set" } ]; -}</pre> - -<p>一个对象表达式. A literal property in an object expression can have either a string or number as its <code>value</code>. Ordinary property initializers have a <code>kind</code> value <code>"init"</code>; getters and setters have the <code>kind</code> values <code>"get"</code> and <code>"set"</code>, respectively.</p> - -<pre>interface FunctionExpression <: Function, Expression { - type: "FunctionExpression"; - id: Identifier | null; - params: [ Pattern ]; - defaults: [ Expression ]; - rest: Identifier | null; - body: BlockStatement | Expression; - generator: boolean; - expression: boolean; -} -</pre> - -<p>一个函数表达式.</p> - -<pre>interface SequenceExpression <: Expression { - type: "SequenceExpression"; - expressions: [ Expression ]; -}</pre> - -<p>一个序列表达式,也就是一个由逗号分割的表达式序列.</p> - -<pre>interface UnaryExpression <: Expression { - type: "UnaryExpression"; - operator: UnaryOperator; - prefix: boolean; - argument: Expression; -}</pre> - -<p>A unary operator expression.</p> - -<pre>interface BinaryExpression <: Expression { - type: "BinaryExpression"; - operator: BinaryOperator; - left: Expression; - right: Expression; -}</pre> - -<p>一个二元运算符表达式.</p> - -<pre>interface AssignmentExpression <: Expression { - type: "AssignmentExpression"; - operator: AssignmentOperator; - left: Expression; - right: Expression; -}</pre> - -<p>An assignment operator expression.</p> - -<pre>interface UpdateExpression <: Expression { - type: "UpdateExpression"; - operator: UpdateOperator; - argument: Expression; - prefix: boolean; -}</pre> - -<p>An update (increment or decrement) operator expression.</p> - -<pre>interface LogicalExpression <: Expression { - type: "LogicalExpression"; - operator: LogicalOperator; - left: Expression; - right: Expression; -}</pre> - -<p>一个逻辑运算符表达式.</p> - -<pre>interface ConditionalExpression <: Expression { - type: "ConditionalExpression"; - test: Expression; - alternate: Expression; - consequent: Expression; -}</pre> - -<p>一个条件运算符表达式, i.e., a ternary <code>?</code>/<code>:</code> expression.</p> - -<pre>interface NewExpression <: Expression { - type: "NewExpression"; - callee: Expression; - arguments: [ Expression ] | null; -}</pre> - -<p>A <code>new</code> expression.</p> - -<pre>interface CallExpression <: Expression { - type: "CallExpression"; - callee: Expression; - arguments: [ Expression ]; -}</pre> - -<p>A function or method call expression.</p> - -<pre>interface MemberExpression <: Expression { - type: "MemberExpression"; - object: Expression; - property: Identifier | Expression; - computed : boolean; -}</pre> - -<p>一个member表达式. If <code>computed === true</code>, the node corresponds to a computed <code>e1[e2]</code> expression and property is an <code>Expression</code>. If <code>computed === false</code>, the node corresponds to a static <code>e1.x</code> expression and property is an <code>Identifier</code>.</p> - -<pre>interface YieldExpression <: Expression { - argument: Expression | null; -} -</pre> - -<p>A <code>yield</code> expression.</p> - -<div class="note"><strong>注:</strong> <code>yield</code> expressions 是SpiderMonkey特有的.</div> - -<pre>interface ComprehensionExpression <: Expression { - body: Expression; - blocks: [ ComprehensionBlock ]; - filter: Expression | null; -} -</pre> - -<p>An <a href="/en/JavaScript/Guide/Obsolete_Pages/Working_with_Arrays#Array_comprehensions" title="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Working_with_Arrays#Array_comprehensions">array comprehension</a>. The <code>blocks</code> array corresponds to the sequence of <code>for</code> and <code>for each</code> blocks. The optional <code>filter</code> expression corresponds to the final <code>if</code> clause, if present.</p> - -<div class="note"><strong>注:</strong> Array comprehensions 是SpiderMonkey特有的.</div> - -<pre>interface GeneratorExpression <: Expression { - body: Expression; - blocks: [ ComprehensionBlock ]; - filter: Expression | null; -} -</pre> - -<p>A <a href="/en/JavaScript/Guide/Iterators_and_Generators#Generator_expressions" title="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Iterators_and_Generators#Generator_expressions">generator expression</a>. As with array comprehensions, the <code>blocks</code> array corresponds to the sequence of <code>for</code> and <code>for each</code> blocks, and the optional <code>filter</code> expression corresponds to the final <code>if</code> clause, if present.</p> - -<div class="note"><strong>注:</strong> Generator expressions 是SpiderMonkey特有的.</div> - -<pre>interface GraphExpression <: Expression { - index: uint32; - expression: Literal; -} -</pre> - -<p>A <a href="/en/JavaScript/Sharp_variables_in_JavaScript" title="https://developer.mozilla.org/en/Sharp_variables_in_JavaScript">graph expression</a>, aka "sharp literal," such as <code>#1={ self: #1# }</code>.</p> - -<div class="note"><strong>注:</strong> Graph expressions 是SpiderMonkey特有的.</div> - -<pre>interface GraphIndexExpression <: Expression { - index: uint32; -} -</pre> - -<p>一个<a href="/en/JavaScript/Sharp_variables_in_JavaScript" title="https://developer.mozilla.org/en/Sharp_variables_in_JavaScript">graph索引表达式</a>,又称为"井号变量",比如<code>#1#</code>.</p> - -<div class="note"><strong>注:</strong> Graph索引表达式</div> - -<div class="note">Graph索引表达式是SpiderMonkey特有的.</div> - -<pre>interface LetExpression <: Expression { - type: "LetExpression"; - head: [ { id: Pattern, init: Expression | null } ]; - body: Expression; -} -</pre> - -<p>一个<code>let表达式</code>.</p> - -<div class="note"><strong>注:</strong> <code>let</code>表达式是SpiderMonkey特有的.</div> - -<h3 id="模式">模式</h3> - -<pre>interface Pattern <: Node { } -</pre> - -<p>JavaScript 1.7 introduced <a href="/en/JavaScript/New_in_JavaScript/1.7#Destructuring_assignment_%28Merge_into_own_page.2fsection%29" title="https://developer.mozilla.org/en/new_in_javascript_1.7#Destructuring_assignment_(Merge_into_own_page.2fsection)">destructuring assignment and binding</a> forms. All binding forms (such as function parameters, variable declarations, and <code>catch</code> block headers), accept array and object destructuring patterns in addition to plain identifiers. The left-hand sides of assignment expressions can be arbitrary expressions, but in the case where the expression is an object or array literal, it is interpreted by SpiderMonkey as a destructuring pattern.</p> - -<p>Since the left-hand side of an assignment can in general be any expression, in an assignment context, a pattern can be any expression. In binding positions (such as function parameters, variable declarations, and <code>catch</code> headers), patterns can only be identifiers in the base case, not arbitrary expressions.</p> - -<pre>interface ObjectPattern <: Pattern { - type: "ObjectPattern"; - properties: [ { key: Literal | Identifier, value: Pattern } ]; -} -</pre> - -<p>An object-destructuring pattern. A literal property in an object pattern can have either a string or number as its <code>value</code>.</p> - -<pre>interface ArrayPattern <: Pattern { - type: "ArrayPattern"; - elements: [ Pattern | null ]; -} -</pre> - -<p>An array-destructuring pattern.</p> - -<h3 id="子句">子句</h3> - -<pre>interface SwitchCase <: Node { - type: "SwitchCase"; - test: Expression | null; - consequent: [ Statement ]; -} -</pre> - -<p>一个<code>case</code> (if <code>test</code> is an <code>Expression</code>) or <code>default</code> (if <code>test === null</code>) clause in the body of a <code>switch</code>语句.</p> - -<pre>interface CatchClause <: Node { - type: "CatchClause"; - param: Pattern; - guard: Expression | null; - body: BlockStatement; -} -</pre> - -<p>A <code>catch</code> clause following a <code>try</code> block. The optional <code>guard</code> property corresponds to the optional expression guard on the bound variable.</p> - -<div class="note"><strong>注:</strong> The guard expression is SpiderMonkey-specific.</div> - -<pre>interface ComprehensionBlock <: Node { - left: Pattern; - right: Expression; - each: boolean; -} -</pre> - -<p>A <code>for</code> or <code>for each</code> block in an array comprehension or generator expression.</p> - -<div class="note"><strong>注:</strong> Array comprehensions and generator expressions 是SpiderMonkey特有的.</div> - -<h3 class="r" id="杂项"><nobr>杂项</nobr></h3> - -<pre>interface Identifier <: Node, Expression, Pattern { - type: "Identifier"; - name: string; -} -</pre> - -<p>An identifier. Note that an identifier may be an expression or a destructuring pattern.</p> - -<pre>interface Literal <: Node, Expression { - type: "Literal"; - value: string | boolean | null | number | RegExp; -} -</pre> - -<p>A literal token. Note that a literal can be an expression.</p> - -<pre>enum UnaryOperator { - "-" | "+" | "!" | "~" | "typeof" | "void" | "delete" -} -</pre> - -<p>A unary operator token.</p> - -<pre>enum BinaryOperator { - "==" | "!=" | "===" | "!==" - | "<" | "<=" | ">" | ">=" - | "<<" | ">>" | ">>>" - | "+" | "-" | "*" | "/" | "%" - | "|" | "^" | "in" - | "instanceof" | ".." -} -</pre> - -<p>A binary operator token.</p> - -<div class="note"><strong>注:</strong> The <code>..</code> operator is E4X-specific.</div> - -<pre>enum LogicalOperator { - "||" | "&&" -} -</pre> - -<p>A logical operator token.</p> - -<pre>enum AssignmentOperator { - "=" | "+=" | "-=" | "*=" | "/=" | "%=" - | "<<=" | ">>=" | ">>>=" - | "|=" | "^=" | "&=" -} -</pre> - -<p>An assignment operator token.</p> - -<pre>enum UpdateOperator { - "++" | "--" -} -</pre> - -<p>An update (increment or decrement) operator token.</p> - -<h3 id="E4X">E4X</h3> - -<p>下面介绍一下为E4X提供支持的节点类型.</p> - -<div class="note"><strong>注:</strong> E4X不是ECMAScript规范(<a class="external" href="http://www.ecma-international.org/publications/standards/Ecma-262.htm" title="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMA-262</a>)的一部分,它是一个单独的标准(<a class="external" href="http://www.ecma-international.org/publications/standards/Ecma-357.htm" title="http://www.ecma-international.org/publications/standards/Ecma-357.htm">ECMA-357</a>).</div> - -<h4 id="声明_2">声明</h4> - -<pre>interface XMLDefaultDeclaration <: Declaration { - type: "XMLDefaultDeclaration"; - namespace: Expression; -} -</pre> - -<p>一个默认<code>xml命名空间</code>声明</p> - -<h4 id="表达式_2">表达式</h4> - -<pre>interface XMLAnyName <: Expression { - type: "XMLAnyName"; -} -</pre> - -<p>The special E4X wildcard pseudo-identifier <code>*</code>.</p> - -<pre>interface XMLQualifiedIdentifier <: Expression { - type: "XMLQualifiedIdentifier"; - left: Identifier | XMLAnyName; - right: Identifier | Expression; - computed: boolean; -} -</pre> - -<p>An E4X qualified identifier, i.e., a pseudo-identifier using the namespace separator <code>::</code>. If the qualified identifier has a computed name (i.e., the <code>id::[expr]</code> form), then <code>computed</code> is <code>true</code> and the <code>right</code> property is an expression.</p> - -<pre>interface XMLFunctionQualifiedIdentifier <: Expression { - type: "XMLFunctionQualifiedIdentifier"; - right: Identifier | Expression; - computed: boolean; -} -</pre> - -<p>An E4X identifier qualified by the <code>function</code> keyword, e.g. <code>function::id</code>.</p> - -<div class="note"><strong>注:</strong> <code>function</code>-qualified identifiers 是SpiderMonkey特有的.</div> - -<pre>interface XMLAttributeSelector <: Expression { - type: "XMLAttributeSelector"; - attribute: Expression; -} -</pre> - -<p>An E4X attribute selector expression, i.e., an <code>@</code> expression.</p> - -<pre>interface XMLFilterExpression <: Expression { - type: "XMLFilterExpression"; - left: Expression; - right: Expression; -} -</pre> - -<p>An E4X list filter expression, i.e., an expression of the form <code>expr.(expr)</code>.</p> - -<pre>interface XMLElement <: XML, Expression { - type: "XMLElement"; - contents: [ XML ]; -} -</pre> - -<p>An E4X literal representing a single XML element.</p> - -<pre>interface XMLList <: XML, Expression { - type: "XMLList"; - contents: [ XML ]; -} -</pre> - -<p>An E4X literal representing a list of XML elements.</p> - -<h4 id="XML">XML</h4> - -<pre>interface XML <: Node { } -</pre> - -<p>XML data.</p> - -<pre>interface XMLEscape <: XML { - type "XMLEscape"; - expression: Expression; -} -</pre> - -<p>XML data with an escaped JavaScript expression.</p> - -<pre>interface XMLText <: XML { - type: "XMLText"; - text: string; -} -</pre> - -<p>Literal XML text.</p> - -<pre>interface XMLStartTag <: XML { - type: "XMLStartTag"; - contents: [ XML ]; -} -</pre> - -<p>An XML start tag.</p> - -<pre>interface XMLEndTag <: XML { - type: "XMLEndTag"; - contents: [ XML ]; -} -</pre> - -<p>An XML end tag.</p> - -<pre>interface XMLPointTag <: XML { - type: "XMLPointTag"; - contents: [ XML ]; -} -</pre> - -<p>An XML point tag.</p> - -<pre>interface XMLName <: XML { - type: "XMLName"; - contents: string | [ XML ]; -} -</pre> - -<p>An XML name.</p> - -<pre>interface XMLAttribute <: XML { - type: "XMLAttribute"; - value: string; -} -</pre> - -<p>An XML attribute value.</p> - -<pre>interface XMLCdata <: XML { - type: "XMLCdata"; - contents: string; -} -</pre> - -<p>An XML CDATA node.</p> - -<pre>interface XMLComment <: XML { - type: "XMLComment"; - contents: string; -} -</pre> - -<p>An XML comment.</p> - -<pre>interface XMLProcessingInstruction <: XML { - type: "XMLProcessingInstruction"; - target: string; - contents: string | null; -} -</pre> - -<p>An XML processing instruction.</p> - -<h2 id="Builder_objects">Builder objects</h2> - -<p>The optional <strong><code>builder</code></strong> parameter to <code>Reflect.parse()</code> makes it possible to construct user-specified data from the parser, rather than the default <code>Node</code> objects. Builder objects may contain any of the callback methods described in this section.</p> - -<p>Each callback can produce any custom, user-defined datatype; these are referred to below as <code>CustomExpression</code>, <code>CustomStatement</code>, etc.</p> - -<div class="note"><strong>注:</strong> Because this library uses <code>null</code> for optional nodes, it is recommended that user-defined datatypes <strong>not</strong> use <code>null</code> as a representation of an AST node.</div> - -<p>If the <strong><code>loc</code></strong> option is enabled (see the <a href="/en/SpiderMonkey/Parser_API#Reflect.parse(src.5b.2c_options.5d)" title="en/SpiderMonkey/Parser API#Reflect.parse(src.5b.2c options.5d)">Reflect.parse() options</a> above), then each callback is provided with the source location information of the parsed node as an extra parameter.</p> - -<p>All builder callbacks are optional. When a callback is missing, the default format is used, but the provided builder methods are still used recursively for sub-nodes.</p> - -<h3 id="Programs_2">Programs</h3> - -<h5 id="program(body_loc)"><code>program(body[, loc])</code></h5> - -<pre>body: [ CustomStatement ] -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomProgram</p> - -<p>Callback to produce a custom program node.</p> - -<h3 id="Statements">Statements</h3> - -<h5 id="emptyStatement(loc)"><code>emptyStatement([loc])</code></h5> - -<pre>loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom empty statement node.</p> - -<h5 id="blockStatement(body_loc)"><code>blockStatement(body[, loc])</code></h5> - -<pre>body: CustomStatement -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom block statement node.</p> - -<h5 id="expressionStatement(expr_loc)"><code>expressionStatement(expr[, loc])</code></h5> - -<pre>expr: CustomExpression -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom expression statement node.</p> - -<h5 id="labeledStatement(label_body_loc)"><code>labeledStatement(label, body[, loc])</code></h5> - -<pre>label: CustomIdentifier -body: CustomStatement -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom labeled statement node.</p> - -<h5 id="ifStatement(test_cons_alt_loc)"><code>ifStatement(test, cons, alt[, loc])</code></h5> - -<pre>test: CustomExpression -cons: CustomStatement -alt: CustomStatement | null -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom <code>if</code> statement node.</p> - -<h5 id="switchStatement(disc_cases_isLexical_loc)"><code>switchStatement(disc, cases, isLexical[, loc])</code></h5> - -<pre>disc: CustomExpression -cases: [ CustomSwitchCase ] -isLexical: boolean -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom <code>switch</code> statement node. The <strong><code>isLexical</code></strong> flag is metadata indicating whether the <code>switch</code> statement contains any unnested <code>let</code> declarations (and therefore introduces a new lexical scope).</p> - -<h5 id="whileStatement(test_body_loc)"><code>whileStatement(test, body[, loc])</code></h5> - -<pre>test: CustomExpression -body: CustomStatement -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom <code>while</code> statement node.</p> - -<h5 id="doWhileStatement(body_test_loc)"><code>doWhileStatement(body, test[, loc])</code></h5> - -<pre>body: CustomStatement -test: CustomExpression -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom <code>do</code>-<code>while</code> statement node.</p> - -<h5 id="forStatement(init_test_update_body_loc)"><code>forStatement(init, test, update, body[, loc])</code></h5> - -<pre>init: CustomVariableDeclaration | CustomExpression | null -test: CustomExpression | null -update: CustomExpression | null -body: CustomStatement -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom <code>for</code> statement node.</p> - -<h5 id="forInStatement(left_right_body_isForEach_loc)"><code>forInStatement(left, right, body, isForEach[, loc])</code></h5> - -<pre>left: CustomVariableDeclaration | CustomExpression -right: CustomExpression -body: CustomStatement -isForEach: boolean -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom <code>for</code>-<code>in</code> statement node. The <strong><code>isForEach</code></strong> flag indicates whether the node is a <code>for each</code> statement.</p> - -<h5 id="breakStatement(label_loc)"><code>breakStatement(label[, loc])</code></h5> - -<pre>label: CustomIdentifier | null -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom <code>break</code> statement node.</p> - -<h5 id="continueStatement(label_loc)"><code>continueStatement(label[, loc])</code></h5> - -<pre>label: CustomIdentifier | null -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom <code>continue</code> statement node.</p> - -<h5 id="withStatement(obj_body_loc)"><code>withStatement(obj, body[, loc])</code></h5> - -<pre>obj: CustomExpression -body: CustomStatement -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom <code>with</code> statement node.</p> - -<h5 id="returnStatement(arg_loc)"><code>returnStatement(arg[, loc])</code></h5> - -<pre>arg: CustomExpression | null -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom <code>return</code> statement node.</p> - -<h5 id="tryStatement(body_handlers_fin_loc)"><code>tryStatement(body, handlers, fin[, loc])</code></h5> - -<pre>body: CustomStatement -handlers: [ CustomCatchClause ] -fin: CustomStatement | null -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom <code>try</code> statement node.</p> - -<h5 id="throwStatement(arg_loc)"><code>throwStatement(arg[, loc])</code></h5> - -<pre>arg: CustomExpression -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom <code>throw</code> statement node.</p> - -<h5 id="debuggerStatement(loc)"><code>debuggerStatement([loc])</code></h5> - -<pre>loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom <code>debugger</code> statement node.</p> - -<h5 id="letStatement(head_body_loc)"><code>letStatement(head, body[, loc])</code></h5> - -<pre>head: [ CustomDeclarator ] -body: CustomStatement -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomStatement</p> - -<p>Callback to produce a custom <code>let</code> statement node.</p> - -<h3 id="声明_3">声明</h3> - -<h5 id="functionDeclaration(name_args_body_isGenerator_isExpression_loc)"><code>functionDeclaration(name, args, body, isGenerator, isExpression[, loc])</code></h5> - -<pre>name: string -args: [ CustomPattern ] -body: CustomStatement | CustomExpression -isGenerator: boolean -isExpression: boolean -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomDeclaration</p> - -<p>Callback to produce a custom function declaration node.</p> - -<h5 id="variableDeclaration(kind_dtors_loc)"><code>variableDeclaration(kind, dtors[, loc])</code></h5> - -<pre>kind: "const" | "let" | "var" -dtors: [ CustomDeclarator ] -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomDeclaration</p> - -<p>Callback to produce a custom variable declaration node.</p> - -<h5 id="variableDeclarator(patt_init_loc)"><code>variableDeclarator(patt, init[, loc])</code></h5> - -<pre>patt: CustomPattern -init: CustomExpression | null -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomDeclarator</p> - -<p>Callback to produce a custom variable declarator node.</p> - -<h3 id="表达式_3">表达式</h3> - -<h5 id="sequenceExpression(exprs_loc)"><code>sequenceExpression(exprs[, loc])</code></h5> - -<pre>exprs: [ CustomExpression ] -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom sequence expression node.</p> - -<h5 id="conditionalExpression(test_cons_alt_loc)"><code>conditionalExpression(test, cons, alt[, loc])</code></h5> - -<pre>test: CustomExpression -cons: CustomExpression -alt: CustomExpression -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom conditional expression node.</p> - -<h5 id="unaryExpression(op_arg_isPrefix_loc)"><code>unaryExpression(op, arg, isPrefix[, loc])</code></h5> - -<pre>op: UnaryOperator -arg: CustomExpression -isPrefix: boolean -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom unary expression node.</p> - -<h5 id="binaryExpression(op_left_right_loc)"><code>binaryExpression(op, left, right[, loc])</code></h5> - -<pre>op: BinaryOperator -left: CustomExpression -right: CustomExpression -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom binary expression node.</p> - -<h5 id="assignmentExpression(op_left_right_loc)"><code>assignmentExpression(op, left, right[, loc])</code></h5> - -<pre>op: AssignmentOperator -left: CustomExpression -right: CustomExpression -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom assignment expression node.</p> - -<h5 id="logicalExpression(op_left_right_loc)"><code>logicalExpression(op, left, right[, loc])</code></h5> - -<pre>op: LogicalOperator -left: CustomExpression -right: CustomExpression -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom logical expression node.</p> - -<h5 id="updateExpression(op_arg_isPrefix_loc)"><code>updateExpression(op, arg, isPrefix[, loc])</code></h5> - -<pre>op: UpdateOperator -arg: CustomExpression -isPrefix: boolean -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom update expression node.</p> - -<h5 id="newExpression(callee_args_loc)"><code>newExpression(callee, args[, loc])</code></h5> - -<pre>callee: CustomExpression -args: [ CustomExpression ] -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom <code>new</code>-expression node.</p> - -<h5 id="callExpression(callee_args_loc)"><code>callExpression(callee, args[, loc])</code></h5> - -<pre>callee: CustomExpression -args: [ CustomExpression ] -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom function call node.</p> - -<h5 id="memberExpression(obj_prop_isComputed_loc)"><code>memberExpression(obj, prop, isComputed[, loc])</code></h5> - -<pre>obj: CustomExpression -prop: CustomIdentifier | CustomExpression -isComputed: boolean -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom member expression node.</p> - -<h5 id="functionExpression(name_args_body_isGenerator_isExpression_loc)"><code>functionExpression(name, args, body, isGenerator, isExpression[, loc])</code></h5> - -<pre>name: CustomIdentifier | null -args: [ CustomPattern ] -body: CustomStatement | CustomExpression -isGenerator: boolean -isExpression: boolean -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom function expression node.</p> - -<h5 id="arrayExpression(elts_loc)"><code>arrayExpression(elts[, loc])</code></h5> - -<pre>elts: [ CustomExpression | null ] -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom array expression node.</p> - -<h5 id="objectExpression(props_loc)"><code>objectExpression(props[, loc])</code></h5> - -<pre>props: [ CustomObjectProperty ] -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom object expression node.</p> - -<h5 id="thisExpression(loc)"><code>thisExpression([loc])</code></h5> - -<pre>loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom <code>this</code> expression node.</p> - -<h5 id="graphExpression(index_expr_loc)"><code>graphExpression(index, expr[, loc])</code></h5> - -<pre>index: uint32 >= 1 -expr: CustomExpression -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom <code>graph</code> expression node.</p> - -<h5 id="graphIndexExpression(index_loc)"><code>graphIndexExpression(index[, loc])</code></h5> - -<pre>index: uint32 >= 1 -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom <code>graph index</code> expression node.</p> - -<h5 id="comprehensionExpression(body_blocks_filter_loc)"><code>comprehensionExpression(body, blocks, filter[, loc])</code></h5> - -<pre>body: CustomExpression -blocks: [ CustomComprehensionBlock ] -filter: CustomExpression | null -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom <code>comprehension</code> expression node.</p> - -<h5 id="generatorExpression(body_blocks_filter_loc)"><code>generatorExpression(body, blocks, filter[, loc])</code></h5> - -<pre>body: CustomExpression -blocks: [ CustomComprehensionBlock ] -filter: CustomExpression | null -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom <code>generator</code> expression node.</p> - -<h5 id="yieldExpression(arg_loc)"><code>yieldExpression(arg[, loc])</code></h5> - -<pre>arg: CustomExpression -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom <code>yield</code> expression node.</p> - -<h5 id="letExpression(head_body_loc)"><code>letExpression(head, body[, loc])</code></h5> - -<pre>head: [ CustomDeclarator ] -body: CustomExpression -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomExpression</p> - -<p>Callback to produce a custom <code>let</code> expression node.</p> - -<h3 id="Patterns">Patterns</h3> - -<h5 id="arrayPattern(elts_loc)"><code>arrayPattern(elts[, loc])</code></h5> - -<pre>elts: [ CustomPattern | null ] -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomPattern</p> - -<p>Callback to produce a custom array destructuring pattern node.</p> - -<h5 id="objectPattern(props_loc)"><code>objectPattern(props[, loc])</code></h5> - -<pre>props: [ CustomPropertyPattern ] -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomPattern</p> - -<p>Callback to produce a custom object destructuring pattern node.</p> - -<h5 id="propertyPattern(key_patt_loc)"><code>propertyPattern(key, patt[, loc])</code></h5> - -<pre>key: CustomLiteral | CustomIdentifier -patt: CustomPattern -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomPropertyPattern</p> - -<p>Callback to produce a custom object property destructuring pattern node.</p> - -<h3 id="Clauses">Clauses</h3> - -<h5 id="switchCase(test_cons_loc)"><code>switchCase(test, cons[, loc])</code></h5> - -<pre>test: CustomExpression | null -cons: [ CustomStatement ] -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomSwitchCase</p> - -<p>Callback to produce a custom <code>case</code> or <code>default</code> clause node. The <strong><code>test</code></strong> argument is <code>null</code> if and only if the node is a <code>default</code> clause.</p> - -<h5 id="catchClause(arg_guard_body_loc)"><code>catchClause(arg, guard, body[, loc])</code></h5> - -<pre>arg: CustomPattern -guard: CustomExpression -body: CustomStatement -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomCatchClause</p> - -<p>Callback to produce a custom <code>catch</code> clause node.</p> - -<h5 id="comprehensionBlock(left_right_isForEach_loc)"><code>comprehensionBlock(left, right, isForEach[, loc])</code></h5> - -<pre>left: CustomPattern -right: CustomExpression -isForEach: boolean -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomComprehensionBlock</p> - -<p>Callback to produce a custom comprehension block node. The <strong><code>isForEach</code></strong> flag indicates whether the node is a <code>for each</code> block.</p> - -<h3 id="Miscellaneous">Miscellaneous</h3> - -<h5 id="identifier(name_loc)"><code>identifier(name[, loc])</code></h5> - -<pre>name: string -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomIdentifier/CustomPattern/CustomExpression</p> - -<p>Callback to produce a custom identifier node.</p> - -<h5 id="literal(val_loc)"><code>literal(val[, loc])</code></h5> - -<pre>val: string | boolean | null | number | RegExp -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomLiteral / CustomExpression</p> - -<p>Callback to produce a custom literal node.</p> - -<h5 id="property(kind_key_val_loc)"><code>property(kind, key, val[, loc])</code></h5> - -<pre>kind: "init" | "get" | "set" -key: CustomLiteral | CustomIdentifier -val: CustomExpression -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomObjectProperty</p> - -<p>Callback to produce a custom object property initializer node.</p> - -<h3 id="E4X_2">E4X</h3> - -<h4 id="Declarations">Declarations</h4> - -<h5 id="xmlDefaultDeclaration(ns_loc)"><code>xmlDefaultDeclaration(ns[, loc])</code></h5> - -<pre>loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomDeclaration</p> - -<p>Callback to produce a custom XML default namespace declaration node.</p> - -<h4 id="Expressions">Expressions</h4> - -<h5 id="xmlAnyName(loc)"><code>xmlAnyName([loc])</code></h5> - -<pre>loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXMLAnyName/CustomXML/CustomExpression</p> - -<p>Callback to produce a custom XML node for the wildcard pseudo-identifier <code>*</code>.</p> - -<h5 id="xmlAttributeSelector(expr_loc)"><code>xmlAttributeSelector(expr[, loc])</code></h5> - -<pre>expr: CustomExpression -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXML/CustomExpression</p> - -<p>Callback to produce a custom XML attribute selector node.</p> - -<h5 id="xmlFilterExpression(left_right_loc)"><code>xmlFilterExpression(left, right[, loc])</code></h5> - -<pre>left: CustomExpression -right: CustomExpression -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXML/CustomExpression</p> - -<p>Callback to produce a custom XML filter expression node.</p> - -<h5 id="xmlQualifiedIdentifier(left_right_isComputed_loc)"><code>xmlQualifiedIdentifier(left, right, isComputed[, loc])</code></h5> - -<pre>left: CustomIdentifier | CustomXMLAnyName -right: CustomIdentifier | CustomExpression -isComputed: boolean -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXML/CustomExpression</p> - -<p>Callback to produce a custom qualified identifier node.</p> - -<h5 id="xmlFunctionQualifiedIdentifier(right_isComputed_loc)"><code>xmlFunctionQualifiedIdentifier(right, isComputed[, loc])</code></h5> - -<pre>right: CustomIdentifier | CustomExpression -isComputed: boolean -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXML/CustomExpression</p> - -<p>Callback to produce a custom XML <code>function</code>-qualified identifier node.</p> - -<h5 id="xmlElement(contents_loc)"><code>xmlElement(contents[, loc])</code></h5> - -<pre>contents: [ CustomXML ] -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXML / CustomExpression</p> - -<p>Callback to produce a custom XML element node.</p> - -<h5 id="xmlList(contents_loc)"><code>xmlList(contents[, loc])</code></h5> - -<pre>contents: [ CustomXML ] -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXML/CustomExpression</p> - -<p>Callback to produce a custom XML list node.</p> - -<h4 id="XML_2">XML</h4> - -<h5 id="xmlEscape(expr_loc)"><code>xmlEscape(expr[, loc])</code></h5> - -<pre>expr: CustomExpression -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXML</p> - -<p>Callback to produce a custom XML escape node.</p> - -<h5 id="xmlText(text_loc)"><code>xmlText(text[, loc])</code></h5> - -<pre>text: string -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXML</p> - -<p>Callback to produce a custom XML text node.</p> - -<h5 id="xmlStartTag(contents_loc)"><code>xmlStartTag(contents[, loc])</code></h5> - -<pre>contents: [ CustomXML ] -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXML</p> - -<p>Callback to produce a custom XML start-tag node.</p> - -<h5 id="xmlEndTag(contents_loc)"><code>xmlEndTag(contents[, loc])</code></h5> - -<pre>contents: [ CustomXML ] -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXML</p> - -<p>Callback to produce a custom XML end-tag node.</p> - -<h5 id="xmlPointTag(contents_loc)"><code>xmlPointTag(contents[, loc])</code></h5> - -<pre>contents: [ CustomXML ] -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXML</p> - -<p>Callback to produce a custom XML point tag node.</p> - -<h5 id="xmlName(contents_loc)"><code>xmlName(contents[, loc])</code></h5> - -<pre>contents: string | [ CustomXML ] -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXML</p> - -<p>Callback to produce a custom XML name node.</p> - -<h5 id="xmlAttribute(value_loc)"><code>xmlAttribute(value[, loc])</code></h5> - -<pre>value: string -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXML</p> - -<p>Callback to produce a custom XML attribute node.</p> - -<h5 id="xmlCdata(contents_loc)"><code>xmlCdata(contents[, loc])</code></h5> - -<pre>contents: string -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXML</p> - -<p>Callback to produce a custom XML <code>CDATA</code> node.</p> - -<h5 id="xmlComment(contents_loc)"><code>xmlComment(contents[, loc])</code></h5> - -<pre>contents: string -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXML</p> - -<p>Callback to produce a custom XML comment node.</p> - -<h5 id="xmlProcessingInstruction(target_contents_loc)"><code>xmlProcessingInstruction(target, contents[, loc])</code></h5> - -<pre>target: string -contents: string | null -loc: SourceLocation -</pre> - -<p><strong>返回:</strong> CustomXML</p> - -<p>Callback to produce a custom XML processing instruction node.</p> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/releases/index.html b/files/zh-cn/mozilla/projects/spidermonkey/releases/index.html deleted file mode 100644 index fd88b37529..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/releases/index.html +++ /dev/null @@ -1,42 +0,0 @@ ---- -title: SpiderMonkey releases -slug: Mozilla/Projects/SpiderMonkey/Releases -translation_of: Mozilla/Projects/SpiderMonkey/Releases ---- -<div>{{SpiderMonkeySidebar("Releases")}}</div> - -<div class="summary"> -<p>本页开列了 <a href="/en-US/docs/Mozilla/Projects/SpiderMonkey">SpiderMonkey</a> 的版本记录.</p> -</div> - -<div class="note"> -<p><strong>注意:</strong> 独立的 SpiderMonkey 并不是官方产品. Our continuous integration system does produce a tarball that is built into a binary that runs our smoke tests, but we do not maintain it nor actively test its suitability for general embedding. We have periodically created "releases", but they are best-effort and incomplete. We do happily accept patches, and make some effort to keep the tip of the Gecko tree minimally working as an embeddable source package. We are very limited in our ability to support older versions, including those labeled as "releases" on this page.</p> -</div> - -<p>The easiest way to fetch the version corresponding to the current Firefox release is to visit the <a href="https://treeherder.mozilla.org/#/jobs?repo=mozilla-release&filter-searchStr=spidermonkey-sm-package">treeherder page for the release repository</a> and click on the first SM(pkg) link you see. That will open a small window in the bottom left with a line like "<label>artifact uploaded:</label> <a href="https://queue.taskcluster.net/v1/task/e8X3tKITQTeSFhtdirD7Xg/runs/0/artifacts/public/build/mozjs-57.0.1.tar.bz2" title="artifact uploaded">mozjs-57.0.1.tar.bz2</a>".</p> - -<h2 id="当前版本">当前版本</h2> - -<ul> - <li><a href="/en-US/docs/Mozilla/Projects/SpiderMonkey/Releases/52">SpiderMonkey 52</a></li> -</ul> - -<h2 id="Future_release">Future release</h2> - -<ul> - <li>None</li> -</ul> - -<h2 id="过往版本">过往版本</h2> - -<ul> - <li><a href="/en-US/docs/Mozilla/Projects/SpiderMonkey/Releases/45">SpiderMonkey 45</a></li> - <li><a href="/en-US/docs/Mozilla/Projects/SpiderMonkey/Releases/38">SpiderMonkey 38</a></li> - <li><a href="/en-US/docs/Mozilla/Projects/SpiderMonkey/Releases/31">SpiderMonkey 31</a></li> - <li><a href="/en-US/docs/Mozilla/Projects/SpiderMonkey/Releases/24">SpiderMonkey 24</a></li> - <li><a href="/en-US/docs/Mozilla/Projects/SpiderMonkey/Releases/17">SpiderMonkey 17</a></li> - <li><a href="/en-US/docs/Mozilla/Projects/SpiderMonkey/Releases/1.8.8">SpiderMonkey 1.8.8</a></li> - <li><a href="/en-US/docs/Mozilla/Projects/SpiderMonkey/Releases/1.8.7">SpiderMonkey 1.8.7</a></li> - <li><a href="/en-US/docs/Mozilla/Projects/SpiderMonkey/Releases/1.8.5">SpiderMonkey 1.8.5</a></li> - <li><a href="/en-US/docs/Mozilla/Projects/SpiderMonkey/Releases/1.8">SpiderMonkey 1.8</a></li> -</ul> diff --git a/files/zh-cn/mozilla/projects/spidermonkey/split_object/index.html b/files/zh-cn/mozilla/projects/spidermonkey/split_object/index.html deleted file mode 100644 index 86d82e7d58..0000000000 --- a/files/zh-cn/mozilla/projects/spidermonkey/split_object/index.html +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: Split object -slug: Mozilla/Projects/SpiderMonkey/Split_object -translation_of: Mozilla/Projects/SpiderMonkey/Split_object ---- -<p>In <a href="/en/SpiderMonkey" title="en/SpiderMonkey">SpiderMonkey</a>, a <strong>split object</strong> is made up of two <code><a href="/en/SpiderMonkey/JSAPI_Reference/JSObject" title="en/SpiderMonkey/JSAPI_Reference/JSObject">JSObject</a></code>s: an <strong>inner object</strong> and an <strong>outer object</strong>.</p> - -<p>Each half of a split object always has a pointer to the other half. Inner objects implement the <code><a href="/En/SpiderMonkey/JSAPI_Reference/JSExtendedClass.outerObject" title="En/SpiderMonkey/JSAPI_Reference/JSExtendedClass.outerObject">JSExtendedClass.outerObject</a></code> hook, which returns a pointer to the corresponding outer object. Outer objects implement the <code><a href="/En/SpiderMonkey/JSAPI_Reference/JSExtendedClass.outerObject" title="En/SpiderMonkey/JSAPI_Reference/JSExtendedClass.outerObject">JSExtendedClass.innerObject</a></code> hook. But the association is not fixed. An outer object may be associated with different inner objects at different times.</p> - -<p>This feature is complicated. Programs other than Mozilla that embed SpiderMonkey should avoid using split objects.</p> - -<h2 id="The_window_object" name="The_window_object">The <code>window</code> object</h2> - -<p>Split objects were introduced to resolve a problem posed by the <code><a href="/en/DOM/window" title="en/DOM/window">window</a></code> object. Three interrelated requirements on the <code>window</code> object seemed to conflict.</p> - -<ul> - <li> - <p>The <code>window</code> object is the global object for scripts in Web pages. Firefox has to maintain this for Web compatibility. For performance, access to global properties must be fast.</p> - </li> -</ul> - -<ul> - <li> - <p>There is a glaring difference in the lifetime of the <code>window</code> object as seen from two different angles. Suppose a script in page A, in tab TA, has a reference to the <code>window</code> object of page B in another tab TB. The <code>window</code> object for tab TB must persist as the user navigates from page to page in that tab. To the script in page A, the <code>window</code> must appear to be a single object that moves from page to page. But each web page must load with fresh globals.</p> - - <p>(The problem is even a bit subtler than this, since the reference may be direct or indirect. The script in A might have opened TB by calling <code><a href="/en/DOM/window.open" title="en/DOM/window.open">window.open</a></code>, which returns a direct reference to TB's <code>window</code>. More indirectly, suppose there's a JavaScript function defined in page B that refers to global variables in page B. If page A gets a reference to that function, then by calling it, it is indirectly accessing tab TB's <code>window</code>. The <code>Function</code> object carries a reference to the <code>window</code>, via the scope chain. To further complicate matters, A and B are in the same security domain, so security checks between them automatically succeed. This makes the problem resistant to a wrapper-based approach.)</p> - - <p>Older versions of Firefox accomplished this by blowing away all <code>window</code> properties every time a user navigated to another page, then reusing the <code>window</code>. Each page, even on Back, had to load from scratch. This was slow. Circa Firefox 1.5, the decision was made to cache layout information and JavaScript state across navigation. A new approach for <code>window</code> was needed.</p> - </li> -</ul> - -<ul> - <li> - <p>Security privileges are granted to JS code on the basis of the scope chain of the executing code. SpiderMonkey walks up the scope chain to the nearest object that has <code><a href="/en/SpiderMonkey/JSAPI_Reference/JSPrincipals" title="en/SpiderMonkey/JSAPI_Reference/JSPrincipals">JSPrincipals</a></code> attached. The end of the scope chain is the global object for the script. But what <code>JSPrincipals</code> should be attached to a <code>window</code> object? The principals of the page the window is <em>currently</em> displaying? But then the page that called <code>window.open</code> could use a <code>with</code> statement to inject that <code>window</code> into its scope chain, gaining access to that window's privileges. <em>(Note: <code>with</code> does add an object to the scope chain, but it's a special <code>With</code> wrapper object that is skipped, or something, during the search described here. This security feature is not peculiar to split objects. ...And yet, there is special code in jsobj.h with a comment about fixing some kind of interaction between <code>with</code> an split objects. Write that down, it'll be on the test.)</em></p> - </li> -</ul> - -<p>Split objects were the solution. The inner <code>window</code> object is different for each page a browser window visits. It serves as the "globals" object and provides the <code>JSPrincipals</code> for scripts on that page. Access to inner <code>window</code> properties is fast. The outer <code>window</code> object is the object returned by <code>window.open</code>. It represents the window or tab itself and survives as the user navigates in that window or tab. The <code>window</code> object's <code><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass" title="en/SpiderMonkey/JSAPI_Reference/JSClass">JSClass</a>.resolve</code> hook ensures that properties of the inner object are visible via the outer object, if the running code has the right principals to access them. This privilege check may be slow.</p> - -<p>See {{ interwiki('wikimo', 'Gecko:SplitWindow', 'wikimo:Gecko:SplitWindow') }} and {{ Bug(296639) }} for more discussion.</p> - -<p>See also <a class="external" href="http://groups.google.com/group/mozilla.dev.tech.js-engine/msg/df81825b338fb84f" rel="freelink">http://groups.google.com/group/mozil...81825b338fb84f</a></p> - -<h2 id="Details" name="Details">Details</h2> - -<p>This section describes split objects as a feature of the JSAPI. It catalogues (and tries to explain) the subtle ways in which split objects affect SpiderMonkey's behavior.</p> - -<p>Split objects are only useful for implementing objects that will be on the scope chain of functions. SpiderMonkey assumes that inner and outer objects are dangerous in two different and complementary ways.</p> - -<p>Inner objects are dangerous because they have fast property accessors that do not perform security checks. Therefore, no function may be allowed to see an inner object that has different <code>JSPrincipals</code>. Apart from the security issue, if one page directly or indirectly gets a reference to another page's <code>window</code> object, that <code>window</code> object must appear to behave like the outer window and navigate from page to page. SpiderMonkey arranges this by not allowing JS code to see inner objects at all. To enforce this rule:</p> - -<ul> - <li>If <code>this</code> would evaluate to an inner object, it evaluates to the corresponding outer object instead.</li> -</ul> - -<p>Outer objects are dangerous because their <code>JSPrincipals</code> may change over time. Because a <code>Function</code> inherits the <code>JSPrincipals</code> of its lexical scope (specifically, the nearest principals-aware object in its scope chain), untrusted code must <em>never</em> be able to make an outer object appear in a <code>Function</code>'s scope chain. Again, SpiderMonkey enforces a slightly stronger rule: outer objects may never appear in a scope chain at all, except when put there by an explicit C-level JSAPI call (to <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_SetParent" title="en/SpiderMonkey/JSAPI_Reference/JS_SetParent">JS_SetParent</a></code> or equivalent). (Several objects, such as <code><a href="/en/DOM/window.location" title="en/DOM/window.location">window.location</a></code> and <code><a href="/en/DOM/window.navigator" title="en/DOM/window.navigator">window.navigator</a></code>, are intentionally parented to the outer window object using such APIs.) To enforce this rule:</p> - -<ul> - <li>APIs that allow the caller to pass a scope object always check that object first and fail if any outer objects are on its scope chain.</li> -</ul> - -<ul> - <li>In the spirit of this rule, <code><a href="/en/SpiderMonkey/JSAPI_Reference/JS_GetScopeChain" title="en/SpiderMonkey/JSAPI_Reference/JS_GetScopeChain">JS_GetScopeChain</a></code> should always return an inner object. But there is a special case when <code>JS_GetScopeChain</code> is called on a <code>JSContext</code> in which no code is currently running. By convention, the context's global object is returned in this case. For consistency with the rule, if that global object is an outer object, SpiderMonkey returns the inner object instead.</li> -</ul> - -<p>Inner and outer objects are in certain other respects the same object:</p> - -<ul> - <li>If <code><a href="/en/JavaScript/Reference/Global_Objects/Object/hasOwnProperty" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Object/hasOwnProperty">Object.hasOwnProperty</a></code> is called on an inner object, and the named property is found on an outer object, that's considered close enough and <code>hasOwnProperty</code> returns <code>true</code>.</li> -</ul> - -<p>Note that none of the rules listed here affects ordinary property accesses. SpiderMonkey's split object support, by itself, does not cause inner object properties to appear on the outer object or vice versa. Split objects that need this behavior must implement it in custom <code><a href="/en/SpiderMonkey/JSAPI_Reference/JSClass" title="en/SpiderMonkey/JSAPI_Reference/JSClass">JSClass</a></code> hooks. In the case of <code>window</code>, each half has custom hooks.</p> |
