mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-27 01:27:30 +09:00
ported from mozilla: Bug 1476955 - Structured clone algorithm doesn't serialize Array Length contrary to HTML spec, resulting in truncation of trailing sparse arrays like [1,2,3,,] (length=4) to [1,2,3] (length=3); r=sfink (958b3cdb98)
This commit is contained in:
parent
8183d7b70c
commit
a553551082
1 changed files with 11 additions and 2 deletions
|
|
@ -1240,7 +1240,16 @@ JSStructuredCloneWriter::traverseObject(HandleObject obj)
|
||||||
ESClass cls;
|
ESClass cls;
|
||||||
if (!GetBuiltinClass(context(), obj, &cls))
|
if (!GetBuiltinClass(context(), obj, &cls))
|
||||||
return false;
|
return false;
|
||||||
return out.writePair(cls == ESClass::Array ? SCTAG_ARRAY_OBJECT : SCTAG_OBJECT_OBJECT, 0);
|
|
||||||
|
if (cls == ESClass::Array) {
|
||||||
|
uint32_t length = 0;
|
||||||
|
if (!JS_GetArrayLength(context(), obj, &length))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return out.writePair(SCTAG_ARRAY_OBJECT, NativeEndian::swapToLittleEndian(length));
|
||||||
|
}
|
||||||
|
|
||||||
|
return out.writePair(SCTAG_OBJECT_OBJECT, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
@ -2143,7 +2152,7 @@ JSStructuredCloneReader::startRead(MutableHandleValue vp)
|
||||||
case SCTAG_ARRAY_OBJECT:
|
case SCTAG_ARRAY_OBJECT:
|
||||||
case SCTAG_OBJECT_OBJECT: {
|
case SCTAG_OBJECT_OBJECT: {
|
||||||
JSObject* obj = (tag == SCTAG_ARRAY_OBJECT)
|
JSObject* obj = (tag == SCTAG_ARRAY_OBJECT)
|
||||||
? (JSObject*) NewDenseEmptyArray(context())
|
? (JSObject*) NewDenseUnallocatedArray(context(), NativeEndian::swapFromLittleEndian(data))
|
||||||
: (JSObject*) NewBuiltinClassInstance<PlainObject>(context());
|
: (JSObject*) NewBuiltinClassInstance<PlainObject>(context());
|
||||||
if (!obj || !objs.append(ObjectValue(*obj)))
|
if (!obj || !objs.append(ObjectValue(*obj)))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue