blob: 6b6a039ff60cd38cbc5b904577affad201f11630 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/bindings/core/v8/v8_promise_rejection_event.h"
#include "third_party/blink/renderer/bindings/core/v8/exception_state.h"
#include "third_party/blink/renderer/bindings/core/v8/generated_code_helper.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
namespace blink {
void V8PromiseRejectionEvent::promiseAttributeGetterCustom(
const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
// This attribute returns a Promise.
// Per https://heycam.github.io/webidl/#dfn-attribute-getter, all exceptions
// must be turned into a Promise rejection. Returning a Promise type requires
// us to disable some of V8's type checks, so we have to manually check that
// info.Holder() really points to an instance of the type.
PromiseRejectionEvent* event =
V8PromiseRejectionEvent::ToImplWithTypeCheck(isolate, info.Holder());
if (!event) {
ExceptionState exception_state(isolate, ExceptionState::kGetterContext,
"PromiseRejectionEvent", "promise");
ExceptionToRejectPromiseScope rejectPromiseScope(info, exception_state);
exception_state.ThrowTypeError("Illegal invocation");
return;
}
ScriptPromise promise = event->promise(ScriptState::Current(isolate));
if (promise.IsEmpty()) {
V8SetReturnValue(info, v8::Null(isolate));
return;
}
V8SetReturnValue(info, promise.V8Value());
}
} // namespace blink
|