Bug 922283 - Remove the self hosted class mechanism, r=shu.

This commit is contained in:
Brian Hackett 2013-10-02 08:16:04 -06:00
parent 78f7c8c9ac
commit 0c0243ace6
7 changed files with 0 additions and 210 deletions

View File

@ -1,37 +0,0 @@
var NewClassPrototype = getSelfHostedValue("NewClassPrototype");
var NewObjectWithClassPrototype = getSelfHostedValue("NewObjectWithClassPrototype");
var HaveSameClass = getSelfHostedValue("HaveSameClass");
var UnsafeGetReservedSlot = getSelfHostedValue("UnsafeGetReservedSlot");
var UnsafeSetReservedSlot = getSelfHostedValue("UnsafeSetReservedSlot");
var numSlots = 5;
var C = NewClassPrototype(numSlots);
C.getSlots = function getSlots() {
if (!HaveSameClass(this, C))
throw TypeError("bad class");
var slots = [];
for (var i = 0; i < numSlots; i++)
slots.push(UnsafeGetReservedSlot(this, i));
return slots;
};
C.setSlots = function setSlots(slots) {
if (!HaveSameClass(this, C))
throw TypeError("bad class");
for (var i = 0; i < numSlots; i++)
UnsafeSetReservedSlot(this, i, slots[i]);
};
function f() {
var obj = NewObjectWithClassPrototype(C);
var before = ["foo", 2.22, ["bar", "baz"], { x: 0, y: -1.1 }, false];
obj.setSlots(before);
var after = obj.getSlots();
assertEq(before.length, after.length);
for (var i = 0; i < before.length; i++)
assertEq(before[i], after[i]);
}
f();

View File

@ -586,7 +586,6 @@ class IonBuilder : public MIRGenerator
// Utility intrinsics.
InliningStatus inlineIsCallable(CallInfo &callInfo);
InliningStatus inlineNewObjectWithClassPrototype(CallInfo &callInfo);
InliningStatus inlineHaveSameClass(CallInfo &callInfo);
InliningStatus inlineToObject(CallInfo &callInfo);
InliningStatus inlineDump(CallInfo &callInfo);

View File

@ -140,8 +140,6 @@ IonBuilder::inlineNativeCall(CallInfo &callInfo, JSNative native)
// Utility intrinsics.
if (native == intrinsic_IsCallable)
return inlineIsCallable(callInfo);
if (native == intrinsic_NewObjectWithClassPrototype)
return inlineNewObjectWithClassPrototype(callInfo);
if (native == intrinsic_HaveSameClass)
return inlineHaveSameClass(callInfo);
if (native == intrinsic_ToObject)
@ -1454,34 +1452,6 @@ IonBuilder::inlineUnsafeGetReservedSlot(CallInfo &callInfo)
return InliningStatus_Inlined;
}
IonBuilder::InliningStatus
IonBuilder::inlineNewObjectWithClassPrototype(CallInfo &callInfo)
{
if (callInfo.argc() != 1 || callInfo.constructing())
return InliningStatus_NotInlined;
if (callInfo.getArg(0)->type() != MIRType_Object)
return InliningStatus_NotInlined;
MDefinition *arg = callInfo.getArg(0)->toPassArg()->getArgument();
if (!arg->isConstant())
return InliningStatus_NotInlined;
JSObject *proto = &arg->toConstant()->value().toObject();
JSObject *templateObject = NewObjectWithGivenProto(cx, proto->getClass(), proto, cx->global());
if (!templateObject)
return InliningStatus_Error;
MNewObject *newObj = MNewObject::New(templateObject,
/* templateObjectIsClassPrototype = */ true);
current->add(newObj);
current->push(newObj);
if (!resumeAfter(newObj))
return InliningStatus_Error;
return InliningStatus_Inlined;
}
IonBuilder::InliningStatus
IonBuilder::inlineHaveSameClass(CallInfo &callInfo)
{

View File

@ -998,7 +998,6 @@ bool intrinsic_NewDenseArray(JSContext *cx, unsigned argc, Value *vp);
bool intrinsic_UnsafePutElements(JSContext *cx, unsigned argc, Value *vp);
bool intrinsic_UnsafeSetReservedSlot(JSContext *cx, unsigned argc, Value *vp);
bool intrinsic_UnsafeGetReservedSlot(JSContext *cx, unsigned argc, Value *vp);
bool intrinsic_NewObjectWithClassPrototype(JSContext *cx, unsigned argc, Value *vp);
bool intrinsic_HaveSameClass(JSContext *cx, unsigned argc, Value *vp);
bool intrinsic_ShouldForceSequential(JSContext *cx, unsigned argc, Value *vp);

View File

@ -139,7 +139,6 @@ JSRuntime::JSRuntime(JSUseHelperThreads useHelperThreads)
bumpAlloc_(nullptr),
ionRuntime_(nullptr),
selfHostingGlobal_(nullptr),
selfHostedClasses_(nullptr),
nativeStackBase(0),
cxCallback(nullptr),
destroyCompartmentCallback(nullptr),

View File

@ -676,7 +676,6 @@ typedef Vector<JS::Zone *, 4, SystemAllocPolicy> ZoneVector;
class AutoLockForExclusiveAccess;
class AutoPauseWorkersForGC;
struct SelfHostedClass;
class ThreadDataIter;
void RecomputeStackLimit(JSRuntime *rt, StackKind kind);
@ -860,7 +859,6 @@ struct JSRuntime : public JS::shadow::Runtime,
js::jit::IonRuntime *ionRuntime_;
JSObject *selfHostingGlobal_;
js::SelfHostedClass *selfHostedClasses_;
/* Space for interpreter frames. */
js::InterpreterStack interpreterStack_;
@ -906,10 +904,6 @@ struct JSRuntime : public JS::shadow::Runtime,
bool isSelfHostingGlobal(js::HandleObject global) {
return global == selfHostingGlobal_;
}
js::SelfHostedClass *selfHostedClasses() {
return selfHostedClasses_;
}
void addSelfHostedClass(js::SelfHostedClass *shClass);
bool cloneSelfHostedFunctionScript(JSContext *cx, js::Handle<js::PropertyName*> name,
js::Handle<JSFunction*> targetFun);
bool cloneSelfHostedValue(JSContext *cx, js::Handle<js::PropertyName*> name,

View File

@ -26,78 +26,6 @@
using namespace js;
using namespace js::selfhosted;
namespace js {
/*
* A linked-list container for self-hosted prototypes that have need of a
* Class for reserved slots. These are freed when self-hosting is destroyed at
* the destruction of the last context.
*/
struct SelfHostedClass
{
/* Next class in the list. */
SelfHostedClass *next;
/* Class of instances. */
Class class_;
/*
* Create a new self-hosted proto with its class set to a new dynamically
* allocated class with numSlots reserved slots.
*/
static JSObject *newPrototype(JSContext *cx, uint32_t numSlots);
static bool is(JSContext *cx, const Class *clasp);
SelfHostedClass(const char *name, uint32_t numSlots);
};
} /* namespace js */
JSObject *
SelfHostedClass::newPrototype(JSContext *cx, uint32_t numSlots)
{
/* Allocate a new self hosted class and prepend it to the list. */
SelfHostedClass *shClass = cx->new_<SelfHostedClass>("Self-hosted Class", numSlots);
if (!shClass)
return nullptr;
cx->runtime()->addSelfHostedClass(shClass);
Rooted<GlobalObject *> global(cx, cx->global());
RootedObject proto(cx, global->createBlankPrototype(cx, &shClass->class_));
if (!proto)
return nullptr;
return proto;
}
bool
SelfHostedClass::is(JSContext *cx, const Class *clasp)
{
SelfHostedClass *shClass = cx->runtime()->selfHostedClasses();
while (shClass) {
if (clasp == &shClass->class_)
return true;
shClass = shClass->next;
}
return false;
}
SelfHostedClass::SelfHostedClass(const char *name, uint32_t numSlots)
{
mozilla::PodZero(this);
class_.name = name;
class_.flags = JSCLASS_HAS_RESERVED_SLOTS(numSlots);
class_.addProperty = JS_PropertyStub;
class_.delProperty = JS_DeletePropertyStub;
class_.getProperty = JS_PropertyStub;
class_.setProperty = JS_StrictPropertyStub;
class_.enumerate = JS_EnumerateStub;
class_.resolve = JS_ResolveStub;
class_.convert = JS_ConvertStub;
}
static void
selfHosting_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
{
@ -515,37 +443,6 @@ js::intrinsic_UnsafeGetReservedSlot(JSContext *cx, unsigned argc, Value *vp)
return true;
}
static bool
intrinsic_NewClassPrototype(JSContext *cx, unsigned argc, Value *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
JS_ASSERT(args.length() == 1);
JS_ASSERT(args[0].isInt32());
JSObject *proto = SelfHostedClass::newPrototype(cx, args[0].toPrivateUint32());
if (!proto)
return false;
args.rval().setObject(*proto);
return true;
}
bool
js::intrinsic_NewObjectWithClassPrototype(JSContext *cx, unsigned argc, Value *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
JS_ASSERT(args.length() == 1);
JS_ASSERT(args[0].isObject());
RootedObject proto(cx, &args[0].toObject());
JSObject *result = NewObjectWithGivenProto(cx, proto->getClass(), proto, cx->global());
if (!result)
return false;
args.rval().setObject(*result);
return true;
}
bool
js::intrinsic_HaveSameClass(JSContext *cx, unsigned argc, Value *vp)
{
@ -634,9 +531,6 @@ const JSFunctionSpec intrinsic_functions[] = {
JS_FN("UnsafePutElements", intrinsic_UnsafePutElements, 3,0),
JS_FN("UnsafeSetReservedSlot", intrinsic_UnsafeSetReservedSlot, 3,0),
JS_FN("UnsafeGetReservedSlot", intrinsic_UnsafeGetReservedSlot, 2,0),
JS_FN("NewClassPrototype", intrinsic_NewClassPrototype, 1,0),
JS_FN("NewObjectWithClassPrototype", intrinsic_NewObjectWithClassPrototype, 1,0),
JS_FN("HaveSameClass", intrinsic_HaveSameClass, 2,0),
JS_FN("ForkJoin", intrinsic_ForkJoin, 2,0),
@ -770,14 +664,6 @@ void
JSRuntime::finishSelfHosting()
{
selfHostingGlobal_ = nullptr;
SelfHostedClass *shClass = selfHostedClasses_;
while (shClass) {
SelfHostedClass *tmp = shClass;
shClass = shClass->next;
js_delete(tmp);
}
selfHostedClasses_ = nullptr;
}
void
@ -787,13 +673,6 @@ JSRuntime::markSelfHostingGlobal(JSTracer *trc)
MarkObjectRoot(trc, &selfHostingGlobal_, "self-hosting global");
}
void
JSRuntime::addSelfHostedClass(SelfHostedClass *shClass)
{
shClass->next = selfHostedClasses_;
selfHostedClasses_ = shClass;
}
typedef AutoObjectObjectHashMap CloneMemory;
static bool CloneValue(JSContext *cx, MutableHandleValue vp, CloneMemory &clonedObjects);
@ -825,19 +704,6 @@ CloneProperties(JSContext *cx, HandleObject obj, HandleObject clone, CloneMemory
}
}
if (SelfHostedClass::is(cx, obj->getClass())) {
for (uint32_t i = 0; i < JSCLASS_RESERVED_SLOTS(obj->getClass()); i++) {
val = obj->getReservedSlot(i);
if (!CloneValue(cx, &val, clonedObjects))
return false;
clone->setReservedSlot(i, val);
}
/* Privates are not cloned, so be careful! */
if (obj->hasPrivate())
clone->setPrivate(obj->getPrivate());
}
return true;
}