Bug 966518 - Part 0: Make proxy callability into a trap, rather than a class check. (r=bholley, r=djvj, r=peterv)

This commit is contained in:
Eric Faust
2014-09-10 15:52:36 -07:00
parent fab6cd5350
commit a75e6b2b4b
38 changed files with 346 additions and 138 deletions

View File

@@ -3794,6 +3794,14 @@ js::FindClassObject(ExclusiveContext *cx, MutableHandleObject protop, const Clas
return true;
}
bool
JSObject::isCallable() const
{
if (is<JSFunction>())
return true;
return callHook() != nullptr;
}
bool
JSObject::isConstructor() const
{
@@ -3801,7 +3809,39 @@ JSObject::isConstructor() const
const JSFunction &fun = as<JSFunction>();
return fun.isNativeConstructor() || fun.isInterpretedConstructor();
}
return getClass()->construct != nullptr;
return constructHook() != nullptr;
}
JSNative
JSObject::callHook() const
{
const js::Class *clasp = getClass();
if (clasp->call)
return clasp->call;
if (is<js::ProxyObject>()) {
const js::ProxyObject &p = as<js::ProxyObject>();
if (p.handler()->isCallable(const_cast<JSObject*>(this)))
return js::proxy_Call;
}
return nullptr;
}
JSNative
JSObject::constructHook() const
{
const js::Class *clasp = getClass();
if (clasp->construct)
return clasp->construct;
if (is<js::ProxyObject>()) {
const js::ProxyObject &p = as<js::ProxyObject>();
if (p.handler()->isConstructor(const_cast<JSObject*>(this)))
return js::proxy_Construct;
}
return nullptr;
}
/* static */ bool