OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/debug/debug.h" | 8 #include "src/debug/debug.h" |
9 #include "src/debug/debug-frames.h" | 9 #include "src/debug/debug-frames.h" |
10 #include "src/debug/liveedit.h" | 10 #include "src/debug/liveedit.h" |
11 #include "src/frames-inl.h" | 11 #include "src/frames-inl.h" |
12 #include "src/runtime/runtime.h" | 12 #include "src/runtime/runtime.h" |
13 #include "src/runtime/runtime-utils.h" | 13 #include "src/runtime/runtime-utils.h" |
14 | 14 |
15 namespace v8 { | 15 namespace v8 { |
16 namespace internal { | 16 namespace internal { |
17 | 17 |
18 | |
19 static int FindSharedFunctionInfosForScript(HeapIterator* iterator, | |
20 Script* script, | |
21 FixedArray* buffer) { | |
22 DisallowHeapAllocation no_allocation; | |
23 int counter = 0; | |
24 int buffer_size = buffer->length(); | |
25 for (HeapObject* obj = iterator->next(); obj != NULL; | |
26 obj = iterator->next()) { | |
27 DCHECK(obj != NULL); | |
28 if (!obj->IsSharedFunctionInfo()) { | |
29 continue; | |
30 } | |
31 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); | |
32 if (shared->script() != script) { | |
33 continue; | |
34 } | |
35 if (counter < buffer_size) { | |
36 buffer->set(counter, shared); | |
37 } | |
38 counter++; | |
39 } | |
40 return counter; | |
41 } | |
42 | |
43 | |
44 // For a script finds all SharedFunctionInfo's in the heap that points | 18 // For a script finds all SharedFunctionInfo's in the heap that points |
45 // to this script. Returns JSArray of SharedFunctionInfo wrapped | 19 // to this script. Returns JSArray of SharedFunctionInfo wrapped |
46 // in OpaqueReferences. | 20 // in OpaqueReferences. |
47 RUNTIME_FUNCTION(Runtime_LiveEditFindSharedFunctionInfosForScript) { | 21 RUNTIME_FUNCTION(Runtime_LiveEditFindSharedFunctionInfosForScript) { |
48 HandleScope scope(isolate); | 22 HandleScope scope(isolate); |
49 CHECK(isolate->debug()->live_edit_enabled()); | 23 CHECK(isolate->debug()->live_edit_enabled()); |
50 DCHECK(args.length() == 1); | 24 DCHECK(args.length() == 1); |
51 CONVERT_ARG_CHECKED(JSValue, script_value, 0); | 25 CONVERT_ARG_CHECKED(JSValue, script_value, 0); |
52 | 26 |
53 RUNTIME_ASSERT(script_value->value()->IsScript()); | 27 RUNTIME_ASSERT(script_value->value()->IsScript()); |
54 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); | 28 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); |
55 | 29 |
56 const int kBufferSize = 32; | 30 List<Handle<SharedFunctionInfo> > found; |
57 | |
58 Handle<FixedArray> array; | |
59 array = isolate->factory()->NewFixedArray(kBufferSize); | |
60 int number; | |
61 Heap* heap = isolate->heap(); | 31 Heap* heap = isolate->heap(); |
62 { | 32 { |
63 HeapIterator heap_iterator(heap); | 33 HeapIterator iterator(heap); |
64 Script* scr = *script; | 34 HeapObject* heap_obj; |
65 FixedArray* arr = *array; | 35 while ((heap_obj = iterator.next())) { |
66 number = FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); | 36 if (!heap_obj->IsSharedFunctionInfo()) continue; |
67 } | 37 SharedFunctionInfo* shared = SharedFunctionInfo::cast(heap_obj); |
68 if (number > kBufferSize) { | 38 if (shared->script() != *script) continue; |
69 array = isolate->factory()->NewFixedArray(number); | 39 found.Add(Handle<SharedFunctionInfo>(shared)); |
70 HeapIterator heap_iterator(heap); | 40 } |
71 Script* scr = *script; | |
72 FixedArray* arr = *array; | |
73 FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); | |
74 } | 41 } |
75 | 42 |
76 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(array); | 43 Handle<FixedArray> result = isolate->factory()->NewFixedArray(found.length()); |
77 result->set_length(Smi::FromInt(number)); | 44 for (int i = 0; i < found.length(); ++i) { |
78 | 45 Handle<SharedFunctionInfo> shared = found[i]; |
79 LiveEdit::WrapSharedFunctionInfos(result); | 46 SharedInfoWrapper info_wrapper = SharedInfoWrapper::Create(isolate); |
80 | 47 Handle<String> name(String::cast(shared->name())); |
81 return *result; | 48 info_wrapper.SetProperties(name, shared->start_position(), |
| 49 shared->end_position(), shared); |
| 50 result->set(i, *info_wrapper.GetJSArray()); |
| 51 } |
| 52 return *isolate->factory()->NewJSArrayWithElements(result); |
82 } | 53 } |
83 | 54 |
84 | 55 |
85 // For a script calculates compilation information about all its functions. | 56 // For a script calculates compilation information about all its functions. |
86 // The script source is explicitly specified by the second argument. | 57 // The script source is explicitly specified by the second argument. |
87 // The source of the actual script is not used, however it is important that | 58 // The source of the actual script is not used, however it is important that |
88 // all generated code keeps references to this particular instance of script. | 59 // all generated code keeps references to this particular instance of script. |
89 // Returns a JSArray of compilation infos. The array is ordered so that | 60 // Returns a JSArray of compilation infos. The array is ordered so that |
90 // each function with all its descendant is always stored in a continues range | 61 // each function with all its descendant is always stored in a continues range |
91 // with the function itself going first. The root function is a script function. | 62 // with the function itself going first. The root function is a script function. |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 // We don't really care what the inlined frame index is, since we are | 259 // We don't really care what the inlined frame index is, since we are |
289 // throwing away the entire frame anyways. | 260 // throwing away the entire frame anyways. |
290 const char* error_message = LiveEdit::RestartFrame(it.frame()); | 261 const char* error_message = LiveEdit::RestartFrame(it.frame()); |
291 if (error_message) { | 262 if (error_message) { |
292 return *(isolate->factory()->InternalizeUtf8String(error_message)); | 263 return *(isolate->factory()->InternalizeUtf8String(error_message)); |
293 } | 264 } |
294 return heap->true_value(); | 265 return heap->true_value(); |
295 } | 266 } |
296 } // namespace internal | 267 } // namespace internal |
297 } // namespace v8 | 268 } // namespace v8 |
OLD | NEW |