Shaka Player Embedded
js_utils.h
Go to the documentation of this file.
1 // Copyright 2018 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 #ifndef SHAKA_EMBEDDED_MAPPING_JS_UTILS_H_
16 #define SHAKA_EMBEDDED_MAPPING_JS_UTILS_H_
17 
18 #include <functional>
19 #include <future>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 #include "shaka/error.h"
25 #include "shaka/optional.h"
26 #include "src/core/ref_ptr.h"
28 #include "src/mapping/promise.h"
30 
31 namespace shaka {
32 
43 ReturnVal<JsValue> GetDescendant(Handle<JsObject> root,
44  const std::vector<std::string>& names);
45 
51 template <typename T, typename... Args>
52 RefPtr<T> MakeJsRef(Args&&... args) {
53  auto* p = new T(std::forward<Args>(args)...);
54  memory::ObjectTracker::Instance()->RegisterObject(p);
55  return p;
56 }
57 
63 void HandleNetworkFuture(Promise promise, std::future<optional<Error>> future,
64  std::function<void()> on_done);
65 
66 } // namespace shaka
67 
68 #endif // SHAKA_EMBEDDED_MAPPING_JS_UTILS_H_
ReturnVal< JsValue > GetDescendant(Handle< JsObject > root, const std::vector< std::string > &names)
Definition: js_utils.cc:52
void HandleNetworkFuture(Promise promise, std::future< optional< Error >> future, std::function< void()> on_done)
Definition: js_utils.cc:68
RefPtr< T > MakeJsRef(Args &&... args)
Definition: js_utils.h:52