aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_newruntime
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_newruntime')
-rw-r--r--files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_newruntime/index.html33
1 files changed, 33 insertions, 0 deletions
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
new file mode 100644
index 0000000000..885bb3dd6e
--- /dev/null
+++ b/files/zh-cn/mozilla/projects/spidermonkey/jsapi_reference/js_newruntime/index.html
@@ -0,0 +1,33 @@
+---
+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>