ResolveOperation.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright (C) 2012 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef ResolveOperation_h
  26. #define ResolveOperation_h
  27. #include "PropertyOffset.h"
  28. #include "WriteBarrier.h"
  29. #include <wtf/Vector.h>
  30. namespace JSC {
  31. class Structure;
  32. struct ResolveOperation {
  33. typedef enum {
  34. Fail,
  35. SetBaseToUndefined,
  36. ReturnScopeAsBase,
  37. SetBaseToScope,
  38. SetBaseToGlobal,
  39. GetAndReturnScopedVar,
  40. GetAndReturnGlobalVar,
  41. GetAndReturnGlobalVarWatchable,
  42. SkipTopScopeNode,
  43. SkipScopes,
  44. ReturnGlobalObjectAsBase,
  45. GetAndReturnGlobalProperty,
  46. CheckForDynamicEntriesBeforeGlobalScope
  47. } ResolveOperationType;
  48. ResolveOperationType m_operation;
  49. WriteBarrier<Structure> m_structure;
  50. union {
  51. PropertyOffset m_offset;
  52. WriteBarrier<Unknown>* m_registerAddress;
  53. int m_scopesToSkip;
  54. int m_activationRegister;
  55. };
  56. static ResolveOperation getAndReturnScopedVar(PropertyOffset offset)
  57. {
  58. ResolveOperation op;
  59. op.m_operation = GetAndReturnScopedVar;
  60. op.m_offset = offset;
  61. return op;
  62. }
  63. static ResolveOperation checkForDynamicEntriesBeforeGlobalScope()
  64. {
  65. ResolveOperation op;
  66. op.m_operation = CheckForDynamicEntriesBeforeGlobalScope;
  67. return op;
  68. }
  69. static ResolveOperation getAndReturnGlobalVar(WriteBarrier<Unknown>* registerAddress, bool couldBeWatched)
  70. {
  71. ResolveOperation op;
  72. op.m_operation = couldBeWatched ? GetAndReturnGlobalVarWatchable : GetAndReturnGlobalVar;
  73. op.m_registerAddress = registerAddress;
  74. return op;
  75. }
  76. static ResolveOperation getAndReturnGlobalProperty()
  77. {
  78. ResolveOperation op;
  79. op.m_operation = GetAndReturnGlobalProperty;
  80. return op;
  81. }
  82. static ResolveOperation resolveFail()
  83. {
  84. ResolveOperation op;
  85. op.m_operation = Fail;
  86. return op;
  87. }
  88. static ResolveOperation skipTopScopeNode(int activationRegister)
  89. {
  90. ResolveOperation op;
  91. op.m_operation = SkipTopScopeNode;
  92. op.m_activationRegister = activationRegister;
  93. return op;
  94. }
  95. static ResolveOperation skipScopes(int scopesToSkip)
  96. {
  97. ResolveOperation op;
  98. op.m_operation = SkipScopes;
  99. op.m_scopesToSkip = scopesToSkip;
  100. return op;
  101. }
  102. static ResolveOperation returnGlobalObjectAsBase()
  103. {
  104. ResolveOperation op;
  105. op.m_operation = ReturnGlobalObjectAsBase;
  106. return op;
  107. }
  108. static ResolveOperation setBaseToGlobal()
  109. {
  110. ResolveOperation op;
  111. op.m_operation = SetBaseToGlobal;
  112. return op;
  113. }
  114. static ResolveOperation setBaseToUndefined()
  115. {
  116. ResolveOperation op;
  117. op.m_operation = SetBaseToUndefined;
  118. return op;
  119. }
  120. static ResolveOperation setBaseToScope()
  121. {
  122. ResolveOperation op;
  123. op.m_operation = SetBaseToScope;
  124. return op;
  125. }
  126. static ResolveOperation returnScopeAsBase()
  127. {
  128. ResolveOperation op;
  129. op.m_operation = ReturnScopeAsBase;
  130. return op;
  131. }
  132. };
  133. typedef Vector_shared<ResolveOperation> ResolveOperations;
  134. struct PutToBaseOperation {
  135. PutToBaseOperation(bool isStrict)
  136. : m_kind(Uninitialised)
  137. , m_isDynamic(false)
  138. , m_isStrict(isStrict)
  139. , m_predicatePointer(0)
  140. {
  141. }
  142. enum Kind { Uninitialised, Generic, Readonly, GlobalVariablePut, GlobalVariablePutChecked, GlobalPropertyPut, VariablePut };
  143. union {
  144. Kind m_kind : 8;
  145. uint8_t m_kindAsUint8;
  146. };
  147. bool m_isDynamic : 8;
  148. bool m_isStrict : 8;
  149. union {
  150. bool* m_predicatePointer;
  151. unsigned m_scopeDepth;
  152. };
  153. WriteBarrier<Structure> m_structure;
  154. union {
  155. // Used for GlobalVariablePut
  156. WriteBarrier<Unknown>* m_registerAddress;
  157. // Used for GlobalPropertyPut and VariablePut
  158. struct {
  159. PropertyOffset m_offset;
  160. int32_t m_offsetInButterfly;
  161. };
  162. };
  163. };
  164. }
  165. #endif // ResolveOperation_h