OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 private: | 77 private: |
78 #ifdef ENABLE_DEBUGGER_SUPPORT | 78 #ifdef ENABLE_DEBUGGER_SUPPORT |
79 Isolate* isolate_; | 79 Isolate* isolate_; |
80 #endif | 80 #endif |
81 }; | 81 }; |
82 | 82 |
83 #ifdef ENABLE_DEBUGGER_SUPPORT | 83 #ifdef ENABLE_DEBUGGER_SUPPORT |
84 | 84 |
85 class LiveEdit : AllStatic { | 85 class LiveEdit : AllStatic { |
86 public: | 86 public: |
87 static JSArray* GatherCompileInfo(Handle<Script> script, | 87 MUST_USE_RESULT static MaybeHandle<JSArray> GatherCompileInfo( |
88 Handle<String> source); | 88 Handle<Script> script, |
| 89 Handle<String> source); |
89 | 90 |
90 static void WrapSharedFunctionInfos(Handle<JSArray> array); | 91 static void WrapSharedFunctionInfos(Handle<JSArray> array); |
91 | 92 |
92 MUST_USE_RESULT static MaybeObject* ReplaceFunctionCode( | 93 static void ReplaceFunctionCode(Handle<JSArray> new_compile_info_array, |
93 Handle<JSArray> new_compile_info_array, | 94 Handle<JSArray> shared_info_array); |
94 Handle<JSArray> shared_info_array); | |
95 | 95 |
96 static MaybeObject* FunctionSourceUpdated(Handle<JSArray> shared_info_array); | 96 static void FunctionSourceUpdated(Handle<JSArray> shared_info_array); |
97 | 97 |
98 // Updates script field in FunctionSharedInfo. | 98 // Updates script field in FunctionSharedInfo. |
99 static void SetFunctionScript(Handle<JSValue> function_wrapper, | 99 static void SetFunctionScript(Handle<JSValue> function_wrapper, |
100 Handle<Object> script_handle); | 100 Handle<Object> script_handle); |
101 | 101 |
102 MUST_USE_RESULT static MaybeObject* PatchFunctionPositions( | 102 static void PatchFunctionPositions(Handle<JSArray> shared_info_array, |
103 Handle<JSArray> shared_info_array, Handle<JSArray> position_change_array); | 103 Handle<JSArray> position_change_array); |
104 | 104 |
105 // For a script updates its source field. If old_script_name is provided | 105 // For a script updates its source field. If old_script_name is provided |
106 // (i.e. is a String), also creates a copy of the script with its original | 106 // (i.e. is a String), also creates a copy of the script with its original |
107 // source and sends notification to debugger. | 107 // source and sends notification to debugger. |
108 static Object* ChangeScriptSource(Handle<Script> original_script, | 108 static Handle<Object> ChangeScriptSource(Handle<Script> original_script, |
109 Handle<String> new_source, | 109 Handle<String> new_source, |
110 Handle<Object> old_script_name); | 110 Handle<Object> old_script_name); |
111 | 111 |
112 // In a code of a parent function replaces original function as embedded | 112 // In a code of a parent function replaces original function as embedded |
113 // object with a substitution one. | 113 // object with a substitution one. |
114 static void ReplaceRefToNestedFunction(Handle<JSValue> parent_function_shared, | 114 static void ReplaceRefToNestedFunction(Handle<JSValue> parent_function_shared, |
115 Handle<JSValue> orig_function_shared, | 115 Handle<JSValue> orig_function_shared, |
116 Handle<JSValue> subst_function_shared); | 116 Handle<JSValue> subst_function_shared); |
117 | 117 |
118 // Checks listed functions on stack and return array with corresponding | 118 // Checks listed functions on stack and return array with corresponding |
119 // FunctionPatchabilityStatus statuses; extra array element may | 119 // FunctionPatchabilityStatus statuses; extra array element may |
120 // contain general error message. Modifies the current stack and | 120 // contain general error message. Modifies the current stack and |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 168 |
169 protected: | 169 protected: |
170 virtual ~Output() {} | 170 virtual ~Output() {} |
171 }; | 171 }; |
172 | 172 |
173 // Finds the difference between 2 arrays of elements. | 173 // Finds the difference between 2 arrays of elements. |
174 static void CalculateDifference(Input* input, | 174 static void CalculateDifference(Input* input, |
175 Output* result_writer); | 175 Output* result_writer); |
176 }; | 176 }; |
177 | 177 |
| 178 |
| 179 |
| 180 // Simple helper class that creates more or less typed structures over |
| 181 // JSArray object. This is an adhoc method of passing structures from C++ |
| 182 // to JavaScript. |
| 183 template<typename S> |
| 184 class JSArrayBasedStruct { |
| 185 public: |
| 186 static S Create(Isolate* isolate) { |
| 187 Factory* factory = isolate->factory(); |
| 188 Handle<JSArray> array = factory->NewJSArray(S::kSize_); |
| 189 return S(array); |
| 190 } |
| 191 |
| 192 static S cast(Object* object) { |
| 193 JSArray* array = JSArray::cast(object); |
| 194 Handle<JSArray> array_handle(array); |
| 195 return S(array_handle); |
| 196 } |
| 197 |
| 198 explicit JSArrayBasedStruct(Handle<JSArray> array) : array_(array) { |
| 199 } |
| 200 |
| 201 Handle<JSArray> GetJSArray() { |
| 202 return array_; |
| 203 } |
| 204 |
| 205 Isolate* isolate() const { |
| 206 return array_->GetIsolate(); |
| 207 } |
| 208 |
| 209 protected: |
| 210 void SetField(int field_position, Handle<Object> value) { |
| 211 Handle<Object> no_failure = |
| 212 JSObject::SetElement(array_, field_position, value, NONE, SLOPPY); |
| 213 ASSERT(!no_failure.is_null()); |
| 214 USE(no_failure); |
| 215 } |
| 216 |
| 217 void SetSmiValueField(int field_position, int value) { |
| 218 SetField(field_position, Handle<Smi>(Smi::FromInt(value), isolate())); |
| 219 } |
| 220 |
| 221 Handle<Object> GetField(int field_position) { |
| 222 return Object::GetElementNoExceptionThrown( |
| 223 isolate(), array_, field_position); |
| 224 } |
| 225 |
| 226 int GetSmiValueField(int field_position) { |
| 227 Handle<Object> res = GetField(field_position); |
| 228 return Handle<Smi>::cast(res)->value(); |
| 229 } |
| 230 |
| 231 private: |
| 232 Handle<JSArray> array_; |
| 233 }; |
| 234 |
| 235 |
| 236 // Represents some function compilation details. This structure will be used |
| 237 // from JavaScript. It contains Code object, which is kept wrapped |
| 238 // into a BlindReference for sanitizing reasons. |
| 239 class FunctionInfoWrapper : public JSArrayBasedStruct<FunctionInfoWrapper> { |
| 240 public: |
| 241 explicit FunctionInfoWrapper(Handle<JSArray> array) |
| 242 : JSArrayBasedStruct<FunctionInfoWrapper>(array) { |
| 243 } |
| 244 |
| 245 void SetInitialProperties(Handle<String> name, |
| 246 int start_position, |
| 247 int end_position, |
| 248 int param_num, |
| 249 int literal_count, |
| 250 int parent_index); |
| 251 |
| 252 void SetFunctionCode(Handle<Code> function_code, |
| 253 Handle<HeapObject> code_scope_info); |
| 254 |
| 255 void SetFunctionScopeInfo(Handle<Object> scope_info_array) { |
| 256 this->SetField(kFunctionScopeInfoOffset_, scope_info_array); |
| 257 } |
| 258 |
| 259 void SetSharedFunctionInfo(Handle<SharedFunctionInfo> info); |
| 260 |
| 261 int GetLiteralCount() { |
| 262 return this->GetSmiValueField(kLiteralNumOffset_); |
| 263 } |
| 264 |
| 265 int GetParentIndex() { |
| 266 return this->GetSmiValueField(kParentIndexOffset_); |
| 267 } |
| 268 |
| 269 Handle<Code> GetFunctionCode(); |
| 270 |
| 271 Handle<Object> GetCodeScopeInfo(); |
| 272 |
| 273 int GetStartPosition() { |
| 274 return this->GetSmiValueField(kStartPositionOffset_); |
| 275 } |
| 276 |
| 277 int GetEndPosition() { return this->GetSmiValueField(kEndPositionOffset_); } |
| 278 |
| 279 private: |
| 280 static const int kFunctionNameOffset_ = 0; |
| 281 static const int kStartPositionOffset_ = 1; |
| 282 static const int kEndPositionOffset_ = 2; |
| 283 static const int kParamNumOffset_ = 3; |
| 284 static const int kCodeOffset_ = 4; |
| 285 static const int kCodeScopeInfoOffset_ = 5; |
| 286 static const int kFunctionScopeInfoOffset_ = 6; |
| 287 static const int kParentIndexOffset_ = 7; |
| 288 static const int kSharedFunctionInfoOffset_ = 8; |
| 289 static const int kLiteralNumOffset_ = 9; |
| 290 static const int kSize_ = 10; |
| 291 |
| 292 friend class JSArrayBasedStruct<FunctionInfoWrapper>; |
| 293 }; |
| 294 |
| 295 |
| 296 // Wraps SharedFunctionInfo along with some of its fields for passing it |
| 297 // back to JavaScript. SharedFunctionInfo object itself is additionally |
| 298 // wrapped into BlindReference for sanitizing reasons. |
| 299 class SharedInfoWrapper : public JSArrayBasedStruct<SharedInfoWrapper> { |
| 300 public: |
| 301 static bool IsInstance(Handle<JSArray> array) { |
| 302 return array->length() == Smi::FromInt(kSize_) && |
| 303 Object::GetElementNoExceptionThrown( |
| 304 array->GetIsolate(), array, kSharedInfoOffset_)->IsJSValue(); |
| 305 } |
| 306 |
| 307 explicit SharedInfoWrapper(Handle<JSArray> array) |
| 308 : JSArrayBasedStruct<SharedInfoWrapper>(array) { |
| 309 } |
| 310 |
| 311 void SetProperties(Handle<String> name, |
| 312 int start_position, |
| 313 int end_position, |
| 314 Handle<SharedFunctionInfo> info); |
| 315 |
| 316 Handle<SharedFunctionInfo> GetInfo(); |
| 317 |
| 318 private: |
| 319 static const int kFunctionNameOffset_ = 0; |
| 320 static const int kStartPositionOffset_ = 1; |
| 321 static const int kEndPositionOffset_ = 2; |
| 322 static const int kSharedInfoOffset_ = 3; |
| 323 static const int kSize_ = 4; |
| 324 |
| 325 friend class JSArrayBasedStruct<SharedInfoWrapper>; |
| 326 }; |
| 327 |
178 #endif // ENABLE_DEBUGGER_SUPPORT | 328 #endif // ENABLE_DEBUGGER_SUPPORT |
179 | 329 |
180 | 330 |
181 } } // namespace v8::internal | 331 } } // namespace v8::internal |
182 | 332 |
183 #endif /* V*_LIVEEDIT_H_ */ | 333 #endif /* V*_LIVEEDIT_H_ */ |
OLD | NEW |