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