V8 Project
v8::internal::MessageHandler Class Reference

#include <messages.h>

+ Collaboration diagram for v8::internal::MessageHandler:

Static Public Member Functions

static Handle< JSMessageObjectMakeMessageObject (Isolate *isolate, const char *type, MessageLocation *loc, Vector< Handle< Object > > args, Handle< JSArray > stack_frames)
 
static void ReportMessage (Isolate *isolate, MessageLocation *loc, Handle< Object > message)
 
static void DefaultMessageReport (Isolate *isolate, const MessageLocation *loc, Handle< Object > message_obj)
 
static Handle< StringGetMessage (Isolate *isolate, Handle< Object > data)
 
static SmartArrayPointer< char > GetLocalizedMessage (Isolate *isolate, Handle< Object > data)
 

Detailed Description

Definition at line 67 of file messages.h.

Member Function Documentation

◆ DefaultMessageReport()

void v8::internal::MessageHandler::DefaultMessageReport ( Isolate isolate,
const MessageLocation loc,
Handle< Object message_obj 
)
static

Definition at line 18 of file messages.cc.

20  {
21  SmartArrayPointer<char> str = GetLocalizedMessage(isolate, message_obj);
22  if (loc == NULL) {
23  PrintF("%s\n", str.get());
24  } else {
25  HandleScope scope(isolate);
26  Handle<Object> data(loc->script()->name(), isolate);
27  SmartArrayPointer<char> data_str;
28  if (data->IsString())
29  data_str = Handle<String>::cast(data)->ToCString(DISALLOW_NULLS);
30  PrintF("%s:%i: %s\n", data_str.get() ? data_str.get() : "<unknown>",
31  loc->start_pos(), str.get());
32  }
33 }
static Handle< T > cast(Handle< S > that)
Definition: handles.h:116
static SmartArrayPointer< char > GetLocalizedMessage(Isolate *isolate, Handle< Object > data)
Definition: messages.cc:157
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
@ DISALLOW_NULLS
Definition: objects.h:8337
void PrintF(const char *format,...)
Definition: utils.cc:80

References v8::internal::Handle< T >::cast(), v8::internal::DISALLOW_NULLS, v8::internal::SmartPointerBase< Deallocator, T >::get(), GetLocalizedMessage(), NULL, v8::internal::PrintF(), v8::internal::MessageLocation::script(), and v8::internal::MessageLocation::start_pos().

Referenced by ReportMessage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetLocalizedMessage()

SmartArrayPointer< char > v8::internal::MessageHandler::GetLocalizedMessage ( Isolate isolate,
Handle< Object data 
)
static

Definition at line 157 of file messages.cc.

159  {
160  HandleScope scope(isolate);
161  return GetMessage(isolate, data)->ToCString(DISALLOW_NULLS);
162 }
static Handle< String > GetMessage(Isolate *isolate, Handle< Object > data)
Definition: messages.cc:129

References v8::internal::DISALLOW_NULLS, and GetMessage().

Referenced by DefaultMessageReport(), and v8::internal::Isolate::DoThrow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetMessage()

Handle< String > v8::internal::MessageHandler::GetMessage ( Isolate isolate,
Handle< Object data 
)
static

Definition at line 129 of file messages.cc.

130  {
131  Factory* factory = isolate->factory();
132  Handle<String> fmt_str =
133  factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("FormatMessage"));
134  Handle<JSFunction> fun = Handle<JSFunction>::cast(Object::GetProperty(
135  isolate->js_builtins_object(), fmt_str).ToHandleChecked());
136  Handle<JSMessageObject> message = Handle<JSMessageObject>::cast(data);
137  Handle<Object> argv[] = { Handle<Object>(message->type(), isolate),
138  Handle<Object>(message->arguments(), isolate) };
139 
140  MaybeHandle<Object> maybe_result = Execution::TryCall(
141  fun, isolate->js_builtins_object(), arraysize(argv), argv);
142  Handle<Object> result;
143  if (!maybe_result.ToHandle(&result) || !result->IsString()) {
144  return factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("<error>"));
145  }
146  Handle<String> result_string = Handle<String>::cast(result);
147  // A string that has been obtained from JS code in this way is
148  // likely to be a complicated ConsString of some sort. We flatten it
149  // here to improve the efficiency of converting it to a C string and
150  // other operations that are likely to take place (see GetLocalizedMessage
151  // for example).
152  result_string = String::Flatten(result_string);
153  return result_string;
154 }
static MUST_USE_RESULT MaybeHandle< Object > GetProperty(LookupIterator *it)
Definition: objects.cc:109
static Handle< String > Flatten(Handle< String > string, PretenureFlag pretenure=NOT_TENURED)
Definition: objects-inl.h:3354
#define arraysize(array)
Definition: macros.h:86
#define STATIC_CHAR_VECTOR(x)
Definition: vector.h:154

References arraysize, v8::internal::Handle< T >::cast(), v8::internal::Isolate::factory(), v8::internal::String::Flatten(), v8::internal::Object::GetProperty(), v8::internal::Isolate::js_builtins_object(), and STATIC_CHAR_VECTOR.

Referenced by v8::Message::Get(), and GetLocalizedMessage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MakeMessageObject()

Handle< JSMessageObject > v8::internal::MessageHandler::MakeMessageObject ( Isolate isolate,
const char *  type,
MessageLocation loc,
Vector< Handle< Object > >  args,
Handle< JSArray stack_frames 
)
static

Definition at line 36 of file messages.cc.

41  {
42  Factory* factory = isolate->factory();
43  Handle<String> type_handle = factory->InternalizeUtf8String(type);
44  Handle<FixedArray> arguments_elements =
45  factory->NewFixedArray(args.length());
46  for (int i = 0; i < args.length(); i++) {
47  arguments_elements->set(i, *args[i]);
48  }
49  Handle<JSArray> arguments_handle =
50  factory->NewJSArrayWithElements(arguments_elements);
51 
52  int start = 0;
53  int end = 0;
54  Handle<Object> script_handle = factory->undefined_value();
55  if (loc) {
56  start = loc->start_pos();
57  end = loc->end_pos();
58  script_handle = Script::GetWrapper(loc->script());
59  }
60 
61  Handle<Object> stack_frames_handle = stack_frames.is_null()
62  ? Handle<Object>::cast(factory->undefined_value())
63  : Handle<Object>::cast(stack_frames);
64 
65  Handle<JSMessageObject> message =
66  factory->NewJSMessageObject(type_handle,
67  arguments_handle,
68  start,
69  end,
70  script_handle,
71  stack_frames_handle);
72 
73  return message;
74 }
static Handle< JSObject > GetWrapper(Handle< Script > script)
Definition: objects.cc:9741
kSerializedDataOffset Object
Definition: objects-inl.h:5322

References v8::internal::Handle< T >::cast(), v8::internal::MessageLocation::end_pos(), v8::internal::Isolate::factory(), v8::internal::Script::GetWrapper(), v8::internal::Handle< T >::is_null(), v8::internal::MessageLocation::script(), and v8::internal::MessageLocation::start_pos().

Referenced by v8::internal::Debug::CompileDebuggerScript(), and v8::internal::Isolate::DoThrow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ReportMessage()

void v8::internal::MessageHandler::ReportMessage ( Isolate isolate,
MessageLocation loc,
Handle< Object message 
)
static

Definition at line 77 of file messages.cc.

79  {
80  // We are calling into embedder's code which can throw exceptions.
81  // Thus we need to save current exception state, reset it to the clean one
82  // and ignore scheduled exceptions callbacks can throw.
83 
84  // We pass the exception object into the message handler callback though.
85  Object* exception_object = isolate->heap()->undefined_value();
86  if (isolate->has_pending_exception()) {
87  exception_object = isolate->pending_exception();
88  }
89  Handle<Object> exception_handle(exception_object, isolate);
90 
91  Isolate::ExceptionScope exception_scope(isolate);
92  isolate->clear_pending_exception();
93  isolate->set_external_caught_exception(false);
94 
95  v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message);
96  v8::Local<v8::Value> api_exception_obj = v8::Utils::ToLocal(exception_handle);
97 
98  v8::NeanderArray global_listeners(isolate->factory()->message_listeners());
99  int global_length = global_listeners.length();
100  if (global_length == 0) {
101  DefaultMessageReport(isolate, loc, message);
102  if (isolate->has_scheduled_exception()) {
103  isolate->clear_scheduled_exception();
104  }
105  } else {
106  for (int i = 0; i < global_length; i++) {
107  HandleScope scope(isolate);
108  if (global_listeners.get(i)->IsUndefined()) continue;
109  v8::NeanderObject listener(JSObject::cast(global_listeners.get(i)));
110  Handle<Foreign> callback_obj(Foreign::cast(listener.get(0)));
111  v8::MessageCallback callback =
112  FUNCTION_CAST<v8::MessageCallback>(callback_obj->foreign_address());
113  Handle<Object> callback_data(listener.get(1), isolate);
114  {
115  // Do not allow exceptions to propagate.
116  v8::TryCatch try_catch;
117  callback(api_message_obj, callback_data->IsUndefined()
118  ? api_exception_obj
119  : v8::Utils::ToLocal(callback_data));
120  }
121  if (isolate->has_scheduled_exception()) {
122  isolate->clear_scheduled_exception();
123  }
124  }
125  }
126 }
A light-weight stack-allocated object handle.
Definition: v8.h:334
An external exception handler.
Definition: v8.h:5271
static Local< Context > ToLocal(v8::internal::Handle< v8::internal::Context > obj)
static Local< Message > MessageToLocal(v8::internal::Handle< v8::internal::Object > obj)
static void DefaultMessageReport(Isolate *isolate, const MessageLocation *loc, Handle< Object > message_obj)
Definition: messages.cc:18
void(* MessageCallback)(Handle< Message > message, Handle< Value > error)
Definition: v8.h:4120

References v8::internal::Isolate::clear_pending_exception(), v8::internal::Isolate::clear_scheduled_exception(), DefaultMessageReport(), v8::internal::Isolate::factory(), v8::NeanderObject::get(), v8::NeanderArray::get(), v8::internal::Isolate::has_pending_exception(), v8::internal::Isolate::has_scheduled_exception(), v8::internal::Isolate::heap(), v8::NeanderArray::length(), v8::Utils::MessageToLocal(), v8::internal::Isolate::pending_exception(), and v8::Utils::ToLocal().

Referenced by v8::internal::Debug::CompileDebuggerScript(), and v8::internal::Isolate::ReportPendingMessages().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: