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

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

Issue 648423003: Enforce ScriptForbiddenScope and make it non-fatal. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Getting ambitious Created 6 years, 2 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
« no previous file with comments | « Source/bindings/core/v8/NPV8Object.cpp ('k') | Source/bindings/core/v8/V8ScriptRunner.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 17 matching lines...) Expand all
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/core/v8/V8PerIsolateData.h" 34 #include "bindings/core/v8/V8PerIsolateData.h"
35 #include "core/dom/ExecutionContext.h" 35 #include "core/dom/ExecutionContext.h"
36 #include "platform/ScriptForbiddenScope.h" 36 #include "platform/ScriptForbiddenScope.h"
37 #include "wtf/Noncopyable.h" 37 #include "wtf/Noncopyable.h"
38 #include "wtf/PassOwnPtr.h"
38 #include <v8.h> 39 #include <v8.h>
39 40
40 namespace blink { 41 namespace blink {
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 explicit V8RecursionScope(v8::Isolate* isolate) 63 static PassOwnPtr<V8RecursionScope> create(v8::Isolate* isolate)
haraken 2014/10/14 01:04:29 Shall we rename create => createIfScriptAllowed ?
63 : m_isolate(isolate)
64 { 64 {
65 V8PerIsolateData::from(m_isolate)->incrementRecursionLevel(); 65 return !ScriptForbiddenScope::isScriptForbidden()
66 RELEASE_ASSERT(!ScriptForbiddenScope::isScriptForbidden()); 66 ? adoptPtr(new V8RecursionScope(isolate))
67 // If you want V8 to autorun microtasks, this class needs to have a 67 : nullptr;
68 // v8::Isolate::SuppressMicrotaskExecutionScope member.
69 ASSERT(!isolate->WillAutorunMicrotasks());
70 } 68 }
71 69
72 ~V8RecursionScope() 70 ~V8RecursionScope()
73 { 71 {
74 if (!V8PerIsolateData::from(m_isolate)->decrementRecursionLevel()) 72 if (!V8PerIsolateData::from(m_isolate)->decrementRecursionLevel())
75 didLeaveScriptContext(); 73 didLeaveScriptContext();
76 } 74 }
77 75
78 static int recursionLevel(v8::Isolate* isolate) 76 static int recursionLevel(v8::Isolate* isolate)
79 { 77 {
80 return V8PerIsolateData::from(isolate)->recursionLevel(); 78 return V8PerIsolateData::from(isolate)->recursionLevel();
81 } 79 }
82 80
83 #if ENABLE(ASSERT) 81 #if ENABLE(ASSERT)
84 static bool properlyUsed(v8::Isolate* isolate) 82 static bool properlyUsed(v8::Isolate* isolate)
85 { 83 {
86 return recursionLevel(isolate) > 0 || V8PerIsolateData::from(isolate)->i nternalScriptRecursionLevel() > 0; 84 return recursionLevel(isolate) > 0 || V8PerIsolateData::from(isolate)->i nternalScriptRecursionLevel() > 0;
87 } 85 }
88 #endif 86 #endif
89 87
90 class MicrotaskSuppression { 88 class MicrotaskSuppression {
haraken 2014/10/14 01:04:30 You need to take care of MicrotaskSuppression as w
91 public: 89 public:
92 MicrotaskSuppression(v8::Isolate* isolate) 90 MicrotaskSuppression(v8::Isolate* isolate)
93 #if ENABLE(ASSERT) 91 #if ENABLE(ASSERT)
94 : m_isolate(isolate) 92 : m_isolate(isolate)
95 #endif 93 #endif
96 { 94 {
97 ASSERT(!ScriptForbiddenScope::isScriptForbidden()); 95 ASSERT(!ScriptForbiddenScope::isScriptForbidden());
98 #if ENABLE(ASSERT) 96 #if ENABLE(ASSERT)
99 V8PerIsolateData::from(m_isolate)->incrementInternalScriptRecursionL evel(); 97 V8PerIsolateData::from(m_isolate)->incrementInternalScriptRecursionL evel();
100 #endif 98 #endif
101 } 99 }
102 100
103 ~MicrotaskSuppression() 101 ~MicrotaskSuppression()
104 { 102 {
105 #if ENABLE(ASSERT) 103 #if ENABLE(ASSERT)
106 V8PerIsolateData::from(m_isolate)->decrementInternalScriptRecursionL evel(); 104 V8PerIsolateData::from(m_isolate)->decrementInternalScriptRecursionL evel();
107 #endif 105 #endif
108 } 106 }
109 107
110 private: 108 private:
111 #if ENABLE(ASSERT) 109 #if ENABLE(ASSERT)
112 v8::Isolate* m_isolate; 110 v8::Isolate* m_isolate;
113 #endif 111 #endif
114 }; 112 };
115 113
116 private: 114 private:
115 explicit V8RecursionScope(v8::Isolate* isolate)
116 : m_isolate(isolate)
117 {
118 V8PerIsolateData::from(m_isolate)->incrementRecursionLevel();
119 // If you want V8 to autorun microtasks, this class needs to have a
120 // v8::Isolate::SuppressMicrotaskExecutionScope member.
121 ASSERT(!isolate->WillAutorunMicrotasks());
122 }
123
117 void didLeaveScriptContext(); 124 void didLeaveScriptContext();
118 125
119 v8::Isolate* m_isolate; 126 v8::Isolate* m_isolate;
120 }; 127 };
121 128
122 } // namespace blink 129 } // namespace blink
123 130
124 #endif // V8RecursionScope_h 131 #endif // V8RecursionScope_h
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/NPV8Object.cpp ('k') | Source/bindings/core/v8/V8ScriptRunner.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698