Skip to content

Commit

Permalink
Support debugging non-private builtin functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Nov 6, 2024
1 parent 8ac9b8c commit 737c1a9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ BytecodeGenerator::BytecodeGenerator(VM& vm, FunctionNode* functionNode, Unlinke
, m_ecmaMode(ECMAMode::fromBool(functionNode->isStrictMode()))
, m_derivedContextType(codeBlock->derivedContextType())
{
#if USE(BUN_JSC_ADDITIONS)
m_isPrivateBuiltinFunction = m_isBuiltinFunction && (!m_scopeNode->source().provider() || !m_scopeNode->source().provider()->sourceURL());
#endif
ECMAMode ecmaMode = m_ecmaMode;
pushPrivateAccessNames(parentPrivateNameEnvironment);

Expand Down
12 changes: 10 additions & 2 deletions Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ namespace JSC {
if (!divot || !divotStart || !divotEnd)
return;

if (m_isBuiltinFunction)
if (isPrivateBuiltinFunction())
return;

unsigned sourceOffset = m_scopeNode->source().startOffset();
Expand Down Expand Up @@ -1072,7 +1072,7 @@ namespace JSC {

bool shouldBeConcernedWithCompletionValue() const { return !m_defaultAllowCallIgnoreResultOptimization; }

bool shouldEmitDebugHooks() const { return m_codeGenerationMode.contains(CodeGenerationMode::Debugger) && !m_isBuiltinFunction; }
bool shouldEmitDebugHooks() const { return m_codeGenerationMode.contains(CodeGenerationMode::Debugger) && !isPrivateBuiltinFunction(); }
bool shouldEmitTypeProfilerHooks() const { return m_codeGenerationMode.contains(CodeGenerationMode::TypeProfiler); }
bool shouldEmitControlFlowProfilerHooks() const { return m_codeGenerationMode.contains(CodeGenerationMode::ControlFlowProfiler); }

Expand All @@ -1082,6 +1082,11 @@ namespace JSC {
SourceParseMode parseMode() const { return m_codeBlock->parseMode(); }

bool isBuiltinFunction() const { return m_isBuiltinFunction; }
#if USE(BUN_JSC_ADDITIONS)
bool isPrivateBuiltinFunction() const { return m_isPrivateBuiltinFunction; }
#else
bool isPrivateBuiltinFunction() const { return isBuiltinFunction(); }
#endif

OpcodeID lastOpcodeID() const { return m_lastOpcodeID; }

Expand Down Expand Up @@ -1397,6 +1402,9 @@ namespace JSC {
bool m_usesExceptions { false };
bool m_expressionTooDeep { false };
bool m_isBuiltinFunction { false };
#if USE(BUN_JSC_ADDITIONS)
bool m_isPrivateBuiltinFunction { false };
#endif
bool m_usesSloppyEval { false };
bool m_allowTailCallOptimization { false };
bool m_allowCallIgnoreResultOptimization { false };
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/interpreter/CallFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ SourceOrigin CallFrame::callerSourceOrigin(VM& vm)
// In the above case, the eval function will be interpreted as the indirect call to eval inside forEach function.
// At that time, the generated eval code should have the source origin to the original caller of the forEach function
// instead of the source origin of the forEach function.
if (static_cast<FunctionExecutable*>(visitor->codeBlock()->ownerExecutable())->isBuiltinFunction())
if (static_cast<FunctionExecutable*>(visitor->codeBlock()->ownerExecutable())->isPrivateBuiltinFunction())
return IterationStatus::Continue;
FALLTHROUGH;

Expand Down
4 changes: 4 additions & 0 deletions Source/JavaScriptCore/runtime/FunctionExecutable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ JSString* FunctionExecutable::toStringSlow(JSGlobalObject* globalObject)
return cache(::JSC::asString(value));
};

#if USE(BUN_JSC_ADDITIONS)
if (isPrivateBuiltinFunction())
#else
if (isBuiltinFunction())
#endif
return cacheIfNoException(jsMakeNontrivialString(globalObject, "function "_s, name().string(), "() {\n [native code]\n}"_s));

if (isClass())
Expand Down
1 change: 1 addition & 0 deletions Source/JavaScriptCore/runtime/FunctionExecutable.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class FunctionExecutable final : public ScriptExecutable {
FunctionMode functionMode() { return m_unlinkedExecutable->functionMode(); }
ImplementationVisibility implementationVisibility() const { return m_unlinkedExecutable->implementationVisibility(); }
bool isBuiltinFunction() const { return m_unlinkedExecutable->isBuiltinFunction(); }
bool isPrivateBuiltinFunction() const { return isBuiltinFunction() && (!m_source.provider() || !m_source.provider()->sourceURL()); }
ConstructAbility constructAbility() const { return m_unlinkedExecutable->constructAbility(); }
InlineAttribute inlineAttribute() const { return m_unlinkedExecutable->inlineAttribute(); }
bool isClass() const { return m_unlinkedExecutable->isClass(); }
Expand Down

0 comments on commit 737c1a9

Please sign in to comment.