OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium 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 #ifndef ScriptState_h | 5 #ifndef ScriptState_h |
6 #define ScriptState_h | 6 #define ScriptState_h |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "platform/PlatformExport.h" | 10 #include "platform/PlatformExport.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 // | 27 // |
28 // When you need ScriptState, you can add [CallWith=ScriptState] to IDL files | 28 // When you need ScriptState, you can add [CallWith=ScriptState] to IDL files |
29 // and pass around ScriptState into a place where you need ScriptState. | 29 // and pass around ScriptState into a place where you need ScriptState. |
30 // | 30 // |
31 // In some cases, you need ScriptState in code that doesn't have any JavaScript | 31 // In some cases, you need ScriptState in code that doesn't have any JavaScript |
32 // on the stack. Then you can store ScriptState on a C++ object using | 32 // on the stack. Then you can store ScriptState on a C++ object using |
33 // RefPtr<ScriptState>. | 33 // RefPtr<ScriptState>. |
34 // | 34 // |
35 // class SomeObject { | 35 // class SomeObject { |
36 // void someMethod(ScriptState* scriptState) { | 36 // void someMethod(ScriptState* scriptState) { |
37 // m_scriptState = scriptState; // Record the ScriptState. | 37 // script_state_ = scriptState; // Record the ScriptState. |
38 // ...; | 38 // ...; |
39 // } | 39 // } |
40 // | 40 // |
41 // void asynchronousMethod() { | 41 // void asynchronousMethod() { |
42 // if (!m_scriptState->contextIsValid()) { | 42 // if (!script_state_->contextIsValid()) { |
43 // // It's possible that the context is already gone. | 43 // // It's possible that the context is already gone. |
44 // return; | 44 // return; |
45 // } | 45 // } |
46 // // Enter the ScriptState. | 46 // // Enter the ScriptState. |
47 // ScriptState::Scope scope(m_scriptState.get()); | 47 // ScriptState::Scope scope(script_state_.get()); |
48 // // Do V8 related things. | 48 // // Do V8 related things. |
49 // ToV8(...); | 49 // ToV8(...); |
50 // } | 50 // } |
51 // RefPtr<ScriptState> m_scriptState; | 51 // RefPtr<ScriptState> script_state_; |
52 // }; | 52 // }; |
53 // | 53 // |
54 // You should not store ScriptState on a C++ object that can be accessed | 54 // You should not store ScriptState on a C++ object that can be accessed |
55 // by multiple worlds. For example, you can store ScriptState on | 55 // by multiple worlds. For example, you can store ScriptState on |
56 // ScriptPromiseResolver, ScriptValue etc because they can be accessed from one | 56 // ScriptPromiseResolver, ScriptValue etc because they can be accessed from one |
57 // world. However, you cannot store ScriptState on a DOM object that has | 57 // world. However, you cannot store ScriptState on a DOM object that has |
58 // an IDL interface because the DOM object can be accessed from multiple | 58 // an IDL interface because the DOM object can be accessed from multiple |
59 // worlds. If ScriptState of one world "leak"s to another world, you will | 59 // worlds. If ScriptState of one world "leak"s to another world, you will |
60 // end up with leaking any JavaScript objects from one Chrome extension | 60 // end up with leaking any JavaScript objects from one Chrome extension |
61 // to another Chrome extension, which is a severe security bug. | 61 // to another Chrome extension, which is a severe security bug. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 192 } |
193 | 193 |
194 private: | 194 private: |
195 RefPtr<ScriptState> script_state_; | 195 RefPtr<ScriptState> script_state_; |
196 ScopedPersistent<v8::Context> context_; | 196 ScopedPersistent<v8::Context> context_; |
197 }; | 197 }; |
198 | 198 |
199 } // namespace blink | 199 } // namespace blink |
200 | 200 |
201 #endif // ScriptState_h | 201 #endif // ScriptState_h |
OLD | NEW |