Shaka Player Embedded
v8_utils.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 
16 
17 #include <glog/logging.h>
18 
21 #include "src/mapping/convert_js.h"
22 #include "src/mapping/js_engine.h"
24 
25 namespace shaka {
26 
27 v8::Isolate* GetIsolate() {
28  return JsEngine::Instance()->isolate();
29 }
30 
31 void PrintStackTrace(const v8::Local<v8::StackTrace>& stack) {
32  auto* isolate = GetIsolate();
33  v8::HandleScope handle_scope(isolate);
34  for (int i = 0; i < stack->GetFrameCount(); ++i) {
35  const v8::Local<v8::StackFrame> frame = stack->GetFrame(isolate, i);
36  const v8::String::Utf8Value name(isolate, frame->GetScriptName());
37  const v8::String::Utf8Value func(isolate, frame->GetFunctionName());
38  const int row = frame->GetLineNumber();
39  const int col = frame->GetColumn();
40 
41  std::string func_or_main = func.length() ? *func : "<anonymous>";
42  LOG(ERROR) << " at " << func_or_main << " (" << *name << ":" << row << ":"
43  << col << ")";
44  }
45 }
46 
47 void OnUncaughtException(const v8::Local<v8::Value>& exception,
48  bool in_promise) {
49  if (exception.IsEmpty())
50  return;
51 
52  // Print the exception and stack trace.
53  v8::Isolate* isolate = GetIsolate();
54  v8::String::Utf8Value err_str(isolate, exception);
55  if (in_promise)
56  LOG(ERROR) << "Uncaught (in promise): " << *err_str;
57  else
58  LOG(ERROR) << "Uncaught:" << *err_str;
59 
60  v8::HandleScope handle_scope(isolate);
61  v8::Local<v8::StackTrace> stack = v8::Exception::GetStackTrace(exception);
62  if (!stack.IsEmpty()) {
63  PrintStackTrace(stack);
64  }
65 }
66 
67 } // namespace shaka
std::shared_ptr< shaka::media::DecodedFrame > frame
const char * name
void OnUncaughtException(JSValueRef exception, bool in_promise)
Definition: jsc_utils.cc:28
void PrintStackTrace(const v8::Local< v8::StackTrace > &stack)
Definition: v8_utils.cc:31
v8::Isolate * GetIsolate()
Definition: v8_utils.cc:27