File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -1033,11 +1033,32 @@ namespace Js
1033
1033
}
1034
1034
}
1035
1035
1036
+ // Returns a raw pointer to the display name which may not have a well-known lifetime. It's safer to use
1037
+ // GetExternalDisplayNameObject if the end goal is to create an object anyway.
1036
1038
const char16* ParseableFunctionInfo::GetExternalDisplayName () const
1037
1039
{
1038
1040
return GetExternalDisplayName (this );
1039
1041
}
1040
1042
1043
+ // Allocates a new JavascriptString object containing the display name associated with the FunctionBody.
1044
+ JavascriptString* ParseableFunctionInfo::GetExternalDisplayNameObject (ScriptContext* scriptContext) const
1045
+ {
1046
+ const char16* name = GetExternalDisplayName ();
1047
+
1048
+ if (!GetDisplayNameIsRecyclerAllocated () && !IsConstantFunctionName (name))
1049
+ {
1050
+ // The string is allocated in memory that we don't directly control the lifetime of. Copy the string to
1051
+ // ensure that the buffer remains valid for the lifetime of the object.
1052
+ return Js::JavascriptString::NewCopySz (name, scriptContext);
1053
+ }
1054
+ else
1055
+ {
1056
+ // Use the incoming buffer directly to create the object. This only works when the lifetime of the data is
1057
+ // static or GC allocated.
1058
+ return Js::JavascriptString::NewWithSz (name, scriptContext);
1059
+ }
1060
+ }
1061
+
1041
1062
RegSlot
1042
1063
FunctionBody::GetLocalsCount ()
1043
1064
{
Original file line number Diff line number Diff line change @@ -1096,7 +1096,7 @@ namespace Js
1096
1096
// this is also now being used for function.name.
1097
1097
const char16* GetShortDisplayName (charcount_t * shortNameLength);
1098
1098
1099
- bool GetDisplayNameIsRecyclerAllocated () { return m_displayNameIsRecyclerAllocated; }
1099
+ bool GetDisplayNameIsRecyclerAllocated () const { return m_displayNameIsRecyclerAllocated; }
1100
1100
1101
1101
bool IsJitLoopBodyPhaseEnabled () const
1102
1102
{
@@ -1678,6 +1678,7 @@ namespace Js
1678
1678
void CopyNestedArray (ParseableFunctionInfo * other);
1679
1679
1680
1680
const char16* GetExternalDisplayName () const ;
1681
+ JavascriptString* GetExternalDisplayNameObject (ScriptContext* scriptContext) const ;
1681
1682
1682
1683
//
1683
1684
// Algorithm to retrieve a function body's external display name. Template supports both
You can’t perform that action at this time.
0 commit comments