Modified: branches/safari-612-branch/LayoutTests/ChangeLog (287708 => 287709)
--- branches/safari-612-branch/LayoutTests/ChangeLog 2022-01-06 19:59:35 UTC (rev 287708)
+++ branches/safari-612-branch/LayoutTests/ChangeLog 2022-01-06 20:01:46 UTC (rev 287709)
@@ -1,5 +1,19 @@
2022-01-06 Russell Epstein <[email protected]>
+ Apply patch. rdar://problem/87124847
+
+ 2022-01-06 Youenn Fablet <[email protected]>
+
+ ReadableStream::lock should check whether there is an exception when getting ReadableStreamDefaultReader private constructor
+ https://bugs.webkit.org/show_bug.cgi?id=234890
+
+ Reviewed by Frédéric Wang.
+
+ * streams/readable-stream-lock-after-worker-terminates-crash-expected.txt: Added.
+ * streams/readable-stream-lock-after-worker-terminates-crash.html: Added.
+
+2022-01-06 Russell Epstein <[email protected]>
+
Apply patch. rdar://problem/87125345
2022-01-06 Youenn Fablet <[email protected]>
Added: branches/safari-612-branch/LayoutTests/streams/readable-stream-lock-after-worker-terminates-crash-expected.txt (0 => 287709)
--- branches/safari-612-branch/LayoutTests/streams/readable-stream-lock-after-worker-terminates-crash-expected.txt (rev 0)
+++ branches/safari-612-branch/LayoutTests/streams/readable-stream-lock-after-worker-terminates-crash-expected.txt 2022-01-06 20:01:46 UTC (rev 287709)
@@ -0,0 +1,2 @@
+CONSOLE MESSAGE: This test PASS if it does not crash.
+
Added: branches/safari-612-branch/LayoutTests/streams/readable-stream-lock-after-worker-terminates-crash.html (0 => 287709)
--- branches/safari-612-branch/LayoutTests/streams/readable-stream-lock-after-worker-terminates-crash.html (rev 0)
+++ branches/safari-612-branch/LayoutTests/streams/readable-stream-lock-after-worker-terminates-crash.html 2022-01-06 20:01:46 UTC (rev 287709)
@@ -0,0 +1,30 @@
+<script>
+function createWorker() {
+ function createRequest() {
+ setTimeout(() => {
+ const request = new Request("http://test.org", {"method": "POST", "body": "text" });
+ request.text();
+ request.body;
+ }, 0);
+ self.postMessage("");
+ };
+ const worker = new Worker('data:application/_javascript_;charset=utf-8,' + createRequest.toString() + ';createRequest()');
+ return new Promise(resolve => {
+ worker._onmessage_ = () => {
+ worker.terminate();
+ resolve();
+ }
+ });
+}
+
+_onload_ = () => {
+ if (window.testRunner)
+ testRunner.dumpAsText();
+ console.log('This test PASS if it does not crash.')
+ for (var i = 0; i < 100; ++i) {
+ const script = document.createElement('script');
+ script.src = ""
+ document.head.appendChild(script);
+ }
+};
+</script>
Modified: branches/safari-612-branch/Source/WebCore/ChangeLog (287708 => 287709)
--- branches/safari-612-branch/Source/WebCore/ChangeLog 2022-01-06 19:59:35 UTC (rev 287708)
+++ branches/safari-612-branch/Source/WebCore/ChangeLog 2022-01-06 20:01:46 UTC (rev 287709)
@@ -1,5 +1,23 @@
2022-01-06 Russell Epstein <[email protected]>
+ Apply patch. rdar://problem/87124847
+
+ 2022-01-06 Youenn Fablet <[email protected]>
+
+ ReadableStream::lock should check whether there is an exception when getting ReadableStreamDefaultReader private constructor
+ https://bugs.webkit.org/show_bug.cgi?id=234890
+
+ Reviewed by Frédéric Wang and Mark Lam.
+
+ Do in ReadableStream::lock like we are doing when getting ReadableStream private constructor in ReadableStream::create.
+ For that reason, introduce a invokeConstructor utility function.
+
+ Test: streams/readable-stream-lock-after-worker-terminates-crash.html
+
+ * bindings/js/ReadableStream.cpp:
+
+2022-01-06 Russell Epstein <[email protected]>
+
Apply patch. rdar://problem/87125345
2022-01-06 Youenn Fablet <[email protected]>
Modified: branches/safari-612-branch/Source/WebCore/bindings/js/ReadableStream.cpp (287708 => 287709)
--- branches/safari-612-branch/Source/WebCore/bindings/js/ReadableStream.cpp 2022-01-06 19:59:35 UTC (rev 287708)
+++ branches/safari-612-branch/Source/WebCore/bindings/js/ReadableStream.cpp 2022-01-06 20:01:46 UTC (rev 287709)
@@ -37,30 +37,47 @@
namespace WebCore {
using namespace JSC;
-ExceptionOr<Ref<ReadableStream>> ReadableStream::create(JSC::JSGlobalObject& lexicalGlobalObject, RefPtr<ReadableStreamSource>&& source)
+static inline ExceptionOr<JSObject*> invokeConstructor(JSC::JSGlobalObject& lexicalGlobalObject, const JSC::Identifier& identifier, const Function<void(MarkedArgumentBuffer&, JSC::JSGlobalObject&, JSDOMGlobalObject&)>& buildArguments)
{
VM& vm = lexicalGlobalObject.vm();
auto scope = DECLARE_THROW_SCOPE(vm);
- auto& clientData = *static_cast<JSVMClientData*>(vm.clientData);
auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(&lexicalGlobalObject);
- auto* constructor = JSC::asObject(globalObject.get(&lexicalGlobalObject, clientData.builtinNames().ReadableStreamPrivateName()));
+ auto constructorValue = globalObject.get(&lexicalGlobalObject, identifier);
+ EXCEPTION_ASSERT(!scope.exception() || vm.hasPendingTerminationException());
+ RETURN_IF_EXCEPTION(scope, Exception { ExistingExceptionError });
+ auto constructor = JSC::asObject(constructorValue);
auto constructData = getConstructData(vm, constructor);
ASSERT(constructData.type != CallData::Type::None);
MarkedArgumentBuffer args;
- args.append(source ? toJSNewlyCreated(&lexicalGlobalObject, &globalObject, source.releaseNonNull()) : JSC::jsUndefined());
+ buildArguments(args, lexicalGlobalObject, globalObject);
ASSERT(!args.hasOverflowed());
JSObject* object = JSC::construct(&lexicalGlobalObject, constructor, constructData, args);
ASSERT(!!scope.exception() == !object);
+ EXCEPTION_ASSERT(!scope.exception() || vm.hasPendingTerminationException());
RETURN_IF_EXCEPTION(scope, Exception { ExistingExceptionError });
- return create(globalObject, *jsCast<JSReadableStream*>(object));
+ return object;
}
+ExceptionOr<Ref<ReadableStream>> ReadableStream::create(JSC::JSGlobalObject& lexicalGlobalObject, RefPtr<ReadableStreamSource>&& source)
+{
+ auto& clientData = *static_cast<JSVMClientData*>(lexicalGlobalObject.vm().clientData);
+
+ auto objectOrException = invokeConstructor(lexicalGlobalObject, clientData.builtinNames().ReadableStreamPrivateName(), [&source](auto& args, auto& lexicalGlobalObject, auto& globalObject) {
+ args.append(source ? toJSNewlyCreated(&lexicalGlobalObject, &globalObject, source.releaseNonNull()) : JSC::jsUndefined());
+ });
+
+ if (objectOrException.hasException())
+ return objectOrException.releaseException();
+
+ return create(*JSC::jsCast<JSDOMGlobalObject*>(&lexicalGlobalObject), *jsCast<JSReadableStream*>(objectOrException.releaseReturnValue()));
+}
+
static inline std::optional<JSC::JSValue> invokeReadableStreamFunction(JSC::JSGlobalObject& lexicalGlobalObject, const JSC::Identifier& identifier, JSC::JSValue thisValue, const JSC::MarkedArgumentBuffer& arguments)
{
JSC::VM& vm = lexicalGlobalObject.vm();
@@ -113,25 +130,10 @@
void ReadableStream::lock()
{
- auto& lexicalGlobalObject = *m_globalObject;
- auto& vm = lexicalGlobalObject.vm();
-#if ENABLE(EXCEPTION_SCOPE_VERIFICATION)
- auto scope = DECLARE_CATCH_SCOPE(vm);
-#endif
-
- auto& clientData = *static_cast<JSVMClientData*>(vm.clientData);
-
- auto* constructor = JSC::asObject(m_globalObject->get(&lexicalGlobalObject, clientData.builtinNames().ReadableStreamDefaultReaderPrivateName()));
-
- auto constructData = getConstructData(vm, constructor);
- ASSERT(constructData.type != CallData::Type::None);
-
- MarkedArgumentBuffer args;
- args.append(readableStream());
- ASSERT(!args.hasOverflowed());
-
- JSC::construct(&lexicalGlobalObject, constructor, constructData, args);
- EXCEPTION_ASSERT(!scope.exception() || vm.hasPendingTerminationException());
+ auto& clientData = *static_cast<JSVMClientData*>(m_globalObject->vm().clientData);
+ invokeConstructor(*m_globalObject, clientData.builtinNames().ReadableStreamDefaultReaderPrivateName(), [this](auto& args, auto&, auto&) {
+ args.append(readableStream());
+ });
}
static inline bool checkReadableStream(JSDOMGlobalObject& globalObject, JSReadableStream* readableStream, JSC::JSValue function)