17 method_name(method_name),
29 std::stringstream result;
31 int frame_count = stack_trace->GetFrameCount();
32 for (
int i = 0; i < frame_count; i++) {
33 auto frame = stack_trace->GetFrame(i);
34 result << fmt::format(
"{}:{} {}",
35 *v8::String::Utf8Value(frame->GetScriptName()),
36 frame->GetLineNumber(),
37 *v8::String::Utf8Value(frame->GetFunctionName())) << std::endl;
47 #ifdef V8TOOLKIT_DEMANGLE_NAMES 51 auto demangled_name_needs_to_be_freed = abi::__cxa_demangle(mangled_name.c_str(),
nullptr, 0, &status);
52 result = demangled_name_needs_to_be_freed;
54 if (demangled_name_needs_to_be_freed ==
nullptr) {
59 result = demangled_name_needs_to_be_freed;
65 result = mangled_name;
67 if (demangled_name_needs_to_be_freed) {
68 free(demangled_name_needs_to_be_freed);
77 using namespace literals;
80 auto context = isolate->GetCurrentContext();
81 return array->Get(context,
"length"_v8).ToLocalChecked()->Uint32Value();
87 if(array_value->IsArray()) {
98 auto global_object = context->Global();
99 (void)global_object->Set(context, v8::String::NewFromUtf8(isolate, alias_name.c_str()), global_object);
107 if (value->IsUndefined()) {
109 }
else if (value->IsFunction()) {
111 }
else if (value->IsString()) {
113 }
else if (value->IsNumber()) {
115 }
else if (value->IsBoolean()) {
117 }
else if (value->IsSymbol()) {
119 }
else if (value->IsObject()) {
124 return "UNKNOWN VALUE TYPE";
131 auto value = *local_value;
133 std::cout <<
"undefined: " << value->IsUndefined() << std::endl;
134 std::cout <<
"null: " << value->IsNull() << std::endl;
135 std::cout <<
"true: " << value->IsTrue() << std::endl;
136 std::cout <<
"false: " << value->IsFalse() << std::endl;
137 std::cout <<
"name: " << value->IsName() << std::endl;
138 std::cout <<
"string: " << value->IsString() << std::endl;
139 std::cout <<
"symbol: " << value->IsSymbol() << std::endl;
140 std::cout <<
"function: " << value->IsFunction() << std::endl;
141 std::cout <<
"array: " << value->IsArray() << std::endl;
142 std::cout <<
"object: " << value->IsObject() << std::endl;
143 std::cout <<
"boolean: " << value->IsBoolean() << std::endl;
144 std::cout <<
"number: " << value->IsNumber() << std::endl;
145 std::cout <<
"external: " << value->IsExternal() << std::endl;
146 std::cout <<
"isint32: " << value->IsInt32() << std::endl;
147 std::cout <<
"isuint32: " << value->IsUint32() << std::endl;
148 std::cout <<
"date: " << value->IsDate() << std::endl;
149 std::cout <<
"argument object: " << value->IsArgumentsObject() << std::endl;
150 std::cout <<
"boolean object: " << value->IsBooleanObject() << std::endl;
151 std::cout <<
"number object: " << value->IsNumberObject() << std::endl;
152 std::cout <<
"string object: " << value->IsStringObject() << std::endl;
153 std::cout <<
"symbol object: " << value->IsSymbolObject() << std::endl;
154 std::cout <<
"native error: " << value->IsNativeError() << std::endl;
155 std::cout <<
"regexp: " << value->IsRegExp() << std::endl;
156 std::cout <<
"generator function: " << value->IsGeneratorFunction() << std::endl;
157 std::cout <<
"generator object: " << value->IsGeneratorObject() << std::endl;
162 bool own_properties_only)
164 auto context = isolate->GetCurrentContext();
166 if (own_properties_only) {
167 properties =
object->GetOwnPropertyNames(context).ToLocalChecked();
169 properties =
object->GetPropertyNames(context).ToLocalChecked();
173 std::set<std::string> keys;
175 for (
int i = 0; i < array_length; i++) {
176 keys.insert(*v8::String::Utf8Value(properties->Get(context, i).ToLocalChecked()));
185 #define STRINGIFY_VALUE_DEBUG false 189 bool show_all_properties,
193 if (value.IsEmpty()) {
194 return "<Empty v8::Local<v8::Value>>";
198 auto context = isolate->GetCurrentContext();
200 std::stringstream output;
204 if (value->IsObject() || value->IsArray()) {
205 for(
auto processed_value : processed_values) {
206 if(processed_value == value) {
212 processed_values.push_back(value);
216 if(value.IsEmpty()) {
218 return "Value specified as an empty v8::Local";
222 if (value->IsBoolean() || value->IsNumber() || value->IsUndefined() || value->IsNull()) {
224 v8::String::Utf8Value value_utf8value(value);
225 auto string = *value_utf8value;
226 output << (
string ?
string :
"<COULD NOT CONVERT TO STRING>");
228 }
else if (value->IsFunction()) {
229 v8::String::Utf8Value value_utf8value(value);
230 auto string = *value_utf8value;
231 output << (
string ?
string :
"FUNCTION: <COULD NOT CONVERT TO STRING>");
237 }
else if (value->IsString()) {
238 output <<
"\"" << *v8::String::Utf8Value(value) <<
"\"";
239 }
else if (value->IsArray()) {
245 auto first_element =
true;
246 for (
int i = 0; i < array_length; i++) {
247 if (!first_element) {
250 first_element =
false;
251 auto value = array->Get(context, i);
262 output <<
"Object type: " << *v8::String::Utf8Value(object->GetConstructorName()) << std::endl;
263 if (object->InternalFieldCount() > 0) {
264 output <<
"Internal field pointer: " << (
void *)v8::External::Cast(*object->GetInternalField(0))->
Value() << std::endl;
266 if(value->IsObject() && !
object.IsEmpty()) {
270 auto first_key =
true;
271 for(
auto key : keys) {
279 auto value =
object->Get(context, v8::String::NewFromUtf8(isolate, key.c_str()));
290 return get_key_as<v8::Value>(context, object, key);
294 return get_key_as<v8::Value>(context, get_value_as<v8::Object>(value), key);
303 v8::TryCatch tc(isolate);
305 auto maybe_result =
function->Call(context, context->Global(), 0,
nullptr);
306 if(tc.HasCaught() || maybe_result.IsEmpty()) {
308 printf(
"Error running javascript function: '%s'\n", *v8::String::Utf8Value(tc.Exception()));
311 return maybe_result.ToLocalChecked();
317 v8::HandleScope handle_scope(isolate);
318 v8::String::Utf8Value exception(try_catch->Exception());
319 const char* exception_string = *exception;
321 if (message.IsEmpty()) {
324 fprintf(stderr,
"%s\n", exception_string);
327 v8::String::Utf8Value filename(message->GetScriptOrigin().ResourceName());
329 const char* filename_string = *filename;
330 int linenum = message->GetLineNumber(context).FromJust();
331 fprintf(stderr,
"%s:%i: %s\n", filename_string, linenum, exception_string);
333 v8::String::Utf8Value sourceline(
334 message->GetSourceLine(context).ToLocalChecked());
335 const char* sourceline_string = *sourceline;
336 fprintf(stderr,
"%s\n", sourceline_string);
338 int start = message->GetStartColumn(context).FromJust();
339 for (
int i = 0; i < start; i++) {
340 fprintf(stderr,
" ");
342 int end = message->GetEndColumn(context).FromJust();
343 for (
int i = start; i < end; i++) {
344 fprintf(stderr,
"^");
346 fprintf(stderr,
"\n");
348 if (try_catch->StackTrace(context).ToLocal(&stack_trace_string) &&
349 stack_trace_string->IsString() &&
351 v8::String::Utf8Value stack_trace(stack_trace_string);
352 const char* stack_trace_string = *stack_trace;
353 fprintf(stderr,
"%s\n", stack_trace_string);
369 "Object",
"Symbol",
"Date",
"Array",
"Set",
"WeakSet",
370 "Map",
"WeakMap",
"JSON"};
#define STRINGIFY_VALUE_DEBUG
bool Value(const T &value, M matcher)
const T & move(const T &t)