LiteralString.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #include "RuntimeLibraryPch.h"
  6. namespace Js
  7. {
  8. DEFINE_RECYCLER_TRACKER_PERF_COUNTER(LiteralString);
  9. LiteralString::LiteralString(StaticType * type) : JavascriptString(type)
  10. {
  11. }
  12. LiteralString::LiteralString(StaticType * type, const wchar_t* content, charcount_t charLength) :
  13. JavascriptString(type, charLength, content)
  14. {
  15. #if defined(DBG) && defined(_M_IX86)
  16. // Make sure content isn't on the stack by comparing to stack bounds in TIB
  17. AssertMsg(!ThreadContext::IsOnStack((void*)content),
  18. "LiteralString object created using stack buffer...");
  19. #endif
  20. AssertMsg(AutoSystemInfo::IsJscriptModulePointer((void *)content)
  21. || type->GetScriptContext()->GetRecycler()->IsValidObject((void *)content),
  22. "LiteralString can only be used with static or GC strings");
  23. #ifdef PROFILE_STRINGS
  24. StringProfiler::RecordNewString( type->GetScriptContext(), content, charLength );
  25. #endif
  26. }
  27. LiteralString* LiteralString::New(StaticType* type, const wchar_t* content, charcount_t charLength, Recycler* recycler)
  28. {
  29. return RecyclerNew(recycler, LiteralString, type, content, charLength);
  30. }
  31. LiteralString* LiteralString::CreateEmptyString(StaticType* type)
  32. {
  33. return RecyclerNew(type->GetScriptContext()->GetRecycler(), LiteralString, type, L"", 0);
  34. }
  35. ArenaLiteralString::ArenaLiteralString(StaticType * type, const wchar_t* content, charcount_t charLength) :
  36. JavascriptString(type, charLength, content)
  37. {
  38. #if defined(DBG) && defined(_M_IX86)
  39. // Make sure content isn't on the stack by comparing to stack bounds in TIB
  40. AssertMsg(!ThreadContext::IsOnStack((void*)content),
  41. "ArenaLiteralString object created using stack buffer...");
  42. #endif
  43. AssertMsg(!type->GetScriptContext()->GetRecycler()->IsValidObject((void *)content),
  44. "ArenaLiteralString should not be used with GC strings");
  45. #ifdef PROFILE_STRINGS
  46. StringProfiler::RecordNewString( type->GetScriptContext(), content, charLength );
  47. #endif
  48. }
  49. ArenaLiteralString* ArenaLiteralString::New(StaticType* type, const wchar_t* content, charcount_t charLength, Recycler* recycler)
  50. {
  51. return RecyclerNew(recycler, ArenaLiteralString, type, content, charLength);
  52. }
  53. ArenaLiteralString* ArenaLiteralString::New(StaticType* type, const wchar_t* content, charcount_t charLength, ArenaAllocator* arena)
  54. {
  55. return Anew(arena, ArenaLiteralString, type, content, charLength);
  56. }
  57. RecyclableObject * ArenaLiteralString::CloneToScriptContext(ScriptContext* requestContext)
  58. {
  59. return JavascriptString::NewCopyBuffer(this->GetSz(), this->GetLength(), requestContext);
  60. }
  61. } // namespace Js