Bug 1090636, part 8 - Factor out SetDenseOrTypedArrayElement from SetExistingProperty. No change in behavior. r=efaust.

--HG--
extra : rebase_source : a81ae31c30c8d0206b7e18f79afeb1c6eee8b201
This commit is contained in:
Jason Orendorff 2014-10-29 12:29:28 -05:00
parent 497606c43f
commit ddeec566f8

View File

@ -2101,6 +2101,12 @@ SetNonexistentProperty(typename ExecutionModeTraits<mode>::ContextType cxArg,
return SetPropertyByDefining<mode>(cxArg, receiver, id, v, strict);
}
template <ExecutionMode mode>
static bool
SetDenseOrTypedArrayElement(typename ExecutionModeTraits<mode>::ContextType cxArg,
HandleNativeObject obj, uint32_t index, MutableHandleValue vp,
bool strict);
/*
* Implement "the rest of" assignment to receiver[id] when an existing property
* (foundShape) has been found on a native object (pobj).
@ -2173,55 +2179,8 @@ SetExistingProperty(typename ExecutionModeTraits<mode>::ContextType cxArg,
}
}
if (IsImplicitDenseOrTypedArrayElement(shape)) {
uint32_t index = JSID_TO_INT(id);
if (IsAnyTypedArray(obj)) {
double d;
if (mode == ParallelExecution) {
// Bail if converting the value might invoke user-defined
// conversions.
if (vp.isObject())
return false;
if (!NonObjectToNumber(cxArg, vp, &d))
return false;
} else {
if (!ToNumber(cxArg->asJSContext(), vp, &d))
return false;
}
// Silently do nothing for out-of-bounds sets, for consistency with
// current behavior. (ES6 currently says to throw for this in
// strict mode code, so we may eventually need to change.)
uint32_t len = AnyTypedArrayLength(obj);
if (index < len) {
if (obj->is<TypedArrayObject>())
TypedArrayObject::setElement(obj->as<TypedArrayObject>(), index, d);
else
SharedTypedArrayObject::setElement(obj->as<SharedTypedArrayObject>(), index, d);
}
return true;
}
bool definesPast;
if (!WouldDefinePastNonwritableLength(cxArg, obj, index, strict, &definesPast))
return false;
if (definesPast) {
/* Bail out of parallel execution if we are strict to throw. */
if (mode == ParallelExecution)
return !strict;
return true;
}
if (!obj->maybeCopyElementsForWrite(cxArg))
return false;
if (mode == ParallelExecution)
return obj->setDenseElementIfHasType(index, vp);
obj->setDenseElementWithType(cxArg->asJSContext(), index, vp);
return true;
}
if (IsImplicitDenseOrTypedArrayElement(shape))
return SetDenseOrTypedArrayElement<mode>(cxArg, obj, JSID_TO_INT(id), vp, strict);
if (shape) {
if (obj->is<ArrayObject>() && id == NameToId(cxArg->names().length)) {
@ -2234,6 +2193,59 @@ SetExistingProperty(typename ExecutionModeTraits<mode>::ContextType cxArg,
return SetPropertyByDefining<mode>(cxArg, receiver, id, vp, strict);
}
template <ExecutionMode mode>
static bool
SetDenseOrTypedArrayElement(typename ExecutionModeTraits<mode>::ContextType cxArg,
HandleNativeObject obj, uint32_t index, MutableHandleValue vp,
bool strict)
{
if (IsAnyTypedArray(obj)) {
double d;
if (mode == ParallelExecution) {
// Bail if converting the value might invoke user-defined
// conversions.
if (vp.isObject())
return false;
if (!NonObjectToNumber(cxArg, vp, &d))
return false;
} else {
if (!ToNumber(cxArg->asJSContext(), vp, &d))
return false;
}
// Silently do nothing for out-of-bounds sets, for consistency with
// current behavior. (ES6 currently says to throw for this in
// strict mode code, so we may eventually need to change.)
uint32_t len = AnyTypedArrayLength(obj);
if (index < len) {
if (obj->is<TypedArrayObject>())
TypedArrayObject::setElement(obj->as<TypedArrayObject>(), index, d);
else
SharedTypedArrayObject::setElement(obj->as<SharedTypedArrayObject>(), index, d);
}
return true;
}
bool definesPast;
if (!WouldDefinePastNonwritableLength(cxArg, obj, index, strict, &definesPast))
return false;
if (definesPast) {
/* Bail out of parallel execution if we are strict to throw. */
if (mode == ParallelExecution)
return !strict;
return true;
}
if (!obj->maybeCopyElementsForWrite(cxArg))
return false;
if (mode == ParallelExecution)
return obj->setDenseElementIfHasType(index, vp);
obj->setDenseElementWithType(cxArg->asJSContext(), index, vp);
return true;
}
template <ExecutionMode mode>
bool
baseops::SetPropertyHelper(typename ExecutionModeTraits<mode>::ContextType cxArg,