5 #include "src/api-inl.h" 6 #include "src/builtins/builtins-utils-inl.h" 7 #include "src/builtins/builtins.h" 8 #include "src/counters.h" 9 #include "src/debug/interface-types.h" 10 #include "src/objects-inl.h" 18 #define CONSOLE_METHOD_LIST(V) \ 29 V(GroupCollapsed, groupCollapsed) \ 30 V(GroupEnd, groupEnd) \ 33 V(CountReset, countReset) \ 36 V(ProfileEnd, profileEnd) \ 41 Isolate* isolate, internal::BuiltinArguments& args,
44 CHECK(!isolate->has_pending_exception());
45 CHECK(!isolate->has_scheduled_exception());
46 if (!isolate->console_delegate())
return;
47 HandleScope scope(isolate);
48 debug::ConsoleCallArguments wrapper(args);
49 Handle<Object> context_id_obj = JSObject::GetDataProperty(
50 args.target(), isolate->factory()->console_context_id_symbol());
52 context_id_obj->IsSmi() ? Handle<Smi>::cast(context_id_obj)->value() : 0;
53 Handle<Object> context_name_obj = JSObject::GetDataProperty(
54 args.target(), isolate->factory()->console_context_name_symbol());
55 Handle<String> context_name = context_name_obj->IsString()
56 ? Handle<String>::cast(context_name_obj)
57 : isolate->factory()->anonymous_string();
58 (isolate->console_delegate()->*func)(
63 void LogTimerEvent(Isolate* isolate, BuiltinArguments args,
64 Logger::StartEnd se) {
65 if (!isolate->logger()->is_logging())
return;
66 HandleScope scope(isolate);
67 std::unique_ptr<char[]> name;
68 const char* raw_name =
"default";
69 if (args.length() > 1 && args[1]->IsString()) {
71 name = args.at<String>(1)->ToCString();
72 raw_name = name.get();
74 LOG(isolate, TimerEvent(se, raw_name));
78 #define CONSOLE_BUILTIN_IMPLEMENTATION(call, name) \ 79 BUILTIN(Console##call) { \ 80 ConsoleCall(isolate, args, &debug::ConsoleDelegate::call); \ 81 RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate); \ 82 return ReadOnlyRoots(isolate).undefined_value(); \ 84 CONSOLE_METHOD_LIST(CONSOLE_BUILTIN_IMPLEMENTATION)
85 #undef CONSOLE_BUILTIN_IMPLEMENTATION 87 BUILTIN(ConsoleTime) {
88 LogTimerEvent(isolate, args, Logger::START);
89 ConsoleCall(isolate, args, &debug::ConsoleDelegate::Time);
90 RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate);
91 return ReadOnlyRoots(isolate).undefined_value();
94 BUILTIN(ConsoleTimeEnd) {
95 LogTimerEvent(isolate, args, Logger::END);
96 ConsoleCall(isolate, args, &debug::ConsoleDelegate::TimeEnd);
97 RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate);
98 return ReadOnlyRoots(isolate).undefined_value();
101 BUILTIN(ConsoleTimeStamp) {
102 LogTimerEvent(isolate, args, Logger::STAMP);
103 ConsoleCall(isolate, args, &debug::ConsoleDelegate::TimeStamp);
104 RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate);
105 return ReadOnlyRoots(isolate).undefined_value();
109 void InstallContextFunction(Isolate* isolate, Handle<JSObject> target,
110 const char* name, Builtins::Name builtin_id,
111 int context_id, Handle<Object> context_name) {
112 Factory*
const factory = isolate->factory();
114 Handle<String> name_string =
115 Name::ToFunctionName(isolate, factory->InternalizeUtf8String(name))
117 NewFunctionArgs args = NewFunctionArgs::ForBuiltinWithoutPrototype(
118 name_string, builtin_id, i::LanguageMode::kSloppy);
119 Handle<JSFunction> fun = factory->NewFunction(args);
121 fun->shared()->set_native(
true);
122 fun->shared()->DontAdaptArguments();
123 fun->shared()->set_length(1);
125 JSObject::AddProperty(isolate, fun, factory->console_context_id_symbol(),
126 handle(Smi::FromInt(context_id), isolate), NONE);
127 if (context_name->IsString()) {
128 JSObject::AddProperty(isolate, fun, factory->console_context_name_symbol(),
131 JSObject::AddProperty(isolate, target, name_string, fun, NONE);
135 BUILTIN(ConsoleContext) {
136 HandleScope scope(isolate);
138 Factory*
const factory = isolate->factory();
139 Handle<String> name = factory->InternalizeUtf8String(
"Context");
140 NewFunctionArgs arguments = NewFunctionArgs::ForFunctionWithoutCode(
141 name, isolate->sloppy_function_map(), LanguageMode::kSloppy);
142 Handle<JSFunction> cons = factory->NewFunction(arguments);
144 Handle<JSObject> prototype = factory->NewJSObject(isolate->object_function());
145 JSFunction::SetPrototype(cons, prototype);
147 Handle<JSObject> context = factory->NewJSObject(cons, TENURED);
148 DCHECK(context->IsJSObject());
149 int id = isolate->last_console_context_id() + 1;
150 isolate->set_last_console_context_id(
id);
152 #define CONSOLE_BUILTIN_SETUP(call, name) \ 153 InstallContextFunction(isolate, context, #name, Builtins::kConsole##call, \ 155 CONSOLE_METHOD_LIST(CONSOLE_BUILTIN_SETUP)
156 #undef CONSOLE_BUILTIN_SETUP 157 InstallContextFunction(isolate, context,
"time", Builtins::kConsoleTime,
id,
159 InstallContextFunction(isolate, context,
"timeEnd", Builtins::kConsoleTimeEnd,
161 InstallContextFunction(isolate, context,
"timeStamp",
162 Builtins::kConsoleTimeStamp,
id, args.at(1));
167 #undef CONSOLE_METHOD_LIST