From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/promise/Promise-inl.h | 341 ++++++ dom/promise/Promise.cpp | 1129 ++++++++++++++++++++ dom/promise/Promise.h | 460 ++++++++ dom/promise/PromiseDebugging.cpp | 296 +++++ dom/promise/PromiseDebugging.h | 84 ++ dom/promise/PromiseNativeHandler.cpp | 18 + dom/promise/PromiseNativeHandler.h | 78 ++ dom/promise/PromiseWorkerProxy.h | 219 ++++ dom/promise/gtest/NativeThenHandler.cpp | 160 +++ dom/promise/gtest/ThenWithCycleCollectedArgsJS.cpp | 158 +++ dom/promise/gtest/moz.build | 14 + dom/promise/moz.build | 42 + dom/promise/tests/chrome.toml | 27 + .../tests/file_promise_and_timeout_ordering.js | 18 + dom/promise/tests/file_promise_argument_tests.js | 175 +++ ...romise_job_with_bind_from_discarded_iframe.html | 14 + dom/promise/tests/file_promise_retval_tests.js | 56 + dom/promise/tests/file_promise_xrays.html | 34 + dom/promise/tests/mochitest.toml | 44 + dom/promise/tests/promise_uncatchable_exception.js | 11 + dom/promise/tests/test_bug883683.html | 41 + dom/promise/tests/test_on_new_promise.html | 45 + dom/promise/tests/test_on_promise_settled.html | 53 + .../tests/test_on_promise_settled_duplicates.html | 58 + dom/promise/tests/test_promise.html | 844 +++++++++++++++ .../tests/test_promise_and_timeout_ordering.html | 16 + .../test_promise_and_timeout_ordering_workers.html | 14 + dom/promise/tests/test_promise_argument.html | 49 + dom/promise/tests/test_promise_argument_xrays.html | 90 ++ .../tests/test_promise_callback_retval.html | 53 + ...romise_job_with_bind_from_discarded_iframe.html | 63 ++ dom/promise/tests/test_promise_retval.html | 51 + dom/promise/tests/test_promise_retval_xrays.html | 94 ++ .../tests/test_promise_uncatchable_exception.html | 35 + dom/promise/tests/test_promise_utils.html | 313 ++++++ dom/promise/tests/test_promise_xrays.html | 365 +++++++ dom/promise/tests/test_resolve.html | 66 ++ dom/promise/tests/test_resolver_return_value.html | 40 + dom/promise/tests/test_species_getter.html | 25 + .../tests/test_thenable_vs_promise_ordering.html | 29 + dom/promise/tests/test_webassembly_compile.html | 446 ++++++++ .../tests/test_webassembly_compile_sample.wasm | Bin 0 -> 16053 bytes .../tests/test_webassembly_compile_worker.js | 55 + .../test_webassembly_compile_worker_terminate.js | 13 + dom/promise/tests/unit/test_monitor_uncaught.js | 322 ++++++ .../tests/unit/test_promise_job_across_sandbox.js | 221 ++++ .../tests/unit/test_promise_unhandled_rejection.js | 139 +++ dom/promise/tests/unit/xpcshell.toml | 8 + 48 files changed, 6926 insertions(+) create mode 100644 dom/promise/Promise-inl.h create mode 100644 dom/promise/Promise.cpp create mode 100644 dom/promise/Promise.h create mode 100644 dom/promise/PromiseDebugging.cpp create mode 100644 dom/promise/PromiseDebugging.h create mode 100644 dom/promise/PromiseNativeHandler.cpp create mode 100644 dom/promise/PromiseNativeHandler.h create mode 100644 dom/promise/PromiseWorkerProxy.h create mode 100644 dom/promise/gtest/NativeThenHandler.cpp create mode 100644 dom/promise/gtest/ThenWithCycleCollectedArgsJS.cpp create mode 100644 dom/promise/gtest/moz.build create mode 100644 dom/promise/moz.build create mode 100644 dom/promise/tests/chrome.toml create mode 100644 dom/promise/tests/file_promise_and_timeout_ordering.js create mode 100644 dom/promise/tests/file_promise_argument_tests.js create mode 100644 dom/promise/tests/file_promise_job_with_bind_from_discarded_iframe.html create mode 100644 dom/promise/tests/file_promise_retval_tests.js create mode 100644 dom/promise/tests/file_promise_xrays.html create mode 100644 dom/promise/tests/mochitest.toml create mode 100644 dom/promise/tests/promise_uncatchable_exception.js create mode 100644 dom/promise/tests/test_bug883683.html create mode 100644 dom/promise/tests/test_on_new_promise.html create mode 100644 dom/promise/tests/test_on_promise_settled.html create mode 100644 dom/promise/tests/test_on_promise_settled_duplicates.html create mode 100644 dom/promise/tests/test_promise.html create mode 100644 dom/promise/tests/test_promise_and_timeout_ordering.html create mode 100644 dom/promise/tests/test_promise_and_timeout_ordering_workers.html create mode 100644 dom/promise/tests/test_promise_argument.html create mode 100644 dom/promise/tests/test_promise_argument_xrays.html create mode 100644 dom/promise/tests/test_promise_callback_retval.html create mode 100644 dom/promise/tests/test_promise_job_with_bind_from_discarded_iframe.html create mode 100644 dom/promise/tests/test_promise_retval.html create mode 100644 dom/promise/tests/test_promise_retval_xrays.html create mode 100644 dom/promise/tests/test_promise_uncatchable_exception.html create mode 100644 dom/promise/tests/test_promise_utils.html create mode 100644 dom/promise/tests/test_promise_xrays.html create mode 100644 dom/promise/tests/test_resolve.html create mode 100644 dom/promise/tests/test_resolver_return_value.html create mode 100644 dom/promise/tests/test_species_getter.html create mode 100644 dom/promise/tests/test_thenable_vs_promise_ordering.html create mode 100644 dom/promise/tests/test_webassembly_compile.html create mode 100644 dom/promise/tests/test_webassembly_compile_sample.wasm create mode 100644 dom/promise/tests/test_webassembly_compile_worker.js create mode 100644 dom/promise/tests/test_webassembly_compile_worker_terminate.js create mode 100644 dom/promise/tests/unit/test_monitor_uncaught.js create mode 100644 dom/promise/tests/unit/test_promise_job_across_sandbox.js create mode 100644 dom/promise/tests/unit/test_promise_unhandled_rejection.js create mode 100644 dom/promise/tests/unit/xpcshell.toml (limited to 'dom/promise') diff --git a/dom/promise/Promise-inl.h b/dom/promise/Promise-inl.h new file mode 100644 index 0000000000..a7a6ebd0fd --- /dev/null +++ b/dom/promise/Promise-inl.h @@ -0,0 +1,341 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_Promise_inl_h +#define mozilla_dom_Promise_inl_h + +#include +#include + +#include "mozilla/AlreadyAddRefed.h" +#include "mozilla/ResultExtensions.h" +#include "mozilla/dom/BindingUtils.h" +#include "mozilla/dom/Promise.h" +#include "mozilla/dom/PromiseNativeHandler.h" +#include "nsCycleCollectionParticipant.h" + +namespace mozilla::dom { + +class PromiseNativeThenHandlerBase : public PromiseNativeHandler { + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PromiseNativeThenHandlerBase) + + PromiseNativeThenHandlerBase(Promise* aPromise) : mPromise(aPromise) {} + + virtual bool HasResolvedCallback() = 0; + virtual bool HasRejectedCallback() = 0; + + MOZ_CAN_RUN_SCRIPT void ResolvedCallback(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) override; + + MOZ_CAN_RUN_SCRIPT void RejectedCallback(JSContext* aCx, + JS::Handle aValue, + ErrorResult& aRv) override; + + protected: + virtual ~PromiseNativeThenHandlerBase() = default; + + MOZ_CAN_RUN_SCRIPT virtual already_AddRefed CallResolveCallback( + JSContext* aCx, JS::Handle aValue, ErrorResult& aRv) = 0; + MOZ_CAN_RUN_SCRIPT virtual already_AddRefed CallRejectCallback( + JSContext* aCx, JS::Handle aValue, ErrorResult& aRv) = 0; + + virtual void Traverse(nsCycleCollectionTraversalCallback&) = 0; + virtual void Unlink() = 0; + virtual void Trace(const TraceCallbacks& aCallbacks, void* aClosure) = 0; + + RefPtr mPromise; +}; + +namespace { + +template >::value, + bool = (std::is_convertible_v || + std::is_convertible_v)> +struct StorageTypeHelper { + using Type = T; +}; + +template +struct StorageTypeHelper { + using Type = nsCOMPtr; +}; + +template +struct StorageTypeHelper, true, true> { + using Type = nsCOMPtr; +}; + +template +struct StorageTypeHelper { + using Type = RefPtr; +}; + +template +struct StorageTypeHelper, false, false> { + using Type = JS::Heap; +}; + +template