JavascriptString.inl 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. namespace Js
  7. {
  8. template <typename StringType>
  9. inline void JavascriptString::Copy(__out_ecount(bufLen) char16 *const buffer, const charcount_t bufLen)
  10. {
  11. Assert(buffer);
  12. charcount_t stringLen = this->GetLength();
  13. Assert(stringLen == m_charLength);
  14. if (bufLen < stringLen)
  15. {
  16. Throw::InternalError();
  17. }
  18. if (IsFinalized())
  19. {
  20. CopyHelper(buffer, GetString(), stringLen);
  21. return;
  22. }
  23. // Copy everything except nested string trees into the buffer. Collect nested string trees and the buffer locations
  24. // where they need to be copied, and copy them at the end. This is done to avoid excessive recursion during the copy.
  25. StringCopyInfoStack nestedStringTreeCopyInfos(GetScriptContext());
  26. ((StringType *)this)->StringType::CopyVirtual(buffer, nestedStringTreeCopyInfos, 0);
  27. FinishCopy(buffer, nestedStringTreeCopyInfos);
  28. }
  29. } // namespace Js