JavascriptLibrary.inl 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // Create a string literal from a C++ string (const char16 array with compile-time determined size)
  9. // Note: The template arg is the string length in characters, including the NUL terminator.
  10. template< size_t N > JavascriptString* JavascriptLibrary::CreateStringFromCppLiteral(const char16(&value)[N]) const
  11. {
  12. CompileAssert(N>2); // Other values are handled by the specializations below
  13. return LiteralString::New(GetStringTypeStatic(), value, N - 1 /*don't include terminating NUL*/, this->GetRecycler());
  14. }
  15. // Specialization for the empty string
  16. template<> inline JavascriptString* JavascriptLibrary::CreateStringFromCppLiteral(const char16(&value)[1]) const
  17. {
  18. return GetEmptyString();
  19. }
  20. // Specialization for single-char strings
  21. template<> inline JavascriptString* JavascriptLibrary::CreateStringFromCppLiteral(const char16(&value)[2]) const
  22. {
  23. return charStringCache.GetStringForChar(value[0]);
  24. }
  25. template <size_t N>
  26. JavascriptFunction * JavascriptLibrary::AddFunctionToLibraryObjectWithPropertyName(DynamicObject* object, const char16(&propertyName)[N], FunctionInfo * functionInfo, int length)
  27. {
  28. // The PID need to be tracked because it is assigned to the runtime function's nameId
  29. return AddFunctionToLibraryObject(object, scriptContext->GetOrAddPropertyIdTracked(propertyName), functionInfo, length);
  30. }
  31. inline void JavascriptLibrary::CheckAndInvalidateIsConcatSpreadableCache(PropertyId propertyId, ScriptContext *scriptContext)
  32. {
  33. if (!PHASE_OFF1(IsConcatSpreadableCachePhase) && propertyId == PropertyIds::_symbolIsConcatSpreadable)
  34. {
  35. OUTPUT_TRACE(Phase::IsConcatSpreadableCachePhase, _u("IsConcatSpreadableCache invalidated\n"));
  36. scriptContext->GetThreadContext()->GetIsConcatSpreadableCache()->Invalidate();
  37. }
  38. }
  39. #if ENABLE_COPYONACCESS_ARRAY
  40. template <>
  41. inline void JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(const Var instance)
  42. {
  43. if (instance )
  44. {
  45. JavascriptCopyOnAccessNativeIntArray * copyOnAccessArray = JavascriptOperators::TryFromVar<JavascriptCopyOnAccessNativeIntArray>(instance);
  46. if (copyOnAccessArray)
  47. {
  48. copyOnAccessArray->ConvertCopyOnAccessSegment();
  49. }
  50. }
  51. }
  52. template <typename T>
  53. void JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(const T instance)
  54. {
  55. // dummy template function
  56. }
  57. #endif
  58. }