JavascriptString * RuntimeFunction::EnsureSourceString() { JavascriptLibrary* library = this->GetLibrary(); ScriptContext * scriptContext = library->GetScriptContext(); JavascriptString * retStr = nullptr; if (this->functionNameId == nullptr) { retStr = library->GetFunctionDisplayString(); this->functionNameId = retStr; } else { if (TaggedInt::Is(this->functionNameId)) { if (this->GetTypeHandler()->IsDeferredTypeHandler()) { JavascriptString* functionName = nullptr; DebugOnly(bool status = ) this->GetFunctionName(&functionName); Assert(status); this->SetPropertyWithAttributes(PropertyIds::name, functionName, PropertyConfigurable, nullptr); } // This has a side-effect where any other code (such as debugger) that uses functionNameId value will now get the value like "function foo() { native code }" // instead of just "foo". Alternative ways will need to be devised; if it's not desirable to use this full display name value in those cases. retStr = GetNativeFunctionDisplayString(scriptContext, scriptContext->GetPropertyString(TaggedInt::ToInt32(this->functionNameId))); this->functionNameId = retStr; } else {
// We will make sure the iterator will iterate through the exported properties in sorted order. // There is no such requirement for enumerator (forin). ListForListIterator* ModuleNamespace::EnsureSortedExportedNames() { if (sortedExportedNames == nullptr) { ExportedNames* exportedNames = moduleRecord->GetExportedNames(nullptr); ScriptContext* scriptContext = GetScriptContext(); sortedExportedNames = ListForListIterator::New(scriptContext->GetRecycler()); exportedNames->Map([&](PropertyId propertyId) { JavascriptString* propertyString = scriptContext->GetPropertyString(propertyId); sortedExportedNames->Add(propertyString); }); sortedExportedNames->Sort([](void* context, const void* left, const void* right) ->int { JavascriptString** leftString = (JavascriptString**) (left); JavascriptString** rightString = (JavascriptString**) (right); if (JavascriptString::LessThan(*leftString, *rightString)) { return -1; } if (JavascriptString::LessThan(*rightString, *leftString)) { return 1; } return 0; }, nullptr); } return sortedExportedNames; }
Var RuntimeFunction::EnsureSourceString() { JavascriptLibrary* library = this->GetLibrary(); ScriptContext * scriptContext = library->GetScriptContext(); if (this->functionNameId == nullptr) { this->functionNameId = library->GetFunctionDisplayString(); } else { if (TaggedInt::Is(this->functionNameId)) { if (this->GetScriptContext()->GetConfig()->IsES6FunctionNameEnabled() && this->GetTypeHandler()->IsDeferredTypeHandler()) { JavascriptString* functionName = nullptr; DebugOnly(bool status = ) this->GetFunctionName(&functionName); Assert(status); this->SetPropertyWithAttributes(PropertyIds::name, functionName, PropertyConfigurable, nullptr); } this->functionNameId = GetNativeFunctionDisplayString(scriptContext, scriptContext->GetPropertyString(TaggedInt::ToInt32(this->functionNameId))); } }