mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Address bug 684507 review comments, r=luke.
This commit is contained in:
parent
e4d3f5339b
commit
4124a56c30
@ -3905,12 +3905,10 @@ NewArray(JSContext *cx, jsuint length, JSObject *proto)
|
||||
if (!shape)
|
||||
return NULL;
|
||||
|
||||
JSObject* obj = js_NewGCObject(cx, kind);
|
||||
JSObject* obj = JSObject::createDenseArray(cx, kind, shape, type, length);
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
obj->initializeDenseArray(shape, type, length);
|
||||
|
||||
if (entry != -1)
|
||||
cache.fillGlobal(entry, &ArrayClass, parent, kind, obj);
|
||||
|
||||
|
@ -157,10 +157,9 @@ ArgumentsObject::create(JSContext *cx, uint32 argc, JSObject &callee, StackFrame
|
||||
/* We have everything needed to fill in the object, so make the object. */
|
||||
JS_STATIC_ASSERT(NormalArgumentsObject::RESERVED_SLOTS == 3);
|
||||
JS_STATIC_ASSERT(StrictArgumentsObject::RESERVED_SLOTS == 3);
|
||||
JSObject *obj = js_NewGCObject(cx, FINALIZE_OBJECT4);
|
||||
JSObject *obj = JSObject::create(cx, FINALIZE_OBJECT4, emptyArgumentsShape, type, NULL);
|
||||
if (!obj)
|
||||
return NULL;
|
||||
obj->initialize(emptyArgumentsShape, type, NULL);
|
||||
|
||||
ArgumentsObject *argsobj = obj->asArguments();
|
||||
|
||||
@ -712,10 +711,9 @@ NewDeclEnvObject(JSContext *cx, StackFrame *fp)
|
||||
if (!emptyDeclEnvShape)
|
||||
return NULL;
|
||||
|
||||
JSObject *envobj = js_NewGCObject(cx, FINALIZE_OBJECT2);
|
||||
JSObject *envobj = JSObject::create(cx, FINALIZE_OBJECT2, emptyDeclEnvShape, type, NULL);
|
||||
if (!envobj)
|
||||
return NULL;
|
||||
envobj->initialize(emptyDeclEnvShape, type, NULL);
|
||||
envobj->setPrivate(fp);
|
||||
|
||||
if (!envobj->setInternalScopeChain(cx, &fp->scopeChain()))
|
||||
|
@ -420,12 +420,10 @@ NewIteratorObject(JSContext *cx, uintN flags)
|
||||
if (!emptyEnumeratorShape)
|
||||
return NULL;
|
||||
|
||||
JSObject *obj = js_NewGCObject(cx, FINALIZE_OBJECT2);
|
||||
JSObject *obj = JSObject::create(cx, FINALIZE_OBJECT2, emptyEnumeratorShape, type, NULL);
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
obj->initialize(emptyEnumeratorShape, type, NULL);
|
||||
|
||||
JS_ASSERT(obj->numFixedSlots() == JSObject::ITER_CLASS_NFIXED_SLOTS);
|
||||
return obj;
|
||||
}
|
||||
|
@ -2922,15 +2922,13 @@ NewObject(JSContext *cx, Class *clasp, types::TypeObject *type, JSObject *parent
|
||||
return NULL;
|
||||
|
||||
HeapValue *slots;
|
||||
if (!ReserveObjectDynamicSlots(cx, shape, &slots))
|
||||
if (!PreallocateObjectDynamicSlots(cx, shape, &slots))
|
||||
return NULL;
|
||||
|
||||
JSObject* obj = js_NewGCObject(cx, kind);
|
||||
JSObject* obj = JSObject::create(cx, kind, shape, type, slots);
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
obj->initialize(shape, type, slots);
|
||||
|
||||
Probes::createObject(cx, obj);
|
||||
return obj;
|
||||
}
|
||||
@ -3616,10 +3614,9 @@ js_NewWithObject(JSContext *cx, JSObject *proto, JSObject *parent, jsint depth)
|
||||
if (!emptyWithShape)
|
||||
return NULL;
|
||||
|
||||
obj = js_NewGCObject(cx, FINALIZE_OBJECT4);
|
||||
obj = JSObject::create(cx, FINALIZE_OBJECT4, emptyWithShape, type, NULL);
|
||||
if (!obj)
|
||||
return NULL;
|
||||
obj->initialize(emptyWithShape, type, NULL);
|
||||
OBJ_SET_BLOCK_DEPTH(cx, obj, depth);
|
||||
|
||||
if (!obj->setInternalScopeChain(cx, parent))
|
||||
@ -3649,12 +3646,7 @@ js_NewBlockObject(JSContext *cx)
|
||||
if (!emptyBlockShape)
|
||||
return NULL;
|
||||
|
||||
JSObject *blockObj = js_NewGCObject(cx, FINALIZE_OBJECT4);
|
||||
if (!blockObj)
|
||||
return NULL;
|
||||
blockObj->initialize(emptyBlockShape, type, NULL);
|
||||
|
||||
return blockObj;
|
||||
return JSObject::create(cx, FINALIZE_OBJECT4, emptyBlockShape, type, NULL);
|
||||
}
|
||||
|
||||
static const uint32 BLOCK_RESERVED_SLOTS = 2;
|
||||
@ -3669,15 +3661,13 @@ js_CloneBlockObject(JSContext *cx, JSObject *proto, StackFrame *fp)
|
||||
return NULL;
|
||||
|
||||
HeapValue *slots;
|
||||
if (!ReserveObjectDynamicSlots(cx, proto->lastProperty(), &slots))
|
||||
if (!PreallocateObjectDynamicSlots(cx, proto->lastProperty(), &slots))
|
||||
return NULL;
|
||||
|
||||
JSObject *clone = js_NewGCObject(cx, FINALIZE_OBJECT4);
|
||||
JSObject *clone = JSObject::create(cx, FINALIZE_OBJECT4, proto->lastProperty(), type, slots);
|
||||
if (!clone)
|
||||
return NULL;
|
||||
|
||||
clone->initialize(proto->lastProperty(), type, slots);
|
||||
|
||||
StackFrame *priv = js_FloatingFrameIfGenerator(cx, fp);
|
||||
|
||||
/* Set the parent if necessary, as for call objects. */
|
||||
|
@ -504,11 +504,19 @@ struct JSObject : js::gc::Cell
|
||||
/* As above, but does not change the slot span. */
|
||||
inline void setLastPropertyInfallible(const js::Shape *shape);
|
||||
|
||||
/* Set the initial state of a newborn object. */
|
||||
inline void initialize(js::Shape *shape, js::types::TypeObject *type, js::HeapValue *slots);
|
||||
/* Make a non-array object with the specified initial state. */
|
||||
static inline JSObject *create(JSContext *cx,
|
||||
js::gc::AllocKind kind,
|
||||
js::Shape *shape,
|
||||
js::types::TypeObject *type,
|
||||
js::HeapValue *slots);
|
||||
|
||||
/* Set the initial state of a newborn dense array. */
|
||||
inline void initializeDenseArray(js::Shape *shape, js::types::TypeObject *type, uint32 length);
|
||||
/* Make a dense array object with the specified initial state. */
|
||||
static inline JSObject *createDenseArray(JSContext *cx,
|
||||
js::gc::AllocKind kind,
|
||||
js::Shape *shape,
|
||||
js::types::TypeObject *type,
|
||||
uint32 length);
|
||||
|
||||
/*
|
||||
* Remove the last property of an object, provided that it is safe to do so
|
||||
|
@ -1031,8 +1031,9 @@ JSObject::initializeSlotRange(size_t start, size_t length)
|
||||
}
|
||||
}
|
||||
|
||||
inline void
|
||||
JSObject::initialize(js::Shape *shape, js::types::TypeObject *type, js::HeapValue *slots)
|
||||
/* static */ inline JSObject *
|
||||
JSObject::create(JSContext *cx, js::gc::AllocKind kind,
|
||||
js::Shape *shape, js::types::TypeObject *type, js::HeapValue *slots)
|
||||
{
|
||||
/*
|
||||
* Callers must use dynamicSlotsCount to size the initial slot array of the
|
||||
@ -1041,36 +1042,48 @@ JSObject::initialize(js::Shape *shape, js::types::TypeObject *type, js::HeapValu
|
||||
*/
|
||||
JS_ASSERT(shape && type);
|
||||
JS_ASSERT(!!dynamicSlotsCount(shape->numFixedSlots(), shape->slotSpan()) == !!slots);
|
||||
JS_ASSERT(js::gc::GetGCKindSlots(getAllocKind(), shape->getObjectClass()) == shape->numFixedSlots());
|
||||
JS_ASSERT(js::gc::GetGCKindSlots(kind, shape->getObjectClass()) == shape->numFixedSlots());
|
||||
|
||||
this->shape_.init(shape);
|
||||
this->type_.init(type);
|
||||
this->slots = slots;
|
||||
this->elements = js::emptyObjectElements;
|
||||
JSObject *obj = js_NewGCObject(cx, kind);
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
obj->shape_.init(shape);
|
||||
obj->type_.init(type);
|
||||
obj->slots = slots;
|
||||
obj->elements = js::emptyObjectElements;
|
||||
|
||||
if (shape->getObjectClass()->hasPrivate())
|
||||
setPrivate(NULL);
|
||||
obj->setPrivate(NULL);
|
||||
|
||||
size_t span = shape->slotSpan();
|
||||
if (span)
|
||||
initializeSlotRange(0, span);
|
||||
if (size_t span = shape->slotSpan())
|
||||
obj->initializeSlotRange(0, span);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
inline void
|
||||
JSObject::initializeDenseArray(js::Shape *shape, js::types::TypeObject *type, uint32 length)
|
||||
/* static */ inline JSObject *
|
||||
JSObject::createDenseArray(JSContext *cx, js::gc::AllocKind kind,
|
||||
js::Shape *shape, js::types::TypeObject *type, uint32 length)
|
||||
{
|
||||
JS_ASSERT(shape && type);
|
||||
JS_ASSERT(shape->getObjectClass() == &js::ArrayClass);
|
||||
JS_ASSERT(js::gc::GetGCKindSlots(getAllocKind(), shape->getObjectClass()) == shape->numFixedSlots());
|
||||
JS_ASSERT(js::gc::GetGCKindSlots(kind, shape->getObjectClass()) == shape->numFixedSlots());
|
||||
|
||||
JS_STATIC_ASSERT(sizeof(js::ObjectElements) == 2 * sizeof(js::Value));
|
||||
JS_ASSERT(shape->numFixedSlots() >= 2);
|
||||
|
||||
this->shape_.init(shape);
|
||||
this->type_.init(type);
|
||||
this->slots = NULL;
|
||||
setFixedElements();
|
||||
new (getElementsHeader()) js::ObjectElements(shape->numFixedSlots() - 2, length);
|
||||
JSObject *obj = js_NewGCObject(cx, kind);
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
obj->shape_.init(shape);
|
||||
obj->type_.init(type);
|
||||
obj->slots = NULL;
|
||||
obj->setFixedElements();
|
||||
new (obj->getElementsHeader()) js::ObjectElements(shape->numFixedSlots() - 2, length);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
inline void
|
||||
@ -1825,13 +1838,12 @@ NewObjectGCKind(JSContext *cx, js::Class *clasp)
|
||||
|
||||
/*
|
||||
* Fill slots with the initial slot array to use for a newborn object which
|
||||
* may need dynamic slots.
|
||||
* may or may not need dynamic slots.
|
||||
*/
|
||||
inline bool
|
||||
ReserveObjectDynamicSlots(JSContext *cx, Shape *shape, HeapValue **slots)
|
||||
PreallocateObjectDynamicSlots(JSContext *cx, Shape *shape, HeapValue **slots)
|
||||
{
|
||||
size_t count = JSObject::dynamicSlotsCount(shape->numFixedSlots(), shape->slotSpan());
|
||||
if (count) {
|
||||
if (size_t count = JSObject::dynamicSlotsCount(shape->numFixedSlots(), shape->slotSpan())) {
|
||||
*slots = (HeapValue *) cx->malloc_(count * sizeof(HeapValue));
|
||||
if (!*slots)
|
||||
return false;
|
||||
|
@ -62,15 +62,13 @@ CallObject::create(JSContext *cx, JSScript *script, JSObject &scopeChain, JSObje
|
||||
return NULL;
|
||||
|
||||
HeapValue *slots;
|
||||
if (!ReserveObjectDynamicSlots(cx, bindings.lastShape(), &slots))
|
||||
if (!PreallocateObjectDynamicSlots(cx, bindings.lastShape(), &slots))
|
||||
return NULL;
|
||||
|
||||
JSObject *obj = js_NewGCObject(cx, kind);
|
||||
JSObject *obj = JSObject::create(cx, kind, bindings.lastShape(), type, slots);
|
||||
if (!obj)
|
||||
return NULL;
|
||||
|
||||
obj->initialize(bindings.lastShape(), type, slots);
|
||||
|
||||
/*
|
||||
* Update the parent for bindings associated with non-compileAndGo scripts,
|
||||
* whose call objects do not have a consistent global variable and need
|
||||
|
Loading…
Reference in New Issue
Block a user