Commit 37cff53d authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

Use automatic ExceptionState in HTMLPortalElement::activate.

The bindings now provide an ExceptionState and automatically turn the result
into a promise rejection (if an exception is thrown), so we don't need to
duplicate this in the implementation of HTMLPortalElement::activate.

Bug: 1001114
Change-Id: I69f9ffa0301f9d03bd221be5a81fee549f65b73a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1789822Reviewed-by: default avatarAdithya Srinivasan <adithyas@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694269}
parent 24b842b8
...@@ -194,50 +194,41 @@ BlinkTransferableMessage ActivateDataAsMessage( ...@@ -194,50 +194,41 @@ BlinkTransferableMessage ActivateDataAsMessage(
} // namespace } // namespace
ScriptPromise HTMLPortalElement::activate(ScriptState* script_state, ScriptPromise HTMLPortalElement::activate(ScriptState* script_state,
PortalActivateOptions* options) { PortalActivateOptions* options,
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); ExceptionState& exception_state) {
ScriptPromise promise = resolver->Promise();
ExceptionState exception_state(script_state->GetIsolate(),
ExceptionState::kExecutionContext,
"HTMLPortalElement", "activate");
if (!remote_portal_) { if (!remote_portal_) {
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kInvalidStateError,
"The HTMLPortalElement is not associated with a portal context."); "The HTMLPortalElement is not associated with a portal context.");
resolver->Reject(exception_state); return ScriptPromise();
return promise;
} }
if (is_activating_) { if (is_activating_) {
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kInvalidStateError,
"activate() has already been called on this HTMLPortalElement."); "activate() has already been called on this HTMLPortalElement.");
resolver->Reject(exception_state); return ScriptPromise();
return promise;
} }
if (DocumentPortals::From(GetDocument()).IsPortalInDocumentActivating()) { if (DocumentPortals::From(GetDocument()).IsPortalInDocumentActivating()) {
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kInvalidStateError,
"activate() has already been called on another " "activate() has already been called on another "
"HTMLPortalElement in this document."); "HTMLPortalElement in this document.");
resolver->Reject(exception_state); return ScriptPromise();
return promise;
} }
if (GetDocument().GetPage()->InsidePortal()) { if (GetDocument().GetPage()->InsidePortal()) {
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kInvalidStateError,
"Cannot activate a portal that is inside another portal."); "Cannot activate a portal that is inside another portal.");
resolver->Reject(exception_state); return ScriptPromise();
return promise;
} }
BlinkTransferableMessage data = BlinkTransferableMessage data =
ActivateDataAsMessage(script_state, options, exception_state); ActivateDataAsMessage(script_state, options, exception_state);
if (exception_state.HadException()) { if (exception_state.HadException())
resolver->Reject(exception_state); return ScriptPromise();
return promise;
} auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
ScriptPromise promise = resolver->Promise();
// The HTMLPortalElement is bound as a persistent so that it won't get // The HTMLPortalElement is bound as a persistent so that it won't get
// garbage collected while there is a pending callback. // garbage collected while there is a pending callback.
......
...@@ -44,7 +44,7 @@ class CORE_EXPORT HTMLPortalElement : public HTMLFrameOwnerElement, ...@@ -44,7 +44,7 @@ class CORE_EXPORT HTMLPortalElement : public HTMLFrameOwnerElement,
void Trace(Visitor* visitor) override; void Trace(Visitor* visitor) override;
// idl implementation. // idl implementation.
ScriptPromise activate(ScriptState*, PortalActivateOptions*); ScriptPromise activate(ScriptState*, PortalActivateOptions*, ExceptionState&);
void postMessage(ScriptState* script_state, void postMessage(ScriptState* script_state,
const ScriptValue& message, const ScriptValue& message,
const String& target_origin, const String& target_origin,
......
...@@ -9,7 +9,7 @@ interface HTMLPortalElement : HTMLElement { ...@@ -9,7 +9,7 @@ interface HTMLPortalElement : HTMLElement {
[CEReactions, Reflect, URL, RaisesException=Setter] attribute URLString src; [CEReactions, Reflect, URL, RaisesException=Setter] attribute URLString src;
[CEReactions, Reflect, ReflectOnly=("","no-referrer","origin","no-referrer-when-downgrade","origin-when-cross-origin","unsafe-url"), ReflectMissing="", ReflectInvalid=""] attribute DOMString referrerPolicy; [CEReactions, Reflect, ReflectOnly=("","no-referrer","origin","no-referrer-when-downgrade","origin-when-cross-origin","unsafe-url"), ReflectMissing="", ReflectInvalid=""] attribute DOMString referrerPolicy;
[CallWith=ScriptState] Promise<void> activate(optional PortalActivateOptions options); [CallWith=ScriptState, RaisesException] Promise<void> activate(optional PortalActivateOptions options);
[CallWith=ScriptState, RaisesException] void postMessage(any message, DOMString targetOrigin, [CallWith=ScriptState, RaisesException] void postMessage(any message, DOMString targetOrigin,
optional sequence<object> transfer = []); optional sequence<object> transfer = []);
[CallWith=ScriptState, RaisesException] void postMessage(any message, optional WindowPostMessageOptions options); [CallWith=ScriptState, RaisesException] void postMessage(any message, optional WindowPostMessageOptions options);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment