Bug 1167313 - Simplify UbiNode::construct dispatch using CallTyped; r=jimb

--HG--
extra : rebase_source : 880f5856665bea34ba27913d9b6b533bd9cdd1a4
This commit is contained in:
Terrence Cole 2015-05-21 11:41:18 -07:00
parent 86a4d4c6d4
commit ae93611ac6
2 changed files with 7 additions and 21 deletions

View File

@ -271,6 +271,7 @@ class Node {
"ubi::Base specializations must be the same size as ubi::Base");
Concrete<T>::construct(base(), ptr);
}
struct ConstructFunctor;
public:
Node() { construct<void>(nullptr); }

View File

@ -58,33 +58,18 @@ Concrete<void>::size(mozilla::MallocSizeOf mallocSizeof) const
MOZ_CRASH("null ubi::Node");
}
struct Node::ConstructFunctor : public BoolDefaultAdaptor<Value, false> {
template <typename T> bool operator()(T* t, Node* node) { node->construct(t); return true; }
};
Node::Node(JSGCTraceKind kind, void* ptr)
{
switch (kind) {
case JSTRACE_OBJECT: construct(static_cast<JSObject*>(ptr)); break;
case JSTRACE_SCRIPT: construct(static_cast<JSScript*>(ptr)); break;
case JSTRACE_STRING: construct(static_cast<JSString*>(ptr)); break;
case JSTRACE_SYMBOL: construct(static_cast<JS::Symbol*>(ptr)); break;
case JSTRACE_BASE_SHAPE: construct(static_cast<js::BaseShape*>(ptr)); break;
case JSTRACE_JITCODE: construct(static_cast<js::jit::JitCode*>(ptr)); break;
case JSTRACE_LAZY_SCRIPT: construct(static_cast<js::LazyScript*>(ptr)); break;
case JSTRACE_SHAPE: construct(static_cast<js::Shape*>(ptr)); break;
case JSTRACE_OBJECT_GROUP: construct(static_cast<js::ObjectGroup*>(ptr)); break;
default:
MOZ_CRASH("bad JSGCTraceKind passed to JS::ubi::Node::Node");
}
CallTyped(ConstructFunctor(), ptr, kind, this);
}
Node::Node(HandleValue value)
{
if (value.isObject())
construct(&value.toObject());
else if (value.isString())
construct(value.toString());
else if (value.isSymbol())
construct(value.toSymbol());
else
if (!DispatchValueTyped(ConstructFunctor(), value, this))
construct<void>(nullptr);
}