mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1270746 part 1 - Remove hasInstance hook from CType objects. r=iain
We can instead rely on the default behavior for `instanceof` in `JS::OrdinaryHasInstance`. This works because these objects are callable (since the JSClass has a call-hook) and they have a `.prototype` property that returns the value in the proto slot. Differential Revision: https://phabricator.services.mozilla.com/D141342
This commit is contained in:
parent
cbcd1dc469
commit
6dc57e36ea
@ -155,8 +155,6 @@ bool PtrGetter(JSContext* cx, const JS::CallArgs& args);
|
||||
static bool CreateArray(JSContext* cx, unsigned argc, Value* vp);
|
||||
static bool ToString(JSContext* cx, unsigned argc, Value* vp);
|
||||
static bool ToSource(JSContext* cx, unsigned argc, Value* vp);
|
||||
static bool HasInstance(JSContext* cx, HandleObject obj, MutableHandleValue v,
|
||||
bool* bp);
|
||||
|
||||
/*
|
||||
* Get the global "ctypes" object.
|
||||
@ -487,7 +485,7 @@ static const JSClassOps sCTypeClassOps = {
|
||||
nullptr, // mayResolve
|
||||
CType::Finalize, // finalize
|
||||
CType::ConstructData, // call
|
||||
CType::HasInstance, // hasInstance
|
||||
nullptr, // hasInstance
|
||||
CType::ConstructData, // construct
|
||||
CType::Trace, // trace
|
||||
};
|
||||
@ -4929,36 +4927,6 @@ bool CType::ToSource(JSContext* cx, unsigned argc, Value* vp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CType::HasInstance(JSContext* cx, HandleObject obj, MutableHandleValue v,
|
||||
bool* bp) {
|
||||
MOZ_ASSERT(CType::IsCType(obj));
|
||||
|
||||
Value slot = JS::GetReservedSlot(obj, SLOT_PROTO);
|
||||
JS::Rooted<JSObject*> prototype(cx, &slot.toObject());
|
||||
MOZ_ASSERT(prototype);
|
||||
MOZ_ASSERT(CData::IsCDataProto(prototype));
|
||||
|
||||
*bp = false;
|
||||
if (v.isPrimitive()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
RootedObject proto(cx, &v.toObject());
|
||||
for (;;) {
|
||||
if (!JS_GetPrototype(cx, proto, &proto)) {
|
||||
return false;
|
||||
}
|
||||
if (!proto) {
|
||||
break;
|
||||
}
|
||||
if (proto == prototype) {
|
||||
*bp = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static JSObject* CType::GetGlobalCTypes(JSContext* cx, JSObject* objArg) {
|
||||
MOZ_ASSERT(CType::IsCType(objArg));
|
||||
|
||||
|
@ -2168,6 +2168,10 @@ function run_type_ctor_class_tests(
|
||||
Assert.ok(d.__proto__ === t.prototype);
|
||||
Assert.ok(d instanceof t);
|
||||
Assert.ok(d.constructor === t);
|
||||
// Other objects that are not instances of 't'.
|
||||
Assert.equal({} instanceof t, false);
|
||||
Assert.equal(t.__proto__ instanceof t, false);
|
||||
Assert.equal(t.prototype instanceof t, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user