Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

JS EvaluateScript

このテンプレートは廃止されています。使用しないで下さい。

スクリプトのコンパイルおよび実行を行います。 Compile and execute a script.

構文

JSBool JS_EvaluateScript(JSContext *cx, JSObject *obj,
    const char *src, uintN length, const char *filename,
    uintN lineno, jsval *rval);

JSBool JS_EvaluateUCScript(JSContext *cx, JSObject *obj,
    const jschar *src, uintN length, const char *filename,
    uintN lineno, jsval *rval);
Name Type Description
cx JSContext * スクリプトを実行するコンテキストThe context in which to run the script. リクエストが必要。 (JS_THREADSAFE ビルドでは、呼び出し側はこの JSContext 上のリクエストでなければなりません。)
obj JSObject * スクリプトと関連付けるオブジェクトObject with which the script is associated.
src const char * or const jschar * コンパイル・実行対象となるスクリプト文字列String containing the script to compile and execute.
length size_t srcの文字列長The length of <code>src</code>, in characters.
filename const char * エラーメッセージ出力に利用されるスクリプトのファイル名またはそのURLを示す文字列。Name of file or URL containing the script. Used to report filename or URL in error messages.
lineno uintN エラー発生時に出力される行数Line number. Used to report the offending line in the file or URL if an error occurs.
rval jsval * 実行結果の出力先。実行に成功したとき、*rvalにはスクリプトの最終行の実行結果の値が格納されます。Out parameter. On success, <code>*rval</code> receives the value of the last-executed expression statement processed in the script.

説明

JS_EvaluateScriptは、オブジェクトobjに結合する形でスクリプトをコンパイル・実行する関数です。実行が成功したとき、rvalにスクリプトの最終行の実行結果の値へのポインタが格納されています。この関数のUnicode版として、JS_EvaluateUCScriptが用意されています。 <code>JS_EvaluateScript</code> compiles and executes a script associated with a JS object, <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.

srcはスクリプト文字列、lengthはその文字列の長さをそれぞれ引数として取ります。 <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.

filenameはスクリプトの位置を示すファイル名またはURLを引数として取ります。ここで指定した情報は、コンパイルエラーが発生したときのエラーメッセージに利用されます。linenoも同様にエラーメッセージとして出力される行番号として利用されます。 <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.

スクリプトのコンパイルと実行が成功したとき、JS_EvaluateScriptおよびJS_EvaluateUCScriptJS_TRUEを、失敗したときはJS_FALSEをそれぞれ返します。コンパイル・実行に失敗したとき、*rvalの値は未定義とみなす必要があります。 If a script compiles and executes successfully, <code>JS_EvaluateScript</code> or <code>JS_EvaluateUCScript</code> returns <code>JS_TRUE</code>. Otherwise it returns <code>JS_FALSE</code>. On failure, your application should assume that <code>*rval</code> is undefined.

関連項目

MXR ID で JS_EvaluateScript
MXR ID で JS_EvaluateUCScript

JS_CompileFile, JS_CompileScript, JS_DecompileScript, JS_DestroyScript, JS_EvaluateScriptForPrincipals, JS_ExecuteScript

ドキュメントのタグと貢献者

 このページの貢献者: Norihiro
 最終更新者: Norihiro,