27 js::JsError MakeError(
const Error& error) {
29 const double severity = error.severity != 0 ? error.severity : 2;
31 {
"shaka",
"util",
"Error"});
33 LOG(DFATAL) <<
"Unable to find 'shaka.util.Error'";
36 LocalVar<JsFunction> ctor_func = UnsafeJsCast<JsFunction>(ctor);
40 LocalVar<JsValue> results;
42 LOG(DFATAL) <<
"Error creating shaka.util.Error: " 53 const std::vector<std::string>& names) {
57 LocalVar<JsObject> cur = root;
58 for (
size_t i = 0;; i++) {
60 if (i == names.size() - 1)
64 cur = UnsafeJsCast<JsObject>(child);
69 std::function<
void()> on_done) {
70 auto shared_future = future.share();
71 auto finish_future = [=]() {
73 auto error = shared_future.get();
74 if (error.has_value()) {
75 copy.
RejectWith(MakeError(error.value()),
false);
82 if (shared_future.valid()) {
84 using std::operator
""s;
85 if (shared_future.wait_for(0s) == std::future_status::timeout) {
88 std::shared_ptr<int> id(
new int);
90 if (shared_future.wait_for(0s) == std::future_status::timeout)
92 thread->CancelTimer(*
id);
95 *
id = thread->AddRepeatedTimer(250, std::move(poll));
98 std::move(finish_future));
bool IsObject(Handle< JsValue > value)
static JsError Rethrow(Handle< JsValue > error)
ReturnVal< JsValue > GetDescendant(Handle< JsObject > root, const std::vector< std::string > &names)
ReturnVal< JsValue > ToJsValue(T &&source)
void RejectWith(const js::JsError &error, bool run_events=true)
void HandleNetworkFuture(Promise promise, std::future< optional< Error >> future, std::function< void()> on_done)
ReturnVal< JsValue > RawToJsValue(Handle< T > source)
proto::ValueType GetValueType(Handle< JsValue > value)
static JsEngine * Instance()
std::string ConvertToString(Handle< JsValue > value)
static JsError TypeError(const std::string &message)
bool InvokeConstructor(Handle< JsFunction > ctor, int argc, LocalVar< JsValue > *argv, LocalVar< JsValue > *result_or_except)
ReturnVal< JsValue > GetMemberRaw(Handle< JsObject > object, const std::string &name, LocalVar< JsValue > *exception=nullptr)
TaskRunner * MainThread()