Bug 880330 - Refactor jsd to use the new options API; r=sphink

This commit is contained in:
Eddy Bruel 2013-10-28 12:52:27 +01:00
Родитель 1ed81b38c5
Коммит 088abb9836
1 изменённых файлов: 49 добавлений и 9 удалений

Просмотреть файл

@ -1574,7 +1574,7 @@ jsdContext::FromPtr (JSDContext *aJSDCx, JSContext *aJSCx)
else
{
nsCOMPtr<nsISupports> iscx;
if (JS_GetOptions(aJSCx) & JSOPTION_PRIVATE_IS_NSISUPPORTS)
if (JS::ContextOptionsRef(aJSCx).privateIsNSISupports())
iscx = static_cast<nsISupports *>(JS_GetContextPrivate(aJSCx));
jsdicx = new jsdContext (aJSDCx, aJSCx, iscx);
}
@ -1636,11 +1636,41 @@ jsdContext::GetJSContext(JSContext **_rval)
return NS_OK;
}
/* Simulate the old options API in terms of the new one for backwards
* compatibility */
#define JSOPTION_EXTRA_WARNINGS JS_BIT(0)
#define JSOPTION_WERROR JS_BIT(1)
#define JSOPTION_VAROBJFIX JS_BIT(2)
#define JSOPTION_PRIVATE_IS_NSISUPPORTS JS_BIT(3)
#define JSOPTION_COMPILE_N_GO JS_BIT(4)
#define JSOPTION_DONT_REPORT_UNCAUGHT JS_BIT(8)
#define JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT JS_BIT(11)
#define JSOPTION_NO_SCRIPT_RVAL JS_BIT(12)
#define JSOPTION_BASELINE JS_BIT(14)
#define JSOPTION_TYPE_INFERENCE JS_BIT(16)
#define JSOPTION_STRICT_MODE JS_BIT(17)
#define JSOPTION_ION JS_BIT(18)
#define JSOPTION_ASMJS JS_BIT(19)
#define JSOPTION_MASK JS_BITMASK(20)
NS_IMETHODIMP
jsdContext::GetOptions(uint32_t *_rval)
{
ASSERT_VALID_EPHEMERAL;
*_rval = JS_GetOptions(mJSCx);
*_rval = (JS::ContextOptionsRef(mJSCx).extraWarnings() ? JSOPTION_EXTRA_WARNINGS : 0)
| (JS::ContextOptionsRef(mJSCx).werror() ? JSOPTION_WERROR : 0)
| (JS::ContextOptionsRef(mJSCx).varObjFix() ? JSOPTION_VAROBJFIX : 0)
| (JS::ContextOptionsRef(mJSCx).privateIsNSISupports() ? JSOPTION_PRIVATE_IS_NSISUPPORTS : 0)
| (JS::ContextOptionsRef(mJSCx).compileAndGo() ? JSOPTION_COMPILE_N_GO : 0)
| (JS::ContextOptionsRef(mJSCx).dontReportUncaught() ? JSOPTION_DONT_REPORT_UNCAUGHT : 0)
| (JS::ContextOptionsRef(mJSCx).noDefaultCompartmentObject() ? JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT : 0)
| (JS::ContextOptionsRef(mJSCx).noScriptRval() ? JSOPTION_NO_SCRIPT_RVAL : 0)
| (JS::ContextOptionsRef(mJSCx).baseline() ? JSOPTION_BASELINE : 0)
| (JS::ContextOptionsRef(mJSCx).typeInference() ? JSOPTION_TYPE_INFERENCE : 0)
| (JS::ContextOptionsRef(mJSCx).strictMode() ? JSOPTION_STRICT_MODE : 0)
| (JS::ContextOptionsRef(mJSCx).ion() ? JSOPTION_ION : 0)
| (JS::ContextOptionsRef(mJSCx).asmJS() ? JSOPTION_ASMJS : 0);
return NS_OK;
}
@ -1648,14 +1678,25 @@ NS_IMETHODIMP
jsdContext::SetOptions(uint32_t options)
{
ASSERT_VALID_EPHEMERAL;
uint32_t lastOptions = JS_GetOptions(mJSCx);
/* don't let users change this option, they'd just be shooting themselves
* in the foot. */
if ((options ^ lastOptions) & JSOPTION_PRIVATE_IS_NSISUPPORTS)
if (JS::ContextOptionsRef(mJSCx).privateIsNSISupports() !=
(options & JSOPTION_PRIVATE_IS_NSISUPPORTS))
return NS_ERROR_ILLEGAL_VALUE;
JS_SetOptions(mJSCx, options);
JS::ContextOptionsRef(mJSCx).setExtraWarnings(options & JSOPTION_EXTRA_WARNINGS)
.setWerror(options & JSOPTION_WERROR)
.setVarObjFix(options & JSOPTION_VAROBJFIX)
.setCompileAndGo(options & JSOPTION_COMPILE_N_GO)
.setDontReportUncaught(options & JSOPTION_DONT_REPORT_UNCAUGHT)
.setNoDefaultCompartmentObject(options & JSOPTION_NO_DEFAULT_COMPARTMENT_OBJECT)
.setNoScriptRval(options & JSOPTION_NO_SCRIPT_RVAL)
.setBaseline(options & JSOPTION_BASELINE)
.setTypeInference(options & JSOPTION_TYPE_INFERENCE)
.setStrictMode(options & JSOPTION_STRICT_MODE)
.setIon(options & JSOPTION_ION)
.setAsmJS(options & JSOPTION_ASMJS);
return NS_OK;
}
@ -1663,8 +1704,7 @@ NS_IMETHODIMP
jsdContext::GetPrivateData(nsISupports **_rval)
{
ASSERT_VALID_EPHEMERAL;
uint32_t options = JS_GetOptions(mJSCx);
if (options & JSOPTION_PRIVATE_IS_NSISUPPORTS)
if (JS::ContextOptionsRef(mJSCx).privateIsNSISupports())
{
*_rval = static_cast<nsISupports*>(JS_GetContextPrivate(mJSCx));
NS_IF_ADDREF(*_rval);
@ -1673,10 +1713,10 @@ jsdContext::GetPrivateData(nsISupports **_rval)
{
*_rval = nullptr;
}
return NS_OK;
}
NS_IMETHODIMP
jsdContext::GetWrappedContext(nsISupports **_rval)
{