Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Side by Side Diff: Source/bindings/v8/V8RecursionScope.h

Issue 466243002: Support merged Dart-JS callstacks (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/dartium
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef V8RecursionScope_h 31 #ifndef V8RecursionScope_h
32 #define V8RecursionScope_h 32 #define V8RecursionScope_h
33 33
34 #include "bindings/common/StackTrace.h"
34 #include "bindings/v8/V8PerIsolateData.h" 35 #include "bindings/v8/V8PerIsolateData.h"
35 #include "core/dom/ExecutionContext.h" 36 #include "core/dom/ExecutionContext.h"
36 #include "core/dom/ScriptForbiddenScope.h" 37 #include "core/dom/ScriptForbiddenScope.h"
37 #include "wtf/Noncopyable.h" 38 #include "wtf/Noncopyable.h"
38 #include <v8.h> 39 #include <v8.h>
39 40
40 namespace WebCore { 41 namespace WebCore {
41 42
42 // C++ calls into script contexts which are "owned" by WebKit (created in a 43 // C++ calls into script contexts which are "owned" by WebKit (created in a
43 // process where WebKit.cpp initializes v8) must declare their type: 44 // process where WebKit.cpp initializes v8) must declare their type:
44 // 45 //
45 // 1. Calls into page/author script from a frame 46 // 1. Calls into page/author script from a frame
46 // 2. Calls into page/author script from a worker 47 // 2. Calls into page/author script from a worker
47 // 3. Calls into internal script (typically setup/teardown work) 48 // 3. Calls into internal script (typically setup/teardown work)
48 // 49 //
49 // Debug-time checking of this is enforced via this class. 50 // Debug-time checking of this is enforced via this class.
50 // 51 //
51 // Calls of type (1) should generally go through ScriptController, as inspector 52 // Calls of type (1) should generally go through ScriptController, as inspector
52 // instrumentation is needed. ScriptController allocates V8RecursionScope for yo u. 53 // instrumentation is needed. ScriptController allocates V8RecursionScope for yo u.
53 // Calls of type (2) should always stack-allocate a V8RecursionScope in the same 54 // Calls of type (2) should always stack-allocate a V8RecursionScope in the same
54 // block as the call into script. Calls of type (3) should stack allocate a 55 // block as the call into script. Calls of type (3) should stack allocate a
55 // V8RecursionScope::MicrotaskSuppression -- this skips work that is spec'd to 56 // V8RecursionScope::MicrotaskSuppression -- this skips work that is spec'd to
56 // happen at the end of the outer-most script stack frame of calls into page scr ipt: 57 // happen at the end of the outer-most script stack frame of calls into page scr ipt:
57 // 58 //
58 // http://www.whatwg.org/specs/web-apps/current-work/#perform-a-microtask-checkp oint 59 // http://www.whatwg.org/specs/web-apps/current-work/#perform-a-microtask-checkp oint
59 class V8RecursionScope { 60 class V8RecursionScope {
60 WTF_MAKE_NONCOPYABLE(V8RecursionScope); 61 WTF_MAKE_NONCOPYABLE(V8RecursionScope);
61 public: 62 public:
62 V8RecursionScope(v8::Isolate* isolate, ExecutionContext* context) 63 V8RecursionScope(v8::Isolate* isolate, ExecutionContext* context, bool shoul dTrackStackDepth = true)
63 : m_isolate(isolate) 64 : m_isolate(isolate)
64 , m_executionContext(context) 65 , m_executionContext(context)
66 , m_shouldTrackStackDepth(shouldTrackStackDepth)
65 { 67 {
66 V8PerIsolateData::from(m_isolate)->incrementRecursionLevel(); 68 V8PerIsolateData* isolateData = V8PerIsolateData::from(m_isolate);
69
70 if (shouldTrackStackDepth)
71 trackStackDepth(isolateData);
72 isolateData->incrementRecursionLevel();
67 ASSERT(!ScriptForbiddenScope::isScriptForbidden()); 73 ASSERT(!ScriptForbiddenScope::isScriptForbidden());
68 // If you want V8 to autorun microtasks, this class needs to have a 74 // If you want V8 to autorun microtasks, this class needs to have a
69 // v8::Isolate::SuppressMicrotaskExecutionScope member. 75 // v8::Isolate::SuppressMicrotaskExecutionScope member.
70 ASSERT(!isolate->WillAutorunMicrotasks()); 76 ASSERT(!isolate->WillAutorunMicrotasks());
71 } 77 }
72 78
73 ~V8RecursionScope() 79 ~V8RecursionScope()
74 { 80 {
75 if (!V8PerIsolateData::from(m_isolate)->decrementRecursionLevel()) 81 V8PerIsolateData* isolateData = V8PerIsolateData::from(m_isolate);
82 if (m_shouldTrackStackDepth)
83 isolateData->stackTraceTimestampTracker()->decrementRecursionLevel() ;
84 if (!isolateData->decrementRecursionLevel())
76 didLeaveScriptContext(); 85 didLeaveScriptContext();
77 } 86 }
78 87
79 static int recursionLevel(v8::Isolate* isolate) 88 static int recursionLevel(v8::Isolate* isolate)
80 { 89 {
81 return V8PerIsolateData::from(isolate)->recursionLevel(); 90 return V8PerIsolateData::from(isolate)->recursionLevel();
82 } 91 }
83 92
84 #ifndef NDEBUG 93 #ifndef NDEBUG
85 static bool properlyUsed(v8::Isolate* isolate) 94 static bool properlyUsed(v8::Isolate* isolate)
(...skipping 23 matching lines...) Expand all
109 } 118 }
110 119
111 private: 120 private:
112 #ifndef NDEBUG 121 #ifndef NDEBUG
113 v8::Isolate* m_isolate; 122 v8::Isolate* m_isolate;
114 #endif 123 #endif
115 }; 124 };
116 125
117 private: 126 private:
118 void didLeaveScriptContext(); 127 void didLeaveScriptContext();
128 void trackStackDepth(V8PerIsolateData*);
119 129
120 v8::Isolate* m_isolate; 130 v8::Isolate* m_isolate;
121 // FIXME: This is a reference in upstream Blink. In Dartium, it can 131 // FIXME: This is a reference in upstream Blink. In Dartium, it can
122 // be null when instantiated from a DartUtilities::V8Scope. 132 // be null when instantiated from a DartUtilities::V8Scope.
123 ExecutionContext* m_executionContext; 133 ExecutionContext* m_executionContext;
134 bool m_shouldTrackStackDepth;
124 }; 135 };
125 136
126 } // namespace WebCore 137 } // namespace WebCore
127 138
128 #endif // V8RecursionScope_h 139 #endif // V8RecursionScope_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698