5 #include "src/inspector/v8-console.h" 7 #include "src/base/macros.h" 8 #include "src/inspector/injected-script.h" 9 #include "src/inspector/inspected-context.h" 10 #include "src/inspector/string-util.h" 11 #include "src/inspector/v8-console-message.h" 12 #include "src/inspector/v8-debugger-agent-impl.h" 13 #include "src/inspector/v8-inspector-impl.h" 14 #include "src/inspector/v8-inspector-session-impl.h" 15 #include "src/inspector/v8-profiler-agent-impl.h" 16 #include "src/inspector/v8-runtime-agent-impl.h" 17 #include "src/inspector/v8-stack-trace-impl.h" 18 #include "src/inspector/v8-value-utils.h" 20 #include "include/v8-inspector.h" 26 String16 consoleContextToString(
28 if (consoleContext.id() == 0)
return String16();
29 return toProtocolString(isolate, consoleContext.name()) +
"#" +
30 String16::fromInteger(consoleContext.id());
37 V8InspectorImpl* inspector)
39 m_consoleContext(consoleContext),
40 m_isolate(inspector->isolate()),
41 m_context(m_isolate->GetCurrentContext()),
42 m_inspector(inspector),
43 m_contextId(InspectedContext::contextId(m_context)),
44 m_groupId(m_inspector->contextGroupId(m_contextId)) {}
46 int contextId()
const {
return m_contextId; }
47 int groupId()
const {
return m_groupId; }
49 InjectedScript* injectedScript(
int sessionId) {
50 InspectedContext* context = m_inspector->getContext(m_groupId, m_contextId);
51 if (!context)
return nullptr;
52 return context->getInjectedScript(sessionId);
55 V8InspectorSessionImpl* session(
int sessionId) {
56 return m_inspector->sessionById(m_groupId, sessionId);
59 V8ConsoleMessageStorage* consoleMessageStorage() {
60 return m_inspector->ensureConsoleMessageStorage(m_groupId);
63 void reportCall(ConsoleAPIType type) {
64 if (!m_info.Length())
return;
65 std::vector<v8::Local<v8::Value>> arguments;
66 arguments.reserve(m_info.Length());
67 for (
int i = 0;
i < m_info.Length(); ++
i) arguments.push_back(m_info[
i]);
68 reportCall(type, arguments);
71 void reportCallWithDefaultArgument(ConsoleAPIType type,
72 const String16& message) {
73 std::vector<v8::Local<v8::Value>> arguments;
74 for (
int i = 0;
i < m_info.Length(); ++
i) arguments.push_back(m_info[
i]);
75 if (!m_info.Length()) arguments.push_back(toV8String(m_isolate, message));
76 reportCall(type, arguments);
79 void reportCallAndReplaceFirstArgument(ConsoleAPIType type,
80 const String16& message) {
81 std::vector<v8::Local<v8::Value>> arguments;
82 arguments.push_back(toV8String(m_isolate, message));
83 for (
int i = 1;
i < m_info.Length(); ++
i) arguments.push_back(m_info[
i]);
84 reportCall(type, arguments);
87 void reportCallWithArgument(ConsoleAPIType type,
const String16& message) {
88 std::vector<v8::Local<v8::Value>> arguments(1,
89 toV8String(m_isolate, message));
90 reportCall(type, arguments);
93 void reportCall(ConsoleAPIType type,
95 if (!m_groupId)
return;
96 std::unique_ptr<V8ConsoleMessage> message =
97 V8ConsoleMessage::createForConsoleAPI(
98 m_context, m_contextId, m_groupId, m_inspector,
99 m_inspector->client()->currentTimeMS(), type, arguments,
100 consoleContextToString(m_isolate, m_consoleContext),
101 m_inspector->debugger()->captureStackTrace(
false));
102 consoleMessageStorage()->addMessage(std::move(message));
105 void reportDeprecatedCall(
const char*
id,
const String16& message) {
106 if (!consoleMessageStorage()->shouldReportDeprecationMessage(m_contextId,
110 std::vector<v8::Local<v8::Value>> arguments(1,
111 toV8String(m_isolate, message));
112 reportCall(ConsoleAPIType::kWarning, arguments);
115 bool firstArgToBoolean(
bool defaultValue) {
116 if (m_info.Length() < 1)
return defaultValue;
117 if (m_info[0]->IsBoolean())
return m_info[0].As<v8::Boolean>()->Value();
118 return m_info[0]->BooleanValue(m_context->GetIsolate());
121 String16 firstArgToString(
const String16& defaultValue,
122 bool allowUndefined =
true) {
123 if (m_info.Length() < 1 || (!allowUndefined && m_info[0]->IsUndefined())) {
127 v8::TryCatch tryCatch(m_context->GetIsolate());
128 if (m_info[0]->IsObject()) {
129 if (!m_info[0].As<v8::Object>()->ObjectProtoToString(m_context).ToLocal(
133 if (!m_info[0]->ToString(m_context).ToLocal(&titleValue))
136 return toProtocolString(m_context->GetIsolate(), titleValue);
140 if (m_info.Length() < 1 || !m_info[0]->IsObject())
146 if (m_info.Length() < 1 || !m_info[0]->IsFunction())
154 void forEachSession(std::function<
void(V8InspectorSessionImpl*)> callback) {
155 m_inspector->forEachSession(m_groupId, std::move(callback));
161 v8::Isolate* m_isolate;
163 V8InspectorImpl* m_inspector =
nullptr;
167 DISALLOW_COPY_AND_ASSIGN(ConsoleHelper);
174 void createBoundFunctionProperty(
177 const char* description =
nullptr,
180 toV8StringInternalized(context->GetIsolate(), name);
183 v8::ConstructorBehavior::kThrow, side_effect_type)
186 func->SetName(funcName);
189 toV8String(context->GetIsolate(), description);
192 v8::ConstructorBehavior::kThrow,
193 v8::SideEffectType::kHasNoSideEffect)
194 .ToLocal(&toStringFunction))
195 createDataProperty(context, func, toV8StringInternalized(
196 context->GetIsolate(),
"toString"),
199 createDataProperty(context, console, funcName, func);
202 enum InspectRequest { kRegular, kCopyToClipboard, kQueryObjects };
206 V8Console::V8Console(V8InspectorImpl* inspector) : m_inspector(inspector) {}
210 ConsoleHelper(info, consoleContext, m_inspector)
211 .reportCall(ConsoleAPIType::kDebug);
216 ConsoleHelper(info, consoleContext, m_inspector)
217 .reportCall(ConsoleAPIType::kError);
222 ConsoleHelper(info, consoleContext, m_inspector)
223 .reportCall(ConsoleAPIType::kInfo);
228 ConsoleHelper(info, consoleContext, m_inspector)
229 .reportCall(ConsoleAPIType::kLog);
234 ConsoleHelper(info, consoleContext, m_inspector)
235 .reportCall(ConsoleAPIType::kWarning);
240 ConsoleHelper(info, consoleContext, m_inspector)
241 .reportCall(ConsoleAPIType::kDir);
246 ConsoleHelper(info, consoleContext, m_inspector)
247 .reportCall(ConsoleAPIType::kDirXML);
252 ConsoleHelper(info, consoleContext, m_inspector)
253 .reportCall(ConsoleAPIType::kTable);
258 ConsoleHelper(info, consoleContext, m_inspector)
259 .reportCallWithDefaultArgument(ConsoleAPIType::kTrace,
260 String16(
"console.trace"));
265 ConsoleHelper(info, consoleContext, m_inspector)
266 .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroup,
267 String16(
"console.group"));
270 void V8Console::GroupCollapsed(
273 ConsoleHelper(info, consoleContext, m_inspector)
274 .reportCallWithDefaultArgument(ConsoleAPIType::kStartGroupCollapsed,
275 String16(
"console.groupCollapsed"));
280 ConsoleHelper(info, consoleContext, m_inspector)
281 .reportCallWithDefaultArgument(ConsoleAPIType::kEndGroup,
282 String16(
"console.groupEnd"));
287 ConsoleHelper helper(info, consoleContext, m_inspector);
288 if (!helper.groupId())
return;
289 m_inspector->client()->consoleClear(helper.groupId());
290 helper.reportCallWithDefaultArgument(ConsoleAPIType::kClear,
291 String16(
"console.clear"));
294 static String16 identifierFromTitleOrStackTrace(
295 const String16& title,
const ConsoleHelper& helper,
297 V8InspectorImpl* inspector) {
299 if (title.isEmpty()) {
300 std::unique_ptr<V8StackTraceImpl> stackTrace =
301 V8StackTraceImpl::capture(inspector->debugger(), helper.groupId(), 1);
302 if (stackTrace && !stackTrace->isEmpty()) {
303 identifier = toString16(stackTrace->topSourceURL()) +
":" +
304 String16::fromInteger(stackTrace->topLineNumber());
307 identifier = title +
"@";
309 identifier = consoleContextToString(inspector->isolate(), consoleContext) +
317 ConsoleHelper helper(info, consoleContext, m_inspector);
318 String16 title = helper.firstArgToString(String16(
"default"),
false);
319 String16 identifier = identifierFromTitleOrStackTrace(
320 title, helper, consoleContext, m_inspector);
323 helper.consoleMessageStorage()->count(helper.contextId(), identifier);
324 String16 countString = String16::fromInteger(count);
325 helper.reportCallWithArgument(
326 ConsoleAPIType::kCount,
327 title.isEmpty() ? countString : (title +
": " + countString));
332 ConsoleHelper helper(info, consoleContext, m_inspector);
333 String16 title = helper.firstArgToString(String16(
"default"),
false);
334 String16 identifier = identifierFromTitleOrStackTrace(
335 title, helper, consoleContext, m_inspector);
337 if (!helper.consoleMessageStorage()->countReset(helper.contextId(),
339 helper.reportCallWithArgument(ConsoleAPIType::kWarning,
340 "Count for '" + title +
"' does not exist");
346 ConsoleHelper helper(info, consoleContext, m_inspector);
347 DCHECK(!helper.firstArgToBoolean(
false));
349 std::vector<v8::Local<v8::Value>> arguments;
350 for (
int i = 1;
i < info.Length(); ++
i) arguments.push_back(info[
i]);
351 if (info.Length() < 2)
353 toV8String(m_inspector->isolate(), String16(
"console.assert")));
354 helper.reportCall(ConsoleAPIType::kAssert, arguments);
355 m_inspector->debugger()->breakProgramOnAssert(helper.groupId());
360 ConsoleHelper helper(info, consoleContext, m_inspector);
361 helper.forEachSession([&helper](V8InspectorSessionImpl* session) {
362 session->profilerAgent()->consoleProfile(
363 helper.firstArgToString(String16()));
369 ConsoleHelper helper(info, consoleContext, m_inspector);
370 helper.forEachSession([&helper](V8InspectorSessionImpl* session) {
371 session->profilerAgent()->consoleProfileEnd(
372 helper.firstArgToString(String16()));
378 bool timelinePrefix, V8InspectorImpl* inspector) {
379 ConsoleHelper helper(info, consoleContext, inspector);
380 String16 protocolTitle = helper.firstArgToString(
"default",
false);
381 if (timelinePrefix) protocolTitle =
"Timeline '" + protocolTitle +
"'";
382 const String16& timerId =
383 protocolTitle +
"@" +
384 consoleContextToString(inspector->isolate(), consoleContext);
385 if (helper.consoleMessageStorage()->hasTimer(helper.contextId(), timerId)) {
386 helper.reportCallWithArgument(
387 ConsoleAPIType::kWarning,
388 "Timer '" + protocolTitle +
"' already exists");
391 inspector->client()->consoleTime(toStringView(protocolTitle));
392 helper.consoleMessageStorage()->time(helper.contextId(), timerId);
397 bool timeLog, V8InspectorImpl* inspector) {
398 ConsoleHelper helper(info, consoleContext, inspector);
399 String16 protocolTitle = helper.firstArgToString(
"default",
false);
400 const String16& timerId =
401 protocolTitle +
"@" +
402 consoleContextToString(inspector->isolate(), consoleContext);
403 if (!helper.consoleMessageStorage()->hasTimer(helper.contextId(), timerId)) {
404 helper.reportCallWithArgument(
405 ConsoleAPIType::kWarning,
406 "Timer '" + protocolTitle +
"' does not exist");
409 inspector->client()->consoleTimeEnd(toStringView(protocolTitle));
410 String16 title = protocolTitle +
"@" +
411 consoleContextToString(inspector->isolate(), consoleContext);
415 helper.consoleMessageStorage()->timeLog(helper.contextId(), title);
418 helper.consoleMessageStorage()->timeEnd(helper.contextId(), title);
421 protocolTitle +
": " + String16::fromDouble(elapsed) +
"ms";
423 helper.reportCallAndReplaceFirstArgument(ConsoleAPIType::kLog, message);
425 helper.reportCallWithArgument(ConsoleAPIType::kTimeEnd, message);
430 timeFunction(info, consoleContext,
false, m_inspector);
435 timeEndFunction(info, consoleContext,
true, m_inspector);
440 timeEndFunction(info, consoleContext,
false, m_inspector);
445 ConsoleHelper helper(info, consoleContext, m_inspector);
446 String16 title = helper.firstArgToString(String16());
447 m_inspector->client()->consoleTimeStamp(toStringView(title));
450 void V8Console::memoryGetterCallback(
453 if (!m_inspector->client()
456 .ToLocal(&memoryValue))
461 void V8Console::memorySetterCallback(
476 if (!helper.firstArgAsObject().ToLocal(&obj))
return;
478 if (!obj->GetOwnPropertyNames(isolate->GetCurrentContext()).ToLocal(&names))
491 if (!helper.firstArgAsObject().ToLocal(&obj))
return;
494 if (!obj->GetOwnPropertyNames(context).ToLocal(&names))
return;
498 if (!names->Get(context,
i).
ToLocal(&key))
continue;
500 if (!obj->Get(context, key).ToLocal(&value))
continue;
501 createDataProperty(context, values,
i, value);
506 static void setFunctionBreakpoint(ConsoleHelper& helper,
int sessionId,
508 V8DebuggerAgentImpl::BreakpointSource source,
511 V8InspectorSessionImpl* session = helper.session(sessionId);
512 if (session ==
nullptr)
return;
513 if (!session->debuggerAgent()->enabled())
return;
515 session->debuggerAgent()->setBreakpointFor(
function, condition, source);
517 session->debuggerAgent()->removeBreakpointFor(
function, source);
521 void V8Console::debugFunctionCallback(
527 if (!helper.firstArgAsFunction().ToLocal(&
function))
return;
528 if (args.Length() > 1 && args[1]->IsString()) {
531 setFunctionBreakpoint(helper, sessionId,
function,
532 V8DebuggerAgentImpl::DebugCommandBreakpointSource,
536 void V8Console::undebugFunctionCallback(
541 if (!helper.firstArgAsFunction().ToLocal(&
function))
return;
542 setFunctionBreakpoint(helper, sessionId,
function,
543 V8DebuggerAgentImpl::DebugCommandBreakpointSource,
547 void V8Console::monitorFunctionCallback(
552 if (!helper.firstArgAsFunction().ToLocal(&
function))
return;
555 name = function->GetInferredName();
556 String16 functionName =
557 toProtocolStringWithTypeCheck(info.
GetIsolate(), name);
558 String16Builder builder;
559 builder.append(
"console.log(\"function ");
560 if (functionName.isEmpty())
561 builder.append(
"(anonymous function)");
563 builder.append(functionName);
565 " called\" + (arguments.length > 0 ? \" with arguments: \" + " 566 "Array.prototype.join.call(arguments, \", \") : \"\")) && false");
567 setFunctionBreakpoint(helper, sessionId,
function,
568 V8DebuggerAgentImpl::MonitorCommandBreakpointSource,
569 toV8String(info.
GetIsolate(), builder.toString()),
573 void V8Console::unmonitorFunctionCallback(
578 if (!helper.firstArgAsFunction().ToLocal(&
function))
return;
579 setFunctionBreakpoint(helper, sessionId,
function,
580 V8DebuggerAgentImpl::MonitorCommandBreakpointSource,
584 void V8Console::lastEvaluationResultCallback(
588 InjectedScript* injectedScript = helper.injectedScript(sessionId);
589 if (!injectedScript)
return;
590 info.
GetReturnValue().Set(injectedScript->lastEvaluationResult());
595 InspectRequest request, V8InspectorImpl* inspector) {
600 InjectedScript* injectedScript = helper.injectedScript(sessionId);
601 if (!injectedScript)
return;
602 std::unique_ptr<protocol::Runtime::RemoteObject> wrappedObject;
603 protocol::Response response = injectedScript->wrapObject(
604 value,
"", WrapMode::kNoPreview, &wrappedObject);
605 if (!response.isSuccess())
return;
607 std::unique_ptr<protocol::DictionaryValue> hints =
608 protocol::DictionaryValue::create();
609 if (request == kCopyToClipboard) {
610 hints->setBoolean(
"copyToClipboard",
true);
611 }
else if (request == kQueryObjects) {
612 hints->setBoolean(
"queryObjects",
true);
614 if (V8InspectorSessionImpl* session = helper.session(sessionId)) {
615 session->runtimeAgent()->inspect(std::move(wrappedObject),
622 if (info.
Length() < 1)
return;
623 inspectImpl(info, info[0], sessionId, kRegular, m_inspector);
628 if (info.
Length() < 1)
return;
629 inspectImpl(info, info[0], sessionId, kCopyToClipboard, m_inspector);
632 void V8Console::queryObjectsCallback(
634 if (info.
Length() < 1)
return;
636 if (arg->IsFunction()) {
638 v8::TryCatch tryCatch(isolate);
641 ->Get(isolate->GetCurrentContext(),
642 toV8StringInternalized(isolate,
"prototype"))
643 .ToLocal(&prototype) &&
647 if (tryCatch.HasCaught()) {
652 inspectImpl(info, arg, sessionId, kQueryObjects, m_inspector);
656 int sessionId,
unsigned num) {
657 DCHECK_GT(V8InspectorSessionImpl::kInspectedObjectBufferSize, num);
660 if (V8InspectorSessionImpl* session = helper.session(sessionId)) {
661 V8InspectorSession::Inspectable*
object = session->inspectedObject(num);
664 info.
GetReturnValue().Set(object->get(isolate->GetCurrentContext()));
672 v8::Isolate* isolate = context->GetIsolate();
674 console->SetAccessorProperty(
675 toV8StringInternalized(isolate,
"memory"),
677 context, &V8Console::call<&V8Console::memoryGetterCallback>, data, 0,
678 v8::ConstructorBehavior::kThrow, v8::SideEffectType::kHasNoSideEffect)
681 &V8Console::call<&V8Console::memorySetterCallback>,
682 data, 0, v8::ConstructorBehavior::kThrow)
684 static_cast<v8::PropertyAttribute>(
v8::None), v8::DEFAULT);
689 v8::Isolate* isolate = context->GetIsolate();
690 v8::MicrotasksScope microtasksScope(isolate,
691 v8::MicrotasksScope::kDoNotRunMicrotasks);
695 commandLineAPI->
SetPrototype(context, v8::Null(isolate)).FromMaybe(
false);
701 *
static_cast<CommandLineAPIData*
>(data->GetContents().Data()) =
702 CommandLineAPIData(
this, sessionId);
703 createBoundFunctionProperty(context, commandLineAPI, data,
"dir",
704 &V8Console::call<&V8Console::Dir>,
705 "function dir(value) { [Command Line API] }");
706 createBoundFunctionProperty(context, commandLineAPI, data,
"dirxml",
707 &V8Console::call<&V8Console::DirXml>,
708 "function dirxml(value) { [Command Line API] }");
709 createBoundFunctionProperty(context, commandLineAPI, data,
"profile",
710 &V8Console::call<&V8Console::Profile>,
711 "function profile(title) { [Command Line API] }");
712 createBoundFunctionProperty(
713 context, commandLineAPI, data,
"profileEnd",
714 &V8Console::call<&V8Console::ProfileEnd>,
715 "function profileEnd(title) { [Command Line API] }");
716 createBoundFunctionProperty(context, commandLineAPI, data,
"clear",
717 &V8Console::call<&V8Console::Clear>,
718 "function clear() { [Command Line API] }");
719 createBoundFunctionProperty(
720 context, commandLineAPI, data,
"table",
721 &V8Console::call<&V8Console::Table>,
722 "function table(data, [columns]) { [Command Line API] }");
724 createBoundFunctionProperty(context, commandLineAPI, data,
"keys",
725 &V8Console::call<&V8Console::keysCallback>,
726 "function keys(object) { [Command Line API] }",
727 v8::SideEffectType::kHasNoSideEffect);
728 createBoundFunctionProperty(context, commandLineAPI, data,
"values",
729 &V8Console::call<&V8Console::valuesCallback>,
730 "function values(object) { [Command Line API] }",
731 v8::SideEffectType::kHasNoSideEffect);
732 createBoundFunctionProperty(
733 context, commandLineAPI, data,
"debug",
734 &V8Console::call<&V8Console::debugFunctionCallback>,
735 "function debug(function, condition) { [Command Line API] }");
736 createBoundFunctionProperty(
737 context, commandLineAPI, data,
"undebug",
738 &V8Console::call<&V8Console::undebugFunctionCallback>,
739 "function undebug(function) { [Command Line API] }");
740 createBoundFunctionProperty(
741 context, commandLineAPI, data,
"monitor",
742 &V8Console::call<&V8Console::monitorFunctionCallback>,
743 "function monitor(function) { [Command Line API] }");
744 createBoundFunctionProperty(
745 context, commandLineAPI, data,
"unmonitor",
746 &V8Console::call<&V8Console::unmonitorFunctionCallback>,
747 "function unmonitor(function) { [Command Line API] }");
748 createBoundFunctionProperty(
749 context, commandLineAPI, data,
"inspect",
750 &V8Console::call<&V8Console::inspectCallback>,
751 "function inspect(object) { [Command Line API] }");
752 createBoundFunctionProperty(context, commandLineAPI, data,
"copy",
753 &V8Console::call<&V8Console::copyCallback>,
754 "function copy(value) { [Command Line API] }");
755 createBoundFunctionProperty(
756 context, commandLineAPI, data,
"queryObjects",
757 &V8Console::call<&V8Console::queryObjectsCallback>,
758 "function queryObjects(constructor) { [Command Line API] }");
759 createBoundFunctionProperty(
760 context, commandLineAPI, data,
"$_",
761 &V8Console::call<&V8Console::lastEvaluationResultCallback>,
nullptr,
762 v8::SideEffectType::kHasNoSideEffect);
763 createBoundFunctionProperty(context, commandLineAPI, data,
"$0",
764 &V8Console::call<&V8Console::inspectedObject0>,
765 nullptr, v8::SideEffectType::kHasNoSideEffect);
766 createBoundFunctionProperty(context, commandLineAPI, data,
"$1",
767 &V8Console::call<&V8Console::inspectedObject1>,
768 nullptr, v8::SideEffectType::kHasNoSideEffect);
769 createBoundFunctionProperty(context, commandLineAPI, data,
"$2",
770 &V8Console::call<&V8Console::inspectedObject2>,
771 nullptr, v8::SideEffectType::kHasNoSideEffect);
772 createBoundFunctionProperty(context, commandLineAPI, data,
"$3",
773 &V8Console::call<&V8Console::inspectedObject3>,
774 nullptr, v8::SideEffectType::kHasNoSideEffect);
775 createBoundFunctionProperty(context, commandLineAPI, data,
"$4",
776 &V8Console::call<&V8Console::inspectedObject4>,
777 nullptr, v8::SideEffectType::kHasNoSideEffect);
779 m_inspector->client()->installAdditionalCommandLineAPI(context,
781 return commandLineAPI;
784 static bool isCommandLineAPIGetter(
const String16& name) {
785 if (name.length() != 2)
return false;
787 return name[0] ==
'$' &&
788 ((name[1] >=
'0' && name[1] <=
'4') || name[1] ==
'_');
791 void V8Console::CommandLineAPIScope::accessorGetterCallback(
793 CommandLineAPIScope* scope =
static_cast<CommandLineAPIScope*
>(
798 if (scope->m_cleanup) {
799 bool removed = info.
Holder()->Delete(context, name).FromMaybe(
false);
807 if (!commandLineAPI->Get(context, name).
ToLocal(&value))
return;
808 if (isCommandLineAPIGetter(
809 toProtocolStringWithTypeCheck(info.
GetIsolate(), name))) {
810 DCHECK(value->IsFunction());
811 v8::MicrotasksScope microtasks(info.
GetIsolate(),
812 v8::MicrotasksScope::kDoNotRunMicrotasks);
814 ->Call(context, commandLineAPI, 0,
nullptr)
822 void V8Console::CommandLineAPIScope::accessorSetterCallback(
825 CommandLineAPIScope* scope =
static_cast<CommandLineAPIScope*
>(
828 if (!info.
Holder()->Delete(context, name).FromMaybe(
false))
return;
829 if (!info.
Holder()->CreateDataProperty(context, name, value).FromMaybe(
false))
832 scope->m_installedMethods->Delete(context, name).FromMaybe(
false);
837 V8Console::CommandLineAPIScope::CommandLineAPIScope(
840 : m_context(context),
841 m_commandLineAPI(commandLineAPI),
843 m_installedMethods(
v8::Set::New(context->GetIsolate())),
845 v8::MicrotasksScope microtasksScope(context->GetIsolate(),
846 v8::MicrotasksScope::kDoNotRunMicrotasks);
848 if (!m_commandLineAPI->GetOwnPropertyNames(context).ToLocal(&names))
return;
850 v8::External::New(context->GetIsolate(),
this);
853 if (!names->Get(context,
i).ToLocal(&name) || !name->IsName())
continue;
854 if (m_global->Has(context, name).FromMaybe(
true))
continue;
855 if (!m_installedMethods->Add(context, name).ToLocal(&m_installedMethods))
859 CommandLineAPIScope::accessorGetterCallback,
860 CommandLineAPIScope::accessorSetterCallback,
862 v8::SideEffectType::kHasNoSideEffect)
864 bool removed = m_installedMethods->Delete(context, name).FromMaybe(
false);
872 V8Console::CommandLineAPIScope::~CommandLineAPIScope() {
873 v8::MicrotasksScope microtasksScope(m_context->GetIsolate(),
874 v8::MicrotasksScope::kDoNotRunMicrotasks);
879 if (!names->Get(m_context,
i).
ToLocal(&name) || !name->IsName())
continue;
880 if (name->IsString()) {
882 bool success = m_global
V8_INLINE int Length() const
static V8_INLINE Local< T > Cast(Local< S > that)
Local< Array > AsArray() const
static Local< Array > New(Isolate *isolate, int length=0)
V8_INLINE Isolate * GetIsolate() const
static MaybeLocal< Function > New(Local< Context > context, FunctionCallback callback, Local< Value > data=Local< Value >(), int length=0, ConstructorBehavior behavior=ConstructorBehavior::kAllow, SideEffectType side_effect_type=SideEffectType::kHasSideEffect)
V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local< S > *out) const
V8_WARN_UNUSED_RESULT Maybe< bool > SetPrototype(Local< Context > context, Local< Value > prototype)
static Local< ArrayBuffer > New(Isolate *isolate, size_t byte_length)
V8_INLINE Local< Value > Data() const
V8_INLINE ReturnValue< T > GetReturnValue() const
V8_INLINE Local< Value > Data() const
Local< Value > GetBoundFunction() const
V8_INLINE Local< Object > Holder() const
V8_INLINE ReturnValue< T > GetReturnValue() const
V8_WARN_UNUSED_RESULT MaybeLocal< Value > GetOwnPropertyDescriptor(Local< Context > context, Local< Name > key)
V8_INLINE Isolate * GetIsolate() const