From 727a24d78ef80126e3336e279280a3c942cc35fb Mon Sep 17 00:00:00 2001 From: Basilisk-Dev Date: Mon, 30 Oct 2023 15:36:44 -0400 Subject: [PATCH 1/6] No issue - Structured clone algorithm doesn't serialize Array Length contrary to HTML spec, resulting in truncation of trailing sparse arrays like [1,2,3,,] Backport of https://bugzilla.mozilla.org/show_bug.cgi?id=1476955 --- js/src/vm/StructuredClone.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/js/src/vm/StructuredClone.cpp b/js/src/vm/StructuredClone.cpp index e99cfe8f71..f7b7c75965 100644 --- a/js/src/vm/StructuredClone.cpp +++ b/js/src/vm/StructuredClone.cpp @@ -1240,7 +1240,16 @@ JSStructuredCloneWriter::traverseObject(HandleObject obj) ESClass cls; if (!GetBuiltinClass(context(), obj, &cls)) 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 @@ -2143,7 +2152,7 @@ JSStructuredCloneReader::startRead(MutableHandleValue vp) case SCTAG_ARRAY_OBJECT: case SCTAG_OBJECT_OBJECT: { JSObject* obj = (tag == SCTAG_ARRAY_OBJECT) - ? (JSObject*) NewDenseEmptyArray(context()) + ? (JSObject*) NewDenseUnallocatedArray(context(), NativeEndian::swapFromLittleEndian(data)) : (JSObject*) NewBuiltinClassInstance(context()); if (!obj || !objs.append(ObjectValue(*obj))) return false; From ae5bfc9ff22d75bf1e4ecc81b0c339f724d6b9bb Mon Sep 17 00:00:00 2001 From: Basilisk-Dev Date: Mon, 30 Oct 2023 15:38:40 -0400 Subject: [PATCH 2/6] No Issue - StructuredClone serialize and deserialize should treat back reference consistently Backport of https://bugzilla.mozilla.org/show_bug.cgi?id=1538622 --- dom/base/test/mochitest.ini | 1 + dom/tests/mochitest/bugs/test_bug743615.html | 3 +- js/src/vm/StructuredClone.cpp | 32 ++++++++++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/dom/base/test/mochitest.ini b/dom/base/test/mochitest.ini index 27a970c21a..6f5e0ea835 100644 --- a/dom/base/test/mochitest.ini +++ b/dom/base/test/mochitest.ini @@ -764,6 +764,7 @@ skip-if = debug == false [test_setting_opener.html] [test_simplecontentpolicy.html] skip-if = e10s # Bug 1156489. +[test_structuredclone_backref.html] [test_text_wholeText.html] [test_textnode_normalize_in_selection.html] [test_textnode_split_in_selection.html] diff --git a/dom/tests/mochitest/bugs/test_bug743615.html b/dom/tests/mochitest/bugs/test_bug743615.html index 39e978ddad..044e6509dc 100644 --- a/dom/tests/mochitest/bugs/test_bug743615.html +++ b/dom/tests/mochitest/bugs/test_bug743615.html @@ -54,8 +54,7 @@ function windowMessage(evt) { ok(checkPattern(imageData, pattern), 'postMessage from self worked correctly'); - // We're not spec compliant on this yet. - todo_is(imageData.data, evt.data.dataRef, + is(imageData.data, evt.data.dataRef, 'Should have backrefs for imagedata buffer'); // Make a new pattern, and send it to a worker. diff --git a/js/src/vm/StructuredClone.cpp b/js/src/vm/StructuredClone.cpp index f7b7c75965..daaaf52b92 100644 --- a/js/src/vm/StructuredClone.cpp +++ b/js/src/vm/StructuredClone.cpp @@ -2046,6 +2046,7 @@ bool JSStructuredCloneReader::startRead(MutableHandleValue vp) { uint32_t tag, data; + bool alreadAppended = false; if (!in.readPair(&tag, &data)) return false; @@ -2246,15 +2247,29 @@ JSStructuredCloneReader::startRead(MutableHandleValue vp) "unsupported type"); return false; } + + // callbacks->read() might read other objects from the buffer. + // In startWrite we always write the object itself before calling + // the custom function. We should do the same here to keep + // indexing consistent. + uint32_t placeholderIndex = allObjs.length(); + Value dummy = UndefinedValue(); + if (!allObjs.append(dummy)) { + return false; + } + JSObject* obj = callbacks->read(context(), this, tag, data, closure); if (!obj) return false; vp.setObject(*obj); + allObjs[placeholderIndex].set(vp); + alreadAppended = true; } } - if (vp.isObject() && !allObjs.append(vp)) + if (!alreadAppended && vp.isObject() && !allObjs.append(vp)) { return false; + } return true; } @@ -2828,7 +2843,20 @@ JS_WriteTypedArray(JSStructuredCloneWriter* w, HandleValue v) MOZ_ASSERT(v.isObject()); assertSameCompartment(w->context(), v); RootedObject obj(w->context(), &v.toObject()); - return w->writeTypedArray(obj); + + // startWrite can write everything, thus we should check here + // and report error if the user passes a wrong type. + if (!JS_IsTypedArrayObject(obj)) { + JS_ReportErrorNumberASCII(w->context(), GetErrorMessage, nullptr, + JSMSG_SC_BAD_SERIALIZED_DATA, + "expected type array"); + return false; + } + + // We should use startWrite instead of writeTypedArray, because + // typed array is an object, we should add it to the |memory| + // (allObjs) list. Directly calling writeTypedArray won't add it. + return w->startWrite(v); } JS_PUBLIC_API(bool) From 42db0b335f82977fcbd28d34c56faf070def38f0 Mon Sep 17 00:00:00 2001 From: athenian200 Date: Sat, 4 Nov 2023 01:43:49 -0500 Subject: [PATCH 3/6] Issue #1824 - Support SunOS Linker mapfiles. Generating OS-appropriate mapfiles from a provided SYMBOL_FILE is apparently required to work with newer ffvpx. Nothing else in our codebase actually seemed to require it. Also seems to reduce the amount of console spam I see relating to symbol visibility during the build process, and I think it even makes libxul.so link a bit faster. Signed-off-by: athenian200 --- config/rules.mk | 4 ++++ .../mozbuild/action/generate_symbols_file.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/config/rules.mk b/config/rules.mk index d7cbf60987..2078a5160c 100644 --- a/config/rules.mk +++ b/config/rules.mk @@ -411,6 +411,10 @@ EXTRA_DSO_LDOPTS += -Wl,--version-script,$(SYMBOLS_FILE) else ifeq ($(OS_TARGET),Darwin) EXTRA_DSO_LDOPTS += -Wl,-exported_symbols_list,$(SYMBOLS_FILE) +else +ifeq ($(OS_TARGET),SunOS) +EXTRA_DSO_LDOPTS += -Wl,-M,$(SYMBOLS_FILE) +endif endif endif endif diff --git a/python/mozbuild/mozbuild/action/generate_symbols_file.py b/python/mozbuild/mozbuild/action/generate_symbols_file.py index ff6136bb14..3eebf324cc 100644 --- a/python/mozbuild/mozbuild/action/generate_symbols_file.py +++ b/python/mozbuild/mozbuild/action/generate_symbols_file.py @@ -83,6 +83,20 @@ def generate_symbols_file(output, *args): # }; output.write('{\nglobal:\n %s;\nlocal:\n *;\n};' % ';\n '.join(symbols)) + elif buildconfig.substs['OS_TARGET'] == 'SunOS': + # A linker version script is generated for Sun LD that looks like the + # following: + # $mapfile_version 2 + # SYMBOL_VERSION SUNW_1.1 { + # global: + # symbol1; + # symbol2; + # ... + # local: + # *; + # }; + output.write('$mapfile_version 2\nSYMBOL_VERSION SUNW_1.1 {\nglobal:\n %s;\nlocal:\n *;\n};' + % ';\n '.join(symbols)) elif buildconfig.substs['OS_TARGET'] == 'Darwin': # A list of symbols is generated for Apple ld that simply lists all # symbols, with an underscore prefix. From 1ac65a828dfc45971d1e42ac84a0e2e8844aaf89 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 8 Nov 2023 15:34:07 +0100 Subject: [PATCH 4/6] No Issue - Adjust configure to deal with FreeBSD regex breakage for \S --- old-configure.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/old-configure.in b/old-configure.in index ce29bb0034..4a527b4e20 100644 --- a/old-configure.in +++ b/old-configure.in @@ -5572,7 +5572,7 @@ ac_configure_args="$_SUBDIR_CONFIG_ARGS" # --with-system-nspr will have been converted into the relevant $NSPR_CFLAGS # and $NSPR_LIBS. -ac_configure_args="`echo $ac_configure_args | sed -e 's/--with-system-nspr\S* *//'`" +ac_configure_args="`echo $ac_configure_args | sed -e 's/--with-system-nspr[^[:space:]]* *//'`" if test -n "$NSPR_CFLAGS" -o -n "$NSPR_LIBS"; then ac_configure_args="$ac_configure_args --with-nspr-cflags='$NSPR_CFLAGS'" From c68105436b5900e8baa76aebd5759bd303e8857f Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Wed, 8 Nov 2023 19:20:13 -0600 Subject: [PATCH 5/6] Issue #2376 - Split NSPR sed into BSD and GNU. Mac and the BSDs use [^[:space:]]. Use GNU sed on other platforms with \S. --- old-configure.in | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/old-configure.in b/old-configure.in index 4a527b4e20..26653b898f 100644 --- a/old-configure.in +++ b/old-configure.in @@ -5572,7 +5572,14 @@ ac_configure_args="$_SUBDIR_CONFIG_ARGS" # --with-system-nspr will have been converted into the relevant $NSPR_CFLAGS # and $NSPR_LIBS. -ac_configure_args="`echo $ac_configure_args | sed -e 's/--with-system-nspr[^[:space:]]* *//'`" +case "${OS_TARGET}" in + Darwin|DragonFly|FreeBSD|NetBSD|OpenBSD) + ac_configure_args="`echo $ac_configure_args | sed -e 's/--with-system-nspr[^[:space:]]* *//'`" + ;; + *) + ac_configure_args="`echo $ac_configure_args | ${TOOLCHAIN_PREFIX}sed -e 's/--with-system-nspr\S* *//'`" + ;; +esac if test -n "$NSPR_CFLAGS" -o -n "$NSPR_LIBS"; then ac_configure_args="$ac_configure_args --with-nspr-cflags='$NSPR_CFLAGS'" From 6c37943e1c060876c72b0c53649ea69b180038e8 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Thu, 9 Nov 2023 12:25:41 +0100 Subject: [PATCH 6/6] No Issue - add mutex in EventSource Potentially avoids a gc crash when load is high. --- dom/base/EventSource.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/dom/base/EventSource.cpp b/dom/base/EventSource.cpp index 06cabc3098..32329098e2 100644 --- a/dom/base/EventSource.cpp +++ b/dom/base/EventSource.cpp @@ -190,6 +190,7 @@ public: bool IsClosed() { + MutexAutoLock lock(mMutex); return ReadyState() == CLOSED; }