Skip to content
Permalink
Browse files
[JSC] Reduce use of CallFrame::deprecatedVM
https://bugs.webkit.org/show_bug.cgi?id=239326

Reviewed by Devin Rousso.

Reduce use of CallFrame::deprecatedVM, mainly in inspector related code to eventually remove CallFrame::deprecatedVM.

* Source/JavaScriptCore/debugger/Debugger.cpp:
(JSC::Debugger::evaluateBreakpointCondition):
(JSC::Debugger::evaluateBreakpointActions):
(JSC::Debugger::exceptionOrCaughtValue):
* Source/JavaScriptCore/debugger/DebuggerCallFrame.cpp:
(JSC::DebuggerCallFrame::globalObject):
(JSC::DebuggerCallFrame::functionName const):
(JSC::DebuggerCallFrame::scope):
(JSC::DebuggerCallFrame::type const):
(JSC::DebuggerCallFrame::evaluateWithScopeExtension):
(JSC::DebuggerCallFrame::deprecatedVMEntryGlobalObject const): Deleted.
* Source/JavaScriptCore/debugger/DebuggerCallFrame.h:
* Source/JavaScriptCore/inspector/JSJavaScriptCallFrame.cpp:
(Inspector::JSJavaScriptCallFrame::evaluateWithScopeExtension):
(Inspector::JSJavaScriptCallFrame::scopeDescriptions):
(Inspector::JSJavaScriptCallFrame::functionName const):
(Inspector::JSJavaScriptCallFrame::scopeChain const):
(Inspector::JSJavaScriptCallFrame::type const):
* Source/JavaScriptCore/inspector/JavaScriptCallFrame.h:
(Inspector::JavaScriptCallFrame::functionName const):
(Inspector::JavaScriptCallFrame::type const):
(Inspector::JavaScriptCallFrame::scopeChain const):
(Inspector::JavaScriptCallFrame::evaluateWithScopeExtension const):
(Inspector::JavaScriptCallFrame::deprecatedVMEntryGlobalObject const): Deleted.
* Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp:
(Inspector::InspectorDebuggerAgent::debuggerScopeExtensionObject):
(Inspector::InspectorDebuggerAgent::didPause):
* Source/JavaScriptCore/interpreter/Interpreter.cpp:
(JSC::Interpreter::debug):

Canonical link: https://commits.webkit.org/249661@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@292891 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Constellation committed Apr 14, 2022
1 parent e253600 commit c1fc988fa0bb1a85b9d52ac93f23badde6951907
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 49 deletions.
@@ -1,3 +1,42 @@
2022-04-14 Yusuke Suzuki <ysuzuki@apple.com>

[JSC] Reduce use of CallFrame::deprecatedVM
https://bugs.webkit.org/show_bug.cgi?id=239326

Reviewed by Devin Rousso.

Reduce use of CallFrame::deprecatedVM, mainly in inspector related code to eventually remove CallFrame::deprecatedVM.

* debugger/Debugger.cpp:
(JSC::Debugger::evaluateBreakpointCondition):
(JSC::Debugger::evaluateBreakpointActions):
(JSC::Debugger::exceptionOrCaughtValue):
* debugger/DebuggerCallFrame.cpp:
(JSC::DebuggerCallFrame::globalObject):
(JSC::DebuggerCallFrame::functionName const):
(JSC::DebuggerCallFrame::scope):
(JSC::DebuggerCallFrame::type const):
(JSC::DebuggerCallFrame::evaluateWithScopeExtension):
(JSC::DebuggerCallFrame::deprecatedVMEntryGlobalObject const): Deleted.
* debugger/DebuggerCallFrame.h:
* inspector/JSJavaScriptCallFrame.cpp:
(Inspector::JSJavaScriptCallFrame::evaluateWithScopeExtension):
(Inspector::JSJavaScriptCallFrame::scopeDescriptions):
(Inspector::JSJavaScriptCallFrame::functionName const):
(Inspector::JSJavaScriptCallFrame::scopeChain const):
(Inspector::JSJavaScriptCallFrame::type const):
* inspector/JavaScriptCallFrame.h:
(Inspector::JavaScriptCallFrame::functionName const):
(Inspector::JavaScriptCallFrame::type const):
(Inspector::JavaScriptCallFrame::scopeChain const):
(Inspector::JavaScriptCallFrame::evaluateWithScopeExtension const):
(Inspector::JavaScriptCallFrame::deprecatedVMEntryGlobalObject const): Deleted.
* inspector/agents/InspectorDebuggerAgent.cpp:
(Inspector::InspectorDebuggerAgent::debuggerScopeExtensionObject):
(Inspector::InspectorDebuggerAgent::didPause):
* interpreter/Interpreter.cpp:
(JSC::Interpreter::debug):

2022-04-14 Alexey Shvayka <ashvayka@apple.com>

InternalFunction::createSubclassStructure() should use base object's global object
@@ -607,14 +607,15 @@ bool Debugger::evaluateBreakpointCondition(Breakpoint& breakpoint, JSGlobalObjec
ASSERT(m_isPaused);
ASSERT(isAttached(globalObject));

VM& vm = globalObject->vm();
const String& condition = breakpoint.condition();
if (condition.isEmpty())
return true;

NakedPtr<Exception> exception;
DebuggerCallFrame& debuggerCallFrame = currentDebuggerCallFrame();
JSObject* scopeExtensionObject = m_client ? m_client->debuggerScopeExtensionObject(*this, globalObject, debuggerCallFrame) : nullptr;
JSValue result = debuggerCallFrame.evaluateWithScopeExtension(condition, scopeExtensionObject, exception);
JSValue result = debuggerCallFrame.evaluateWithScopeExtension(vm, condition, scopeExtensionObject, exception);

// We can lose the debugger while executing JavaScript.
if (!m_currentCallFrame)
@@ -633,6 +634,8 @@ void Debugger::evaluateBreakpointActions(Breakpoint& breakpoint, JSGlobalObject*
ASSERT(m_isPaused);
ASSERT(isAttached(globalObject));

VM& vm = globalObject->vm();

m_currentProbeBatchId++;

for (const auto& action : breakpoint.actions()) {
@@ -644,16 +647,16 @@ void Debugger::evaluateBreakpointActions(Breakpoint& breakpoint, JSGlobalObject*
switch (action.type) {
case Breakpoint::Action::Type::Log:
dispatchFunctionToObservers([&] (Observer& observer) {
observer.breakpointActionLog(debuggerCallFrame.globalObject(), action.data);
observer.breakpointActionLog(debuggerCallFrame.globalObject(vm), action.data);
});
break;

case Breakpoint::Action::Type::Evaluate: {
NakedPtr<Exception> exception;
JSObject* scopeExtensionObject = m_client ? m_client->debuggerScopeExtensionObject(*this, globalObject, debuggerCallFrame) : nullptr;
debuggerCallFrame.evaluateWithScopeExtension(action.data, scopeExtensionObject, exception);
debuggerCallFrame.evaluateWithScopeExtension(vm, action.data, scopeExtensionObject, exception);
if (exception)
reportException(debuggerCallFrame.globalObject(), exception);
reportException(debuggerCallFrame.globalObject(vm), exception);
break;
}

@@ -666,8 +669,8 @@ void Debugger::evaluateBreakpointActions(Breakpoint& breakpoint, JSGlobalObject*
case Breakpoint::Action::Type::Probe: {
NakedPtr<Exception> exception;
JSObject* scopeExtensionObject = m_client ? m_client->debuggerScopeExtensionObject(*this, globalObject, debuggerCallFrame) : nullptr;
JSValue result = debuggerCallFrame.evaluateWithScopeExtension(action.data, scopeExtensionObject, exception);
JSC::JSGlobalObject* debuggerGlobalObject = debuggerCallFrame.globalObject();
JSValue result = debuggerCallFrame.evaluateWithScopeExtension(vm, action.data, scopeExtensionObject, exception);
JSC::JSGlobalObject* debuggerGlobalObject = debuggerCallFrame.globalObject(vm);
if (exception)
reportException(debuggerGlobalObject, exception);

@@ -1026,8 +1029,9 @@ JSC::JSValue Debugger::exceptionOrCaughtValue(JSC::JSGlobalObject* globalObject)
if (reasonForPause() == PausedForException)
return currentException();

VM& vm = globalObject->vm();
for (RefPtr<DebuggerCallFrame> frame = &currentDebuggerCallFrame(); frame; frame = frame->callerFrame()) {
DebuggerScope& scope = *frame->scope();
DebuggerScope& scope = *frame->scope(vm);
if (scope.isCatchScope())
return scope.caughtValue(globalObject);
}
@@ -111,18 +111,9 @@ RefPtr<DebuggerCallFrame> DebuggerCallFrame::callerFrame()
return m_caller;
}

JSGlobalObject* DebuggerCallFrame::globalObject()
JSGlobalObject* DebuggerCallFrame::globalObject(VM& vm)
{
return scope()->globalObject();
}

JSC::JSGlobalObject* DebuggerCallFrame::deprecatedVMEntryGlobalObject() const
{
ASSERT(isValid());
if (!isValid())
return nullptr;
VM& vm = m_validMachineFrame->deprecatedVM();
return vm.deprecatedVMEntryGlobalObject(m_validMachineFrame->lexicalGlobalObject(vm));
return scope(vm)->globalObject();
}

SourceID DebuggerCallFrame::sourceID() const
@@ -135,13 +126,12 @@ SourceID DebuggerCallFrame::sourceID() const
return sourceIDForCallFrame(m_validMachineFrame);
}

String DebuggerCallFrame::functionName() const
String DebuggerCallFrame::functionName(VM& vm) const
{
ASSERT(isValid());
if (!isValid())
return String();

VM& vm = m_validMachineFrame->deprecatedVM();
if (isTailDeleted()) {
if (JSFunction* func = jsDynamicCast<JSFunction*>(vm, m_shadowChickenFrame.callee))
return func->calculatedDisplayName(vm);
@@ -151,14 +141,13 @@ String DebuggerCallFrame::functionName() const
return m_validMachineFrame->friendlyFunctionName();
}

DebuggerScope* DebuggerCallFrame::scope()
DebuggerScope* DebuggerCallFrame::scope(VM& vm)
{
ASSERT(isValid());
if (!isValid())
return nullptr;

if (!m_scope) {
VM& vm = m_validMachineFrame->deprecatedVM();
JSScope* scope;
CodeBlock* codeBlock = m_validMachineFrame->codeBlock();
if (isTailDeleted())
@@ -175,7 +164,7 @@ DebuggerScope* DebuggerCallFrame::scope()
return m_scope.get();
}

DebuggerCallFrame::Type DebuggerCallFrame::type() const
DebuggerCallFrame::Type DebuggerCallFrame::type(VM& vm) const
{
ASSERT(isValid());
if (!isValid())
@@ -184,7 +173,7 @@ DebuggerCallFrame::Type DebuggerCallFrame::type() const
if (isTailDeleted())
return FunctionType;

if (jsDynamicCast<JSFunction*>(m_validMachineFrame->deprecatedVM(), m_validMachineFrame->jsCallee()))
if (jsDynamicCast<JSFunction*>(vm, m_validMachineFrame->jsCallee()))
return FunctionType;

return ProgramType;
@@ -216,7 +205,7 @@ JSValue DebuggerCallFrame::thisValue(VM& vm) const
}

// Evaluate some JavaScript code in the scope of this frame.
JSValue DebuggerCallFrame::evaluateWithScopeExtension(const String& script, JSObject* scopeExtensionObject, NakedPtr<Exception>& exception)
JSValue DebuggerCallFrame::evaluateWithScopeExtension(VM& vm, const String& script, JSObject* scopeExtensionObject, NakedPtr<Exception>& exception)
{
CallFrame* callFrame = nullptr;
CodeBlock* codeBlock = nullptr;
@@ -242,7 +231,6 @@ JSValue DebuggerCallFrame::evaluateWithScopeExtension(const String& script, JSOb
if (!callFrame || !codeBlock)
return jsUndefined();

VM& vm = callFrame->deprecatedVM();
JSLockHolder lock(vm);
auto catchScope = DECLARE_CATCH_SCOPE(vm);

@@ -260,7 +248,7 @@ JSValue DebuggerCallFrame::evaluateWithScopeExtension(const String& script, JSOb

TDZEnvironment variablesUnderTDZ;
PrivateNameEnvironment privateNameEnvironment;
JSScope::collectClosureVariablesUnderTDZ(scope()->jsScope(), variablesUnderTDZ, privateNameEnvironment);
JSScope::collectClosureVariablesUnderTDZ(scope(vm)->jsScope(), variablesUnderTDZ, privateNameEnvironment);

ECMAMode ecmaMode = codeBlock->ownerExecutable()->isInStrictContext() ? ECMAMode::strict() : ECMAMode::sloppy();
auto* eval = DirectEvalExecutable::create(globalObject, makeSource(script, callFrame->callerSourceOrigin(vm)), codeBlock->unlinkedCodeBlock()->derivedContextType(), codeBlock->unlinkedCodeBlock()->needsClassFieldInitializer(), codeBlock->unlinkedCodeBlock()->privateBrandRequirement(), codeBlock->unlinkedCodeBlock()->isArrowFunction(), codeBlock->ownerExecutable()->isInsideOrdinaryFunction(), evalContextType, &variablesUnderTDZ, &privateNameEnvironment, ecmaMode);
@@ -275,7 +263,7 @@ JSValue DebuggerCallFrame::evaluateWithScopeExtension(const String& script, JSOb
globalObject->setGlobalScopeExtension(JSWithScope::create(vm, globalObject, ignoredPreviousScope, scopeExtensionObject));
}

JSValue result = vm.interpreter->execute(eval, globalObject, debuggerCallFrame->thisValue(vm), debuggerCallFrame->scope()->jsScope());
JSValue result = vm.interpreter->execute(eval, globalObject, debuggerCallFrame->thisValue(vm), debuggerCallFrame->scope(vm)->jsScope());
if (UNLIKELY(catchScope.exception())) {
exception = catchScope.exception();
catchScope.clearException();
@@ -48,21 +48,20 @@ class DebuggerCallFrame : public RefCounted<DebuggerCallFrame> {
static Ref<DebuggerCallFrame> create(VM&, CallFrame*);

JS_EXPORT_PRIVATE RefPtr<DebuggerCallFrame> callerFrame();
JSGlobalObject* globalObject();
JSGlobalObject* globalObject(VM&);
JS_EXPORT_PRIVATE SourceID sourceID() const;

// line and column are in base 0 e.g. the first line is line 0.
int line() const { return m_position.m_line.zeroBasedInt(); }
int column() const { return m_position.m_column.zeroBasedInt(); }
JS_EXPORT_PRIVATE const TextPosition& position() const { return m_position; }

JS_EXPORT_PRIVATE JSGlobalObject* deprecatedVMEntryGlobalObject() const;
JS_EXPORT_PRIVATE DebuggerScope* scope();
JS_EXPORT_PRIVATE String functionName() const;
JS_EXPORT_PRIVATE Type type() const;
JS_EXPORT_PRIVATE DebuggerScope* scope(VM&);
JS_EXPORT_PRIVATE String functionName(VM&) const;
JS_EXPORT_PRIVATE Type type(VM&) const;
JS_EXPORT_PRIVATE JSValue thisValue(VM&) const;

JSValue evaluateWithScopeExtension(const String&, JSObject* scopeExtensionObject, NakedPtr<Exception>&);
JSValue evaluateWithScopeExtension(VM&, const String&, JSObject* scopeExtensionObject, NakedPtr<Exception>&);

bool isValid() const { return !!m_validMachineFrame || isTailDeleted(); }
JS_EXPORT_PRIVATE void invalidate();
@@ -85,7 +85,7 @@ JSValue JSJavaScriptCallFrame::evaluateWithScopeExtension(JSGlobalObject* global

NakedPtr<Exception> exception;
JSObject* scopeExtension = callFrame->argument(1).getObject();
JSValue result = impl().evaluateWithScopeExtension(script, scopeExtension, exception);
JSValue result = impl().evaluateWithScopeExtension(vm, script, scopeExtension, exception);
if (exception)
throwException(globalObject, scope, exception);

@@ -130,7 +130,7 @@ JSValue JSJavaScriptCallFrame::scopeDescriptions(JSGlobalObject* globalObject)
VM& vm = globalObject->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);

DebuggerScope* scopeChain = impl().scopeChain();
DebuggerScope* scopeChain = impl().scopeChain(vm);
if (!scopeChain)
return jsUndefined();

@@ -173,18 +173,19 @@ JSValue JSJavaScriptCallFrame::column(JSGlobalObject*) const

JSValue JSJavaScriptCallFrame::functionName(JSGlobalObject* globalObject) const
{
return jsString(globalObject->vm(), impl().functionName());
VM& vm = globalObject->vm();
return jsString(vm, impl().functionName(vm));
}

JSValue JSJavaScriptCallFrame::scopeChain(JSGlobalObject* globalObject) const
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);

if (!impl().scopeChain())
if (!impl().scopeChain(vm))
return jsNull();

DebuggerScope* scopeChain = impl().scopeChain();
DebuggerScope* scopeChain = impl().scopeChain(vm);
DebuggerScope::iterator iter = scopeChain->begin();
DebuggerScope::iterator end = scopeChain->end();

@@ -217,7 +218,7 @@ JSValue JSJavaScriptCallFrame::isTailDeleted(JSC::JSGlobalObject*) const
JSValue JSJavaScriptCallFrame::type(JSGlobalObject* globalObject) const
{
VM& vm = globalObject->vm();
switch (impl().type()) {
switch (impl().type(vm)) {
case DebuggerCallFrame::FunctionType:
return jsNontrivialString(vm, "function"_s);
case DebuggerCallFrame::ProgramType:
@@ -46,14 +46,13 @@ class JavaScriptCallFrame : public RefCounted<JavaScriptCallFrame> {
int line() const { return m_debuggerCallFrame->line(); }
int column() const { return m_debuggerCallFrame->column(); }

String functionName() const { return m_debuggerCallFrame->functionName(); }
JSC::DebuggerCallFrame::Type type() const { return m_debuggerCallFrame->type(); }
JSC::DebuggerScope* scopeChain() const { return m_debuggerCallFrame->scope(); }
JSC::JSGlobalObject* deprecatedVMEntryGlobalObject() const { return m_debuggerCallFrame->deprecatedVMEntryGlobalObject(); }
String functionName(JSC::VM& vm) const { return m_debuggerCallFrame->functionName(vm); }
JSC::DebuggerCallFrame::Type type(JSC::VM& vm) const { return m_debuggerCallFrame->type(vm); }
JSC::DebuggerScope* scopeChain(JSC::VM& vm) const { return m_debuggerCallFrame->scope(vm); }
bool isTailDeleted() const { return m_debuggerCallFrame->isTailDeleted(); }

JSC::JSValue thisValue(JSC::VM& vm) const { return m_debuggerCallFrame->thisValue(vm); }
JSC::JSValue evaluateWithScopeExtension(const String& script, JSC::JSObject* scopeExtension, NakedPtr<JSC::Exception>& exception) const { return m_debuggerCallFrame->evaluateWithScopeExtension(script, scopeExtension, exception); }
JSC::JSValue evaluateWithScopeExtension(JSC::VM& vm, const String& script, JSC::JSObject* scopeExtension, NakedPtr<JSC::Exception>& exception) const { return m_debuggerCallFrame->evaluateWithScopeExtension(vm, script, scopeExtension, exception); }

private:
JavaScriptCallFrame(Ref<JSC::DebuggerCallFrame>&&);
@@ -1127,7 +1127,7 @@ JSC::JSObject* InspectorDebuggerAgent::debuggerScopeExtensionObject(JSC::Debugge
if (injectedScript.hasNoValue())
return JSC::Debugger::Client::debuggerScopeExtensionObject(debugger, globalObject, debuggerCallFrame);

auto* debuggerGlobalObject = debuggerCallFrame.scope()->globalObject();
auto* debuggerGlobalObject = debuggerCallFrame.scope(globalObject->vm())->globalObject();
auto callFrame = toJS(debuggerGlobalObject, debuggerGlobalObject, JavaScriptCallFrame::create(debuggerCallFrame).ptr());
return injectedScript.createCommandLineAPIObject(callFrame);
}
@@ -1203,7 +1203,7 @@ void InspectorDebuggerAgent::didPause(JSC::JSGlobalObject* globalObject, JSC::De
ASSERT(!m_pausedGlobalObject);
m_pausedGlobalObject = globalObject;

auto* debuggerGlobalObject = debuggerCallFrame.scope()->globalObject();
auto* debuggerGlobalObject = debuggerCallFrame.scope(globalObject->vm())->globalObject();
m_currentCallStack = { m_pausedGlobalObject->vm(), toJS(debuggerGlobalObject, debuggerGlobalObject, JavaScriptCallFrame::create(debuggerCallFrame).ptr()) };

InjectedScript injectedScript = m_injectedScriptManager.injectedScriptFor(m_pausedGlobalObject);
@@ -1417,7 +1417,7 @@ JSValue Interpreter::executeModuleProgram(JSModuleRecord* record, ModuleProgramE

NEVER_INLINE void Interpreter::debug(CallFrame* callFrame, DebugHookType debugHookType)
{
VM& vm = callFrame->deprecatedVM();
VM& vm = m_vm;
DeferTermination deferScope(vm);
auto scope = DECLARE_CATCH_SCOPE(vm);

@@ -1,3 +1,13 @@
2022-04-14 Yusuke Suzuki <ysuzuki@apple.com>

[JSC] Reduce use of CallFrame::deprecatedVM
https://bugs.webkit.org/show_bug.cgi?id=239326

Reviewed by Devin Rousso.

* WebView/WebScriptDebugger.mm:
(WebScriptDebugger::handlePause):

2022-04-13 Chris Dumez <cdumez@apple.com>

Replace calls to substring(0, x) with the more concise left(x)
@@ -126,11 +126,12 @@ - (WebScriptCallFrame *)_initWithGlobalObject:(WebScriptObject *)globalObj funct

m_callingDelegate = true;

JSC::VM& vm = globalObject->vm();
WebFrame *webFrame = toWebFrame(globalObject);
WebView *webView = [webFrame webView];
JSC::DebuggerCallFrame& debuggerCallFrame = currentDebuggerCallFrame();
JSC::JSValue exceptionValue = currentException();
String functionName = debuggerCallFrame.functionName();
String functionName = debuggerCallFrame.functionName(vm);
RetainPtr<WebScriptCallFrame> webCallFrame = adoptNS([[WebScriptCallFrame alloc] _initWithGlobalObject:core(webFrame)->script().windowScriptObject() functionName:functionName exceptionValue:exceptionValue]);

WebScriptDebugDelegateImplementationCache* cache = WebViewGetScriptDebugDelegateImplementations(webView);

0 comments on commit c1fc988

Please sign in to comment.