| 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 "bindings/core/v8/ScopedPersistent.h" | 10 #include "bindings/core/v8/ScopedPersistent.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 public: | 70 public: |
| 71 class Scope { | 71 class Scope { |
| 72 STACK_ALLOCATED(); | 72 STACK_ALLOCATED(); |
| 73 | 73 |
| 74 public: | 74 public: |
| 75 // You need to make sure that scriptState->context() is not empty before | 75 // You need to make sure that scriptState->context() is not empty before |
| 76 // creating a Scope. | 76 // creating a Scope. |
| 77 explicit Scope(ScriptState* script_state) | 77 explicit Scope(ScriptState* script_state) |
| 78 : handle_scope_(script_state->GetIsolate()), | 78 : handle_scope_(script_state->GetIsolate()), |
| 79 context_(script_state->GetContext()) { | 79 context_(script_state->GetContext()) { |
| 80 ASSERT(script_state->ContextIsValid()); | 80 DCHECK(script_state->ContextIsValid()); |
| 81 context_->Enter(); | 81 context_->Enter(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 ~Scope() { context_->Exit(); } | 84 ~Scope() { context_->Exit(); } |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 v8::HandleScope handle_scope_; | 87 v8::HandleScope handle_scope_; |
| 88 v8::Local<v8::Context> context_; | 88 v8::Local<v8::Context> context_; |
| 89 }; | 89 }; |
| 90 | 90 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 115 const v8::PropertyCallbackInfo<v8::Value>& info) { | 115 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 116 return From(info.Holder()->CreationContext()); | 116 return From(info.Holder()->CreationContext()); |
| 117 } | 117 } |
| 118 | 118 |
| 119 static ScriptState* ForReceiverObject( | 119 static ScriptState* ForReceiverObject( |
| 120 const v8::PropertyCallbackInfo<void>& info) { | 120 const v8::PropertyCallbackInfo<void>& info) { |
| 121 return From(info.Holder()->CreationContext()); | 121 return From(info.Holder()->CreationContext()); |
| 122 } | 122 } |
| 123 | 123 |
| 124 static ScriptState* From(v8::Local<v8::Context> context) { | 124 static ScriptState* From(v8::Local<v8::Context> context) { |
| 125 ASSERT(!context.IsEmpty()); | 125 DCHECK(!context.IsEmpty()); |
| 126 ScriptState* script_state = | 126 ScriptState* script_state = |
| 127 static_cast<ScriptState*>(context->GetAlignedPointerFromEmbedderData( | 127 static_cast<ScriptState*>(context->GetAlignedPointerFromEmbedderData( |
| 128 kV8ContextPerContextDataIndex)); | 128 kV8ContextPerContextDataIndex)); |
| 129 // ScriptState::from() must not be called for a context that does not have | 129 // ScriptState::from() must not be called for a context that does not have |
| 130 // valid embedder data in the embedder field. | 130 // valid embedder data in the embedder field. |
| 131 SECURITY_CHECK(script_state); | 131 SECURITY_CHECK(script_state); |
| 132 SECURITY_CHECK(script_state->GetContext() == context); | 132 SECURITY_CHECK(script_state->GetContext() == context); |
| 133 return script_state; | 133 return script_state; |
| 134 } | 134 } |
| 135 | 135 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 } | 194 } |
| 195 | 195 |
| 196 private: | 196 private: |
| 197 RefPtr<ScriptState> script_state_; | 197 RefPtr<ScriptState> script_state_; |
| 198 ScopedPersistent<v8::Context> context_; | 198 ScopedPersistent<v8::Context> context_; |
| 199 }; | 199 }; |
| 200 | 200 |
| 201 } // namespace blink | 201 } // namespace blink |
| 202 | 202 |
| 203 #endif // ScriptState_h | 203 #endif // ScriptState_h |
| OLD | NEW |