Visit Mozilla.org

JS SetOptions

From MDC

Enables and disables options on a JSContext, replacing all previously set options.

[edit] Syntax

uint32 JS_SetOptions(JSContext *cx, uint32 options);
Name Type Description
cx JSContext * A context on which to set options.
options uint32 The new set of options. This is the logical OR of zero or more flags described below.

[edit] Description

JS_SetOptions sets the option flags of a given JS context cx. This function returns a uint32 value containing the previous values of the flags.

To turn individual options on or off, use JS_SetOptions with JS_GetOptions:

// turn on strict mode
JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_STRICT);

// turn off strict mode
JS_SetOptions(cx, JS_GetOptions(cx) & ~JSOPTION_STRICT);

The options parameter and the return value are the logical OR of zero or more constants from the following table:

Option Description

JSOPTION_STRICT

Warn on dubious practice.

LXR ID Search for JSOPTION_STRICT

JSOPTION_WERROR

Convert warnings to errors.

LXR ID Search for JSOPTION_WERROR

JSOPTION_VAROBJFIX

Make JS_EvaluateScript() use the last object on its obj param's scope chain as the ECMA "variables object".

LXR ID Search for JSOPTION_VAROBJFIX

JSOPTION_PRIVATE_IS_NSISUPPORTS

Mozilla extension. The context's private data points to an XPCOM object (see nsISupports). This is only meaningful if SpiderMonkey is built with XPConnect.

LXR ID Search for JSOPTION_PRIVATE_IS_NSISUPPORTS

JSOPTION_COMPILE_N_GO

Caller of JS_CompileScript et al promises to execute the compiled script once only. This enables compile-time scope chain resolution of consts (a performance optimization).

LXR ID Search for JSOPTION_COMPILE_N_GO

JSOPTION_ATLINE

//@line number ["filename"] option supported for the XUL preprocessor and kindred beasts.

LXR ID Search for JSOPTION_ATLINE

JSOPTION_XML

ECMAScript for XML (E4X) support: parse <!-- --> as a token, not backward compatible with the comment-hiding hack used in HTML script tags.

LXR ID Search for JSOPTION_XML

JSOPTION_NATIVE_BRANCH_CALLBACK

The branch callback set by JS_SetBranchCallback may be called with a null script parameter, by native code that loops intensively.

LXR ID Search for JSOPTION_NATIVE_BRANCH_CALLBACK

JSOPTION_DONT_REPORT_UNCAUGHT

When returning from the outermost API call, prevent uncaught exceptions from being converted to error reports.

LXR ID Search for JSOPTION_DONT_REPORT_UNCAUGHT

LXR ID Search for JS_SetOptions