ExternalLibraryBase.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. ExternalLibraryBase::ExternalLibraryBase() :
  9. scriptContext(nullptr),
  10. javascriptLibrary(nullptr),
  11. next(nullptr)
  12. {
  13. }
  14. void ExternalLibraryBase::Initialize(JavascriptLibrary* library)
  15. {
  16. Assert(this->javascriptLibrary == nullptr);
  17. this->javascriptLibrary = library;
  18. this->scriptContext = library->GetScriptContext();
  19. #if DBG
  20. ExternalLibraryBase* current = library->externalLibraryList;
  21. while (current != nullptr)
  22. {
  23. Assert(current != this);
  24. current = current->next;
  25. }
  26. #endif
  27. this->next = library->externalLibraryList;
  28. library->externalLibraryList = this;
  29. }
  30. void ExternalLibraryBase::Close()
  31. {
  32. ExternalLibraryBase* current = javascriptLibrary->externalLibraryList;
  33. #if DBG
  34. bool found = false;
  35. #endif
  36. if (current == this)
  37. {
  38. javascriptLibrary->externalLibraryList = this->next;
  39. #if DBG
  40. found = true;
  41. #endif
  42. }
  43. else
  44. {
  45. while (current != nullptr)
  46. {
  47. if (current->next == this)
  48. {
  49. current->next = this->next;
  50. #if DBG
  51. found = true;
  52. #endif
  53. break;
  54. }
  55. }
  56. }
  57. Assert(found);
  58. this->javascriptLibrary = nullptr;
  59. }
  60. }