mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 637572 - Allow the element on which a script was defined to be passed as compile option; r=jimb
This commit is contained in:
parent
18607d69fb
commit
cdbfe5204f
@ -5292,6 +5292,7 @@ JS::CompileOptions::CompileOptions(JSContext *cx)
|
||||
filename(NULL),
|
||||
lineno(1),
|
||||
column(0),
|
||||
element(NullPtr()),
|
||||
compileAndGo(cx->hasOption(JSOPTION_COMPILE_N_GO)),
|
||||
forEval(false),
|
||||
noScriptRval(cx->hasOption(JSOPTION_NO_SCRIPT_RVAL)),
|
||||
|
@ -3895,6 +3895,7 @@ struct JS_PUBLIC_API(CompileOptions) {
|
||||
const char *filename;
|
||||
unsigned lineno;
|
||||
unsigned column;
|
||||
HandleObject element;
|
||||
bool compileAndGo;
|
||||
bool forEval;
|
||||
bool noScriptRval;
|
||||
@ -3915,6 +3916,7 @@ struct JS_PUBLIC_API(CompileOptions) {
|
||||
filename = f; lineno = l; return *this;
|
||||
}
|
||||
CompileOptions &setColumn(unsigned c) { column = c; return *this; }
|
||||
CompileOptions &setElement(HandleObject e) { element = e; return *this; }
|
||||
CompileOptions &setCompileAndGo(bool cng) { compileAndGo = cng; return *this; }
|
||||
CompileOptions &setForEval(bool eval) { forEval = eval; return *this; }
|
||||
CompileOptions &setNoScriptRval(bool nsr) { noScriptRval = nsr; return *this; }
|
||||
|
@ -1,5 +1,4 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- * vim: set ts=8 sts=4 et sw=4 tw=99:
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
@ -927,6 +926,7 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
bool compileAndGo = true;
|
||||
bool noScriptRval = false;
|
||||
const char *fileName = "@evaluate";
|
||||
RootedObject element(cx);
|
||||
JSAutoByteString fileNameBytes;
|
||||
RootedString sourceMapURL(cx);
|
||||
unsigned lineNumber = 1;
|
||||
@ -940,10 +940,10 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
return false;
|
||||
|
||||
if (args.length() == 2) {
|
||||
RootedObject options(cx, &args[1].toObject());
|
||||
RootedObject opts(cx, &args[1].toObject());
|
||||
RootedValue v(cx);
|
||||
|
||||
if (!JS_GetProperty(cx, options, "newContext", v.address()))
|
||||
if (!JS_GetProperty(cx, opts, "newContext", v.address()))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
JSBool b;
|
||||
@ -952,7 +952,7 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
newContext = b;
|
||||
}
|
||||
|
||||
if (!JS_GetProperty(cx, options, "compileAndGo", v.address()))
|
||||
if (!JS_GetProperty(cx, opts, "compileAndGo", v.address()))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
JSBool b;
|
||||
@ -961,7 +961,7 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
compileAndGo = b;
|
||||
}
|
||||
|
||||
if (!JS_GetProperty(cx, options, "noScriptRval", v.address()))
|
||||
if (!JS_GetProperty(cx, opts, "noScriptRval", v.address()))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
JSBool b;
|
||||
@ -970,7 +970,7 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
noScriptRval = b;
|
||||
}
|
||||
|
||||
if (!JS_GetProperty(cx, options, "fileName", v.address()))
|
||||
if (!JS_GetProperty(cx, opts, "fileName", v.address()))
|
||||
return false;
|
||||
if (JSVAL_IS_NULL(v)) {
|
||||
fileName = NULL;
|
||||
@ -983,7 +983,12 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!JS_GetProperty(cx, options, "sourceMapURL", v.address()))
|
||||
if (!JS_GetProperty(cx, opts, "element", v.address()))
|
||||
return false;
|
||||
if (!JSVAL_IS_PRIMITIVE(v))
|
||||
element = JSVAL_TO_OBJECT(v);
|
||||
|
||||
if (!JS_GetProperty(cx, opts, "sourceMapURL", v.address()))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
sourceMapURL = JS_ValueToString(cx, v);
|
||||
@ -991,7 +996,7 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!JS_GetProperty(cx, options, "lineNumber", v.address()))
|
||||
if (!JS_GetProperty(cx, opts, "lineNumber", v.address()))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
uint32_t u;
|
||||
@ -1000,7 +1005,7 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
lineNumber = u;
|
||||
}
|
||||
|
||||
if (!JS_GetProperty(cx, options, "global", v.address()))
|
||||
if (!JS_GetProperty(cx, opts, "global", v.address()))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
global = JSVAL_IS_PRIMITIVE(v) ? NULL : JSVAL_TO_OBJECT(v);
|
||||
@ -1016,7 +1021,7 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
}
|
||||
}
|
||||
|
||||
if (!JS_GetProperty(cx, options, "catchTermination", v.address()))
|
||||
if (!JS_GetProperty(cx, opts, "catchTermination", v.address()))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
JSBool b;
|
||||
@ -1025,7 +1030,7 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
catchTermination = b;
|
||||
}
|
||||
|
||||
if (!JS_GetProperty(cx, options, "saveFrameChain", v.address()))
|
||||
if (!JS_GetProperty(cx, opts, "saveFrameChain", v.address()))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
JSBool b;
|
||||
@ -1055,16 +1060,19 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
|
||||
{
|
||||
JSAutoCompartment ac(cx, global);
|
||||
uint32_t saved = JS_GetOptions(cx);
|
||||
uint32_t options = saved & ~(JSOPTION_COMPILE_N_GO | JSOPTION_NO_SCRIPT_RVAL);
|
||||
uint32_t oldopts = JS_GetOptions(cx);
|
||||
uint32_t opts = oldopts & ~(JSOPTION_COMPILE_N_GO | JSOPTION_NO_SCRIPT_RVAL);
|
||||
if (compileAndGo)
|
||||
options |= JSOPTION_COMPILE_N_GO;
|
||||
opts |= JSOPTION_COMPILE_N_GO;
|
||||
if (noScriptRval)
|
||||
options |= JSOPTION_NO_SCRIPT_RVAL;
|
||||
opts |= JSOPTION_NO_SCRIPT_RVAL;
|
||||
|
||||
JS_SetOptions(cx, options);
|
||||
RootedScript script(cx, JS_CompileUCScript(cx, global, codeChars, codeLength, fileName, lineNumber));
|
||||
JS_SetOptions(cx, saved);
|
||||
JS_SetOptions(cx, opts);
|
||||
CompileOptions options(cx);
|
||||
options.setFileAndLine(fileName, lineNumber);
|
||||
options.setElement(element);
|
||||
RootedScript script(cx, JS::Compile(cx, global, options, codeChars, codeLength));
|
||||
JS_SetOptions(cx, oldopts);
|
||||
if (!script)
|
||||
return false;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user