Commit 02fe0141 authored by oliver@apple.com's avatar oliver@apple.com

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:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154902 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f043dce1
2013-08-30 Oliver Hunt <oliver@apple.com>
Make JSValue bool conversion less dangerous
https://bugs.webkit.org/show_bug.cgi?id=120505
Reviewed by Darin Adler.
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)
2013-08-30 Chris Curtis <chris_curtis@apple.com>
Cleaning errorDescriptionForValue after r154839
......
......@@ -677,7 +677,7 @@ EncodedJSValue DFG_OPERATION operationInOptimizeWithReturnAddress(ExecState* exe
if (!base->isObject()) {
vm->throwException(exec, createInvalidParameterError(exec, "in", base));
return jsUndefined();
return JSValue::encode(jsUndefined());
}
StructureStubInfo& stubInfo = exec->codeBlock()->getStubInfo(returnAddress);
......@@ -704,7 +704,7 @@ EncodedJSValue DFG_OPERATION operationIn(ExecState* exec, JSCell* base, StringIm
if (!base->isObject()) {
vm->throwException(exec, createInvalidParameterError(exec, "in", base));
return jsUndefined();
return JSValue::encode(jsUndefined());
}
Identifier ident(vm, key);
......
......@@ -75,7 +75,7 @@ namespace JSC {
}
JSValue exception() const { return vm().exception(); }
bool hadException() const { return vm().exception(); }
bool hadException() const { return !vm().exception().isEmpty(); }
const CommonIdentifiers& propertyNames() const { return *vm().propertyNames; }
const MarkedArgumentBuffer& emptyList() const { return *vm().emptyList; }
......
......@@ -173,7 +173,8 @@ public:
explicit JSValue(long long);
explicit JSValue(unsigned long long);
operator bool() const;
typedef void* (JSValue::*UnspecifiedBoolType);
operator UnspecifiedBoolType*() const;
bool operator==(const JSValue& other) const;
bool operator!=(const JSValue& other) const;
......
......@@ -210,10 +210,10 @@ inline JSValue::JSValue(const JSCell* ptr)
u.asBits.payload = reinterpret_cast<int32_t>(const_cast<JSCell*>(ptr));
}
inline JSValue::operator bool() const
inline JSValue::operator UnspecifiedBoolType*() const
{
ASSERT(tag() != DeletedValueTag);
return tag() != EmptyValueTag;
return tag() != EmptyValueTag ? reinterpret_cast<UnspecifiedBoolType*>(1) : 0;
}
inline bool JSValue::operator==(const JSValue& other) const
......@@ -358,9 +358,9 @@ inline JSValue::JSValue(const JSCell* ptr)
u.asInt64 = reinterpret_cast<uintptr_t>(const_cast<JSCell*>(ptr));
}
inline JSValue::operator bool() const
inline JSValue::operator UnspecifiedBoolType*() const
{
return u.asInt64;
return u.asInt64 ? reinterpret_cast<UnspecifiedBoolType*>(1) : 0;
}
inline bool JSValue::operator==(const JSValue& other) const
......
......@@ -519,7 +519,7 @@ EncodedJSValue JSC_HOST_CALL globalFuncEval(ExecState* exec)
JSGlobalObject* calleeGlobalObject = exec->callee()->globalObject();
EvalExecutable* eval = EvalExecutable::create(exec, makeSource(s), false);
if (!eval)
return jsUndefined();
return JSValue::encode(jsUndefined());
return JSValue::encode(exec->interpreter()->execute(eval, exec, calleeGlobalObject->globalThis(), calleeGlobalObject));
}
......
......@@ -183,9 +183,9 @@ bool sameValue(ExecState* exec, JSValue a, JSValue b)
bool PropertyDescriptor::equalTo(ExecState* exec, const PropertyDescriptor& other) const
{
if (!other.m_value == m_value ||
!other.m_getter == m_getter ||
!other.m_setter == m_setter)
if (other.m_value.isEmpty() != m_value.isEmpty()
|| other.m_getter.isEmpty() != m_getter.isEmpty()
|| other.m_setter.isEmpty() != m_setter.isEmpty())
return false;
return (!m_value || sameValue(exec, other.m_value, m_value))
&& (!m_getter || JSValue::strictEqual(exec, other.m_getter, m_getter))
......
2013-08-30 Oliver Hunt <oliver@apple.com>
Make JSValue bool conversion less dangerous
https://bugs.webkit.org/show_bug.cgi?id=120505
Reviewed by Darin Adler.
Make LIKELY and UNLIKELY macros coerce to bool before
passing to expect.
* wtf/Compiler.h:
2013-08-30 Antti Koivisto <antti@apple.com>
Remove code behind ENABLE(DIALOG_ELEMENT)
......
......@@ -223,7 +223,7 @@
#ifndef UNLIKELY
#if COMPILER(GCC) || (COMPILER(RVCT) && defined(__GNUC__))
#define UNLIKELY(x) __builtin_expect((x), 0)
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
#else
#define UNLIKELY(x) (x)
#endif
......@@ -234,7 +234,7 @@
#ifndef LIKELY
#if COMPILER(GCC) || (COMPILER(RVCT) && defined(__GNUC__))
#define LIKELY(x) __builtin_expect((x), 1)
#define LIKELY(x) __builtin_expect(!!(x), 1)
#else
#define LIKELY(x) (x)
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment