Shaka Player Embedded
request.cc
Go to the documentation of this file.
1 // Copyright 2016 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 
15 #include "src/js/idb/request.h"
16 
18 #include "src/js/idb/cursor.h"
20 #include "src/js/idb/transaction.h"
21 #include "src/mapping/enum.h"
22 #include "src/memory/heap_tracer.h"
23 
24 namespace shaka {
25 namespace js {
26 namespace idb {
27 
30  RefPtr<IDBTransaction> transaction)
31  : source(source), transaction(transaction) {
33  AddListenerField(EventType::Error, &on_error);
34 }
35 
36 // \cond Doxygen_Skip
37 IDBRequest::~IDBRequest() {}
38 // \endcond Doxygen_Skip
39 
42  tracer->Trace(&error_);
43  tracer->Trace(&result_);
44  tracer->Trace(&source);
45  tracer->Trace(&transaction);
46 }
47 
50 }
51 
55  return result_;
56 }
57 
61  return error_;
62 }
63 
66  result_ = result;
67 
69  bool did_throw;
70  DispatchEventInternal(event, &did_throw);
71  if (did_throw)
72  transaction->Abort();
73 }
74 
77  error_.TryConvert(error.error());
78  RaiseEvent<events::Event>(EventType::Error);
79 }
80 
82  switch (status) {
85  break;
88  break;
91  break;
94  break;
95  default:
97  break;
98  }
99 }
100 
101 
103  AddReadOnlyProperty("source", &IDBRequest::source);
104  AddReadOnlyProperty("transaction", &IDBRequest::transaction);
105  AddReadOnlyProperty("readyState", &IDBRequest::ready_state);
106 
107  AddGenericProperty("result", &IDBRequest::Result);
108  AddGenericProperty("error", &IDBRequest::Error);
109 
111  AddListenerField(EventType::Error, &IDBRequest::on_error);
112 }
113 
114 } // namespace idb
115 } // namespace js
116 } // namespace shaka
Definition: any.h:31
ExceptionOr< bool > DispatchEventInternal(RefPtr< Event > event, bool *did_listeners_throw)
Definition: event_target.cc:68
void Trace(memory::HeapTracer *tracer) const override
Definition: request.cc:40
IDBRequest(optional< variant< Member< IDBObjectStore >, Member< IDBCursor >>> source, RefPtr< IDBTransaction > transaction)
Definition: request.cc:28
optional< variant< Member< IDBObjectStore >, Member< IDBCursor > > > source
Definition: request.h:72
ExceptionOr< Any > Result() const
Definition: request.cc:52
const char * source
Definition: media_utils.cc:30
void CompleteError(JsError error)
Definition: request.cc:75
void Trace(const Traceable *ptr)
Definition: heap_tracer.cc:43
ReturnVal< JsValue > error() const
Definition: js_error.h:52
IDBRequestReadyState ready_state
Definition: request.h:74
void Trace(memory::HeapTracer *tracer) const override
Definition: event_target.cc:31
void CompleteSuccess(Any result)
Definition: request.cc:64
ExceptionOr< Any > Error() const
Definition: request.cc:58
static JsError DOMException(ExceptionCode code)
Definition: js_error.cc:115
Member< IDBTransaction > transaction
Definition: request.h:73
void AddListenerField(EventType type, Listener *on_field)
Definition: event_target.h:138
bool TryConvert(Handle< JsValue > value) override
Definition: any.cc:50