Shaka Player Embedded
rejected_promise_handler.cc
Go to the documentation of this file.
1 // Copyright 2017 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
18 #include "src/memory/heap_tracer.h"
19 
20 namespace shaka {
21 
23 
25 
26 void RejectedPromiseHandler::AddPromise(Handle<JsPromise> promise,
27  Handle<JsValue> value) {
28  promises_.emplace_back(promise, value);
29  if (!has_callback_) {
30  has_callback_ = true;
32  TaskPriority::Immediate, "", [this]() { LogUnhandledRejection(); });
33  }
34 }
35 
36 void RejectedPromiseHandler::RemovePromise(Handle<JsPromise> promise) {
37  for (auto it = promises_.begin(); it != promises_.end(); it++) {
38  if (it->promise == promise) {
39  promises_.erase(it);
40  break;
41  }
42  }
43 }
44 
45 
46 RejectedPromiseHandler::PromiseInfo::PromiseInfo(Handle<JsPromise> promise,
47  Handle<JsValue> value)
48  : promise(promise), value(value) {}
49 
50 RejectedPromiseHandler::PromiseInfo::~PromiseInfo() {}
51 
52 
54  for (auto& info : promises_) {
55  OnUncaughtException(info.value, /* inPromse */ true);
56  }
57  promises_.clear();
58  has_callback_ = false;
59 }
60 
61 } // namespace shaka
void AddPromise(Handle< JsPromise > promise, Handle< JsValue > value)
std::shared_ptr< ThreadEvent< impl::RetOf< Func > > > AddInternalTask(TaskPriority priority, const std::string &name, Func &&callback)
Definition: task_runner.h:219
void OnUncaughtException(JSValueRef exception, bool in_promise)
Definition: jsc_utils.cc:28
void RemovePromise(Handle< JsPromise > promise)
TaskRunner * MainThread()