mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 934557 - Handlify JS::ToBoolean and remove JS_ValueToBoolean. r=terrence
This commit is contained in:
parent
b4bf92d782
commit
8f66a758c7
@ -522,14 +522,14 @@ DeterministicGC(JSContext *cx, unsigned argc, jsval *vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
if (argc != 1) {
|
||||
if (args.length() != 1) {
|
||||
RootedObject callee(cx, &args.callee());
|
||||
ReportUsageError(cx, callee, "Wrong number of arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
gc::SetDeterministicGC(cx, ToBoolean(vp[2]));
|
||||
*vp = JSVAL_VOID;
|
||||
gc::SetDeterministicGC(cx, ToBoolean(args[0]));
|
||||
args.rval().setUndefined();
|
||||
return true;
|
||||
}
|
||||
#endif /* JS_GC_ZEAL */
|
||||
|
@ -2645,10 +2645,7 @@ ExplicitConvert(JSContext* cx, HandleValue val, HandleObject targetType, void* b
|
||||
|
||||
switch (type) {
|
||||
case TYPE_bool: {
|
||||
// Convert according to the ECMAScript ToBoolean() function.
|
||||
bool result;
|
||||
ASSERT_OK(JS_ValueToBoolean(cx, val, &result));
|
||||
*static_cast<bool*>(buffer) = result != false;
|
||||
*static_cast<bool*>(buffer) = ToBoolean(val);
|
||||
break;
|
||||
}
|
||||
#define DEFINE_INT_TYPE(name, type, ffiType) \
|
||||
|
@ -2410,7 +2410,7 @@ class FunctionCompiler
|
||||
MBasicBlock *body;
|
||||
if (!newBlock(curBlock_, &body, bodyPn))
|
||||
return false;
|
||||
if (cond->isConstant() && ToBoolean(cond->toConstant()->value())) {
|
||||
if (cond->isConstant() && cond->toConstant()->valueToBoolean()) {
|
||||
*afterLoop = nullptr;
|
||||
curBlock_->end(MGoto::New(body));
|
||||
} else {
|
||||
@ -2468,7 +2468,7 @@ class FunctionCompiler
|
||||
if (curBlock_) {
|
||||
JS_ASSERT(curBlock_->loopDepth() == loopStack_.length() + 1);
|
||||
if (cond->isConstant()) {
|
||||
if (ToBoolean(cond->toConstant()->value())) {
|
||||
if (cond->toConstant()->valueToBoolean()) {
|
||||
curBlock_->end(MGoto::New(loopEntry));
|
||||
if (!loopEntry->setBackedgeAsmJS(curBlock_))
|
||||
return false;
|
||||
|
@ -657,13 +657,13 @@ LIRGenerator::visitTest(MTest *test)
|
||||
|
||||
// Constant Double operand.
|
||||
if (opd->type() == MIRType_Double && opd->isConstant()) {
|
||||
bool result = ToBoolean(opd->toConstant()->value());
|
||||
bool result = opd->toConstant()->valueToBoolean();
|
||||
return add(new LGoto(result ? ifTrue : ifFalse));
|
||||
}
|
||||
|
||||
// Constant Float32 operand.
|
||||
if (opd->type() == MIRType_Float32 && opd->isConstant()) {
|
||||
bool result = ToBoolean(opd->toConstant()->value());
|
||||
bool result = opd->toConstant()->valueToBoolean();
|
||||
return add(new LGoto(result ? ifTrue : ifFalse));
|
||||
}
|
||||
|
||||
|
@ -2459,12 +2459,12 @@ MNot::foldsTo(bool useValueNumbers)
|
||||
{
|
||||
// Fold if the input is constant
|
||||
if (operand()->isConstant()) {
|
||||
const Value &v = operand()->toConstant()->value();
|
||||
bool result = operand()->toConstant()->valueToBoolean();
|
||||
if (type() == MIRType_Int32)
|
||||
return MConstant::New(Int32Value(!ToBoolean(v)));
|
||||
return MConstant::New(Int32Value(!result));
|
||||
|
||||
// ToBoolean can cause no side effects, so this is safe.
|
||||
return MConstant::New(BooleanValue(!ToBoolean(v)));
|
||||
// ToBoolean can't cause side effects, so this is safe.
|
||||
return MConstant::New(BooleanValue(!result));
|
||||
}
|
||||
|
||||
// NOT of an undefined or null value is always true
|
||||
|
@ -969,6 +969,10 @@ class MConstant : public MNullaryInstruction
|
||||
const js::Value *vp() const {
|
||||
return &value_;
|
||||
}
|
||||
const bool valueToBoolean() const {
|
||||
// A hack to avoid this wordy pattern everywhere in the JIT.
|
||||
return ToBoolean(HandleValue::fromMarkedLocation(&value_));
|
||||
}
|
||||
|
||||
void printOpcode(FILE *fp) const;
|
||||
|
||||
|
@ -123,8 +123,7 @@ UnreachableCodeElimination::optimizableSuccessor(MBasicBlock *block)
|
||||
if (!v->isConstant())
|
||||
return nullptr;
|
||||
|
||||
const Value &val = v->toConstant()->value();
|
||||
BranchDirection bdir = ToBoolean(val) ? TRUE_BRANCH : FALSE_BRANCH;
|
||||
BranchDirection bdir = v->toConstant()->valueToBoolean() ? TRUE_BRANCH : FALSE_BRANCH;
|
||||
return testIns->branchSuccessor(bdir);
|
||||
}
|
||||
|
||||
|
@ -242,7 +242,7 @@ JS_ConvertArgumentsVA(JSContext *cx, unsigned argc, jsval *argv, const char *for
|
||||
RootedValue arg(cx, *sp);
|
||||
switch (c) {
|
||||
case 'b':
|
||||
*va_arg(ap, bool *) = ToBoolean(*sp);
|
||||
*va_arg(ap, bool *) = ToBoolean(arg);
|
||||
break;
|
||||
case 'c':
|
||||
if (!ToUint16(cx, arg, va_arg(ap, uint16_t *)))
|
||||
@ -444,16 +444,6 @@ JS_DoubleToUint32(double d)
|
||||
return ToUint32(d);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(bool)
|
||||
JS_ValueToBoolean(JSContext *cx, jsval value, bool *bp)
|
||||
{
|
||||
AssertHeapIsIdle(cx);
|
||||
CHECK_REQUEST(cx);
|
||||
assertSameCompartment(cx, value);
|
||||
*bp = ToBoolean(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSType)
|
||||
JS_TypeOfValue(JSContext *cx, jsval valueArg)
|
||||
{
|
||||
|
@ -1056,7 +1056,7 @@ ToNumberSlow(JSContext *cx, JS::Value v, double *dp);
|
||||
* DO NOT CALL THIS. Use JS::ToBoolean
|
||||
*/
|
||||
extern JS_PUBLIC_API(bool)
|
||||
ToBooleanSlow(const JS::Value &v);
|
||||
ToBooleanSlow(JS::HandleValue v);
|
||||
} /* namespace js */
|
||||
|
||||
namespace JS {
|
||||
@ -1079,7 +1079,7 @@ ToNumber(JSContext *cx, Handle<Value> v, double *out)
|
||||
}
|
||||
|
||||
JS_ALWAYS_INLINE bool
|
||||
ToBoolean(const Value &v)
|
||||
ToBoolean(HandleValue v)
|
||||
{
|
||||
if (v.isBoolean())
|
||||
return v.toBoolean();
|
||||
@ -1203,9 +1203,6 @@ ToUint64(JSContext *cx, JS::Handle<JS::Value> v, uint64_t *out)
|
||||
|
||||
} /* namespace JS */
|
||||
|
||||
extern JS_PUBLIC_API(bool)
|
||||
JS_ValueToBoolean(JSContext *cx, jsval v, bool *bp);
|
||||
|
||||
extern JS_PUBLIC_API(JSType)
|
||||
JS_TypeOfValue(JSContext *cx, jsval v);
|
||||
|
||||
|
@ -182,7 +182,7 @@ js_BooleanToString(ExclusiveContext *cx, bool b)
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(bool)
|
||||
js::ToBooleanSlow(const Value &v)
|
||||
js::ToBooleanSlow(HandleValue v)
|
||||
{
|
||||
if (v.isString())
|
||||
return v.toString()->length() != 0;
|
||||
|
@ -692,7 +692,7 @@ IndicatePropertyNotFound(MutableHandle<PropertyDescriptor> desc)
|
||||
}
|
||||
|
||||
static bool
|
||||
ValueToBool(const Value &v, bool *bp)
|
||||
ValueToBool(HandleValue v, bool *bp)
|
||||
{
|
||||
*bp = ToBoolean(v);
|
||||
return true;
|
||||
|
@ -917,36 +917,24 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
|
||||
if (!JS_GetProperty(cx, opts, "newContext", &v))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
bool b;
|
||||
if (!JS_ValueToBoolean(cx, v, &b))
|
||||
return false;
|
||||
newContext = b;
|
||||
}
|
||||
if (!v.isUndefined())
|
||||
newContext = ToBoolean(v);
|
||||
|
||||
if (!JS_GetProperty(cx, opts, "compileAndGo", &v))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
bool b;
|
||||
if (!JS_ValueToBoolean(cx, v, &b))
|
||||
return false;
|
||||
compileAndGo = b;
|
||||
}
|
||||
if (!v.isUndefined())
|
||||
compileAndGo = ToBoolean(v);
|
||||
|
||||
if (!JS_GetProperty(cx, opts, "noScriptRval", &v))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
bool b;
|
||||
if (!JS_ValueToBoolean(cx, v, &b))
|
||||
return false;
|
||||
noScriptRval = b;
|
||||
}
|
||||
if (!v.isUndefined())
|
||||
noScriptRval = ToBoolean(v);
|
||||
|
||||
if (!JS_GetProperty(cx, opts, "fileName", &v))
|
||||
return false;
|
||||
if (JSVAL_IS_NULL(v)) {
|
||||
if (v.isNull()) {
|
||||
fileName = nullptr;
|
||||
} else if (!JSVAL_IS_VOID(v)) {
|
||||
} else if (!v.isUndefined()) {
|
||||
JSString *s = JS_ValueToString(cx, v);
|
||||
if (!s)
|
||||
return false;
|
||||
@ -957,12 +945,12 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
|
||||
if (!JS_GetProperty(cx, opts, "element", &v))
|
||||
return false;
|
||||
if (!JSVAL_IS_PRIMITIVE(v))
|
||||
element = JSVAL_TO_OBJECT(v);
|
||||
if (v.isObject())
|
||||
element = &v.toObject();
|
||||
|
||||
if (!JS_GetProperty(cx, opts, "sourceURL", &v))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
if (!v.isUndefined()) {
|
||||
sourceURL = JS_ValueToString(cx, v);
|
||||
if (!sourceURL)
|
||||
return false;
|
||||
@ -970,7 +958,7 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
|
||||
if (!JS_GetProperty(cx, opts, "sourceMapURL", &v))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
if (!v.isUndefined()) {
|
||||
sourceMapURL = JS_ValueToString(cx, v);
|
||||
if (!sourceMapURL)
|
||||
return false;
|
||||
@ -978,7 +966,7 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
|
||||
if (!JS_GetProperty(cx, opts, "lineNumber", &v))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
if (!v.isUndefined()) {
|
||||
uint32_t u;
|
||||
if (!ToUint32(cx, v, &u))
|
||||
return false;
|
||||
@ -987,10 +975,9 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
|
||||
if (!JS_GetProperty(cx, opts, "global", &v))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
global = JSVAL_IS_PRIMITIVE(v) ? nullptr : JSVAL_TO_OBJECT(v);
|
||||
if (global) {
|
||||
global = js::UncheckedUnwrap(global);
|
||||
if (!v.isUndefined()) {
|
||||
if (v.isObject()) {
|
||||
global = js::UncheckedUnwrap(&v.toObject());
|
||||
if (!global)
|
||||
return false;
|
||||
}
|
||||
@ -1003,25 +990,17 @@ Evaluate(JSContext *cx, unsigned argc, jsval *vp)
|
||||
|
||||
if (!JS_GetProperty(cx, opts, "catchTermination", &v))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
bool b;
|
||||
if (!JS_ValueToBoolean(cx, v, &b))
|
||||
return false;
|
||||
catchTermination = b;
|
||||
}
|
||||
if (!v.isUndefined())
|
||||
catchTermination = ToBoolean(v);
|
||||
|
||||
if (!JS_GetProperty(cx, opts, "saveFrameChain", &v))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
bool b;
|
||||
if (!JS_ValueToBoolean(cx, v, &b))
|
||||
return false;
|
||||
saveFrameChain = b;
|
||||
}
|
||||
if (!v.isUndefined())
|
||||
saveFrameChain = ToBoolean(v);
|
||||
|
||||
if (!JS_GetProperty(cx, opts, "sourcePolicy", &v))
|
||||
return false;
|
||||
if (!JSVAL_IS_VOID(v)) {
|
||||
if (!v.isUndefined()) {
|
||||
JSString *s = JS_ValueToString(cx, v);
|
||||
if (!s)
|
||||
return false;
|
||||
@ -2454,13 +2433,14 @@ static bool
|
||||
sandbox_enumerate(JSContext *cx, HandleObject obj)
|
||||
{
|
||||
RootedValue v(cx);
|
||||
bool b;
|
||||
|
||||
if (!JS_GetProperty(cx, obj, "lazy", &v))
|
||||
return false;
|
||||
|
||||
JS_ValueToBoolean(cx, v, &b);
|
||||
return !b || JS_EnumerateStandardClasses(cx, obj);
|
||||
if (!ToBoolean(v))
|
||||
return true;
|
||||
|
||||
return JS_EnumerateStandardClasses(cx, obj);
|
||||
}
|
||||
|
||||
static bool
|
||||
@ -2468,13 +2448,11 @@ sandbox_resolve(JSContext *cx, HandleObject obj, HandleId id, unsigned flags,
|
||||
MutableHandleObject objp)
|
||||
{
|
||||
RootedValue v(cx);
|
||||
bool b, resolved;
|
||||
|
||||
if (!JS_GetProperty(cx, obj, "lazy", &v))
|
||||
return false;
|
||||
|
||||
JS_ValueToBoolean(cx, v, &b);
|
||||
if (b) {
|
||||
if (ToBoolean(v)) {
|
||||
bool resolved;
|
||||
if (!JS_ResolveStandardClass(cx, obj, id, &resolved))
|
||||
return false;
|
||||
if (resolved) {
|
||||
|
@ -73,7 +73,7 @@ static bool
|
||||
#endif
|
||||
ToBooleanOp(const FrameRegs ®s)
|
||||
{
|
||||
return ToBoolean(regs.sp[-1]);
|
||||
return ToBoolean(regs.stackHandleAt(-1));
|
||||
}
|
||||
|
||||
template <bool Eq>
|
||||
|
@ -282,9 +282,7 @@ def write_getter(a, iface, fd):
|
||||
if realtype.count("JS::Value"):
|
||||
fd.write(" aDict.%s = v;\n" % a.name)
|
||||
elif realtype.count("bool"):
|
||||
fd.write(" bool b;\n")
|
||||
fd.write(" MOZ_ALWAYS_TRUE(JS_ValueToBoolean(aCx, v, &b));\n")
|
||||
fd.write(" aDict.%s = b;\n" % a.name)
|
||||
fd.write(" aDict.%s = JS::ToBoolean(v);\n" % a.name)
|
||||
elif realtype.count("uint16_t"):
|
||||
fd.write(" uint32_t u;\n")
|
||||
fd.write(" NS_ENSURE_STATE(JS::ToUint32(aCx, v, &u));\n")
|
||||
|
@ -433,8 +433,7 @@ argumentUnboxingTemplates = {
|
||||
" return false;\n",
|
||||
|
||||
'boolean':
|
||||
" bool ${name};\n"
|
||||
" JS_ValueToBoolean(cx, ${argVal}, &${name});\n",
|
||||
" bool ${name} = JS::ToBoolean(${argVal});\n",
|
||||
|
||||
'[astring]':
|
||||
" xpc_qsAString ${name}(cx, ${argVal}, ${argPtr}, ${notPassed});\n"
|
||||
|
Loading…
Reference in New Issue
Block a user