Ignore:
Timestamp:
Aug 30, 2013, 11:30:41 AM (12 years ago)
Author:
[email protected]
Message:

Make JSValue bool conversion less dangerous
https://bugs.webkit.org/show_bug.cgi?id=120505

Reviewed by Darin Adler.

Source/JavaScriptCore:

Replaces JSValue::operator bool() with a operator UnspecifiedBoolType* as
we do elsewhere. Then fix the places where terrible type coercion was
happening. All of the changes made had no fundamental behavioural impact
as they were coercion results that were ignored (returning undefined
after an exception).

  • dfg/DFGOperations.cpp:
  • interpreter/CallFrame.h:

(JSC::ExecState::hadException):

  • runtime/JSCJSValue.h:
  • runtime/JSCJSValueInlines.h:

(JSC::JSValue::operator UnspecifiedBoolType*):

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::globalFuncEval):

  • runtime/PropertyDescriptor.cpp:

(JSC::PropertyDescriptor::equalTo)

Source/WTF:

Make LIKELY and UNLIKELY macros coerce to bool before
passing to expect.

  • wtf/Compiler.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSCJSValueInlines.h

    r154038 r154902  
    211211}
    212212
    213 inline JSValue::operator bool() const
     213inline JSValue::operator UnspecifiedBoolType*() const
    214214{
    215215    ASSERT(tag() != DeletedValueTag);
    216     return tag() != EmptyValueTag;
     216    return tag() != EmptyValueTag ? reinterpret_cast<UnspecifiedBoolType*>(1) : 0;
    217217}
    218218
     
    359359}
    360360
    361 inline JSValue::operator bool() const
    362 {
    363     return u.asInt64;
     361inline JSValue::operator UnspecifiedBoolType*() const
     362{
     363    return u.asInt64 ? reinterpret_cast<UnspecifiedBoolType*>(1) : 0;
    364364}
    365365
Note: See TracChangeset for help on using the changeset viewer.