21#define CONSOLE_METHOD_LIST(V) \
25 V(GroupEnd, groupEnd) \
28 V(CountReset, countReset) \
30 V(ProfileEnd, profileEnd)
32#define CONSOLE_METHOD_WITH_FORMATTER_LIST(V) \
40 V(GroupCollapsed, groupCollapsed, 1) \
64bool Formatter(Isolate* isolate, BuiltinArguments&
args,
int index) {
65 if (
args.length() < index + 2 || !IsString(
args[index])) {
72 std::stack<State> states;
73 HandleScope scope(isolate);
74 auto percent = isolate->factory()->percent_sign_string();
75 states.push({
args.at<String>(index++), 0});
76 while (!states.empty() && index <
args.length()) {
77 State& state = states.top();
80 state.off ==
static_cast<int>(state.str->length()) - 1) {
85 uint16_t specifier = state.str->Get(state.off + 1, isolate);
86 if (specifier ==
'd' || specifier ==
'f' || specifier ==
'i') {
87 if (IsSymbol(*current)) {
88 current = isolate->factory()->nan_value();
90 DirectHandle<Object> params[] = {
91 current, isolate->factory()->NewNumberFromInt(10)};
92 auto builtin = specifier ==
'f' ? isolate->global_parse_float_fun()
93 : isolate->global_parse_int_fun();
95 isolate->factory()->undefined_value(),
97 .ToHandle(¤t)) {
101 }
else if (specifier ==
's') {
102 DirectHandle<Object> params[] = {current};
104 isolate->factory()->undefined_value(),
106 .ToHandle(¤t)) {
113 }
else if (specifier ==
'c' || specifier ==
'o' || specifier ==
'O' ||
123 }
else if (specifier ==
'%') {
137 args.set_at(index++, *current);
148 CONSOLE_CONTEXT_NAME_INDEX,
149 CONSOLE_CONTEXT_SLOTS,
153 Isolate* isolate,
const internal::BuiltinArguments&
args,
156 if (isolate->is_execution_terminating())
return;
157 CHECK(!isolate->has_exception());
158 if (!isolate->console_delegate())
return;
159 HandleScope scope(isolate);
161 DirectHandle<String> context_name = isolate->factory()->anonymous_string();
162 if (!IsNativeContext(
args.target()->context())) {
163 DirectHandle<Context>
context(
args.target()->context(), isolate);
164 CHECK_EQ(CONSOLE_CONTEXT_SLOTS, context->length());
165 context_id =
Cast<Smi>(context->get(CONSOLE_CONTEXT_ID_INDEX)).value();
167 Cast<String>(context->get(CONSOLE_CONTEXT_NAME_INDEX)), isolate);
169 (isolate->console_delegate()->*func)(
170 debug::ConsoleCallArguments(isolate,
args),
174void LogTimerEvent(Isolate* isolate, BuiltinArguments
args,
176 if (!
v8_flags.log_timer_events)
return;
177 HandleScope scope(isolate);
178 std::unique_ptr<char[]>
name;
179 const char* raw_name =
"default";
180 if (
args.length() > 1 && IsString(
args[1])) {
182 name =
args.at<String>(1)->ToCString();
183 raw_name = name.get();
185 LOG(isolate, TimerEvent(se, raw_name));
190#define CONSOLE_BUILTIN_IMPLEMENTATION(call, name) \
191 BUILTIN(Console##call) { \
192 ConsoleCall(isolate, args, &debug::ConsoleDelegate::call); \
193 RETURN_FAILURE_IF_EXCEPTION(isolate); \
194 return ReadOnlyRoots(isolate).undefined_value(); \
197#undef CONSOLE_BUILTIN_IMPLEMENTATION
199#define CONSOLE_BUILTIN_IMPLEMENTATION(call, name, index) \
200 BUILTIN(Console##call) { \
201 if (!Formatter(isolate, args, index)) { \
202 return ReadOnlyRoots(isolate).exception(); \
204 ConsoleCall(isolate, args, &debug::ConsoleDelegate::call); \
205 RETURN_FAILURE_IF_EXCEPTION(isolate); \
206 return ReadOnlyRoots(isolate).undefined_value(); \
209#undef CONSOLE_BUILTIN_IMPLEMENTATION
240void InstallContextFunction(
Isolate* isolate, DirectHandle<JSObject> target,
241 const char* name,
Builtin builtin,
242 DirectHandle<Context> context) {
243 Factory*
const factory = isolate->factory();
245 DirectHandle<Map> map = isolate->sloppy_function_without_prototype_map();
247 DirectHandle<String> name_string = factory->InternalizeUtf8String(name);
249 DirectHandle<SharedFunctionInfo> info =
250 factory->NewSharedFunctionInfoForBuiltin(name_string, builtin, 1,
253 info->set_native(
true);
255 DirectHandle<JSFunction> fun =
256 Factory::JSFunctionBuilder{
isolate,
info, context}.set_map(map).Build();
265 Factory*
const factory = isolate->factory();
273 if (
args.length() > 1) {
277 int context_id = isolate->last_console_context_id() + 1;
278 isolate->set_last_console_context_id(context_id);
296 DCHECK(IsJSObject(*console_context));
299 isolate->native_context(), CONSOLE_CONTEXT_SLOTS);
300 context->set(CONSOLE_CONTEXT_ID_INDEX,
Smi::FromInt(context_id));
301 context->set(CONSOLE_CONTEXT_NAME_INDEX, *context_name);
303#define CONSOLE_BUILTIN_SETUP(call, name, ...) \
304 InstallContextFunction(isolate, console_context, #name, \
305 Builtin::kConsole##call, context);
312#undef CONSOLE_BUILTIN_SETUP
314 return *console_context;
317#undef CONSOLE_METHOD_LIST
#define CONSOLE_BUILTIN_IMPLEMENTATION(call, name)
#define CONSOLE_BUILTIN_SETUP(call, name,...)
#define CONSOLE_METHOD_WITH_FORMATTER_LIST(V)
#define CONSOLE_METHOD_LIST(V)
virtual void TimeLog(const ConsoleCallArguments &args, const ConsoleContext &context)
virtual void TimeEnd(const ConsoleCallArguments &args, const ConsoleContext &context)
virtual void TimeStamp(const ConsoleCallArguments &args, const ConsoleContext &context)
virtual void Time(const ConsoleCallArguments &args, const ConsoleContext &context)
static V8_WARN_UNUSED_RESULT MaybeHandle< Object > CallBuiltin(Isolate *isolate, DirectHandle< JSFunction > builtin, DirectHandle< Object > receiver, base::Vector< const DirectHandle< Object > > args)
V8_WARN_UNUSED_RESULT Handle< JSFunction > Build()
Handle< SharedFunctionInfo > NewSharedFunctionInfoForBuiltin(MaybeDirectHandle< String > name, Builtin builtin, int len, AdaptArguments adapt, FunctionKind kind=FunctionKind::kNormalFunction)
Handle< JSObject > NewJSObject(DirectHandle< JSFunction > constructor, AllocationType allocation=AllocationType::kYoung, NewJSObjectType=NewJSObjectType::kNoAPIWrapper)
DirectHandle< Context > NewBuiltinContext(DirectHandle< NativeContext > native_context, int length)
Handle< String > InternalizeUtf8String(base::Vector< const char > str)
Handle< NativeContext > native_context()
static void SetPrototype(DirectHandle< JSFunction > function, DirectHandle< Object > value)
static V8_EXPORT_PRIVATE void AddProperty(Isolate *isolate, DirectHandle< JSObject > object, DirectHandle< Name > name, DirectHandle< Object > value, PropertyAttributes attributes)
static V8_WARN_UNUSED_RESULT HandleType< String >::MaybeType ToString(Isolate *isolate, HandleType< T > input)
static constexpr Tagged< Smi > FromInt(int value)
static Tagged< Object > IndexOf(Isolate *isolate, DirectHandle< Object > receiver, DirectHandle< Object > search, DirectHandle< Object > position)
Handle< SharedFunctionInfo > info
#define RETURN_FAILURE_IF_EXCEPTION(isolate)
#define ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, dst, call)
base::Vector< const DirectHandle< Object > > args
#define LOG(isolate, Call)
constexpr Vector< T > VectorOf(T *start, size_t size)
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in name
Handle< T > IndirectHandle
constexpr AdaptArguments kDontAdapt
V8_EXPORT_PRIVATE FlagValues v8_flags
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
#define CHECK_EQ(lhs, rhs)
#define DCHECK(condition)