V8 Project
|
A sandboxed execution context with its own set of built-in objects and functions. More...
#include <v8.h>
Classes | |
class | Scope |
Stack-allocated class which sets the execution context for all operations executed within a local scope. More... | |
Public Member Functions | |
Local< Object > | Global () |
Returns the global proxy object. More... | |
void | DetachGlobal () |
Detaches the global object from its context before the global object can be reused to create a new context. More... | |
void | SetSecurityToken (Handle< Value > token) |
Sets the security token for the context. More... | |
void | UseDefaultSecurityToken () |
Restores the security token to the default value. More... | |
Handle< Value > | GetSecurityToken () |
Returns the security token of this context. More... | |
void | Enter () |
Enter this context. More... | |
void | Exit () |
Exit this context. More... | |
v8::Isolate * | GetIsolate () |
Returns an isolate associated with a current context. More... | |
Local< Value > | GetEmbedderData (int index) |
Gets the embedder data with the given index, which must have been set by a previous call to SetEmbedderData with the same index. More... | |
void | SetEmbedderData (int index, Handle< Value > value) |
Sets the embedder data with the given index, growing the data as needed. More... | |
void * | GetAlignedPointerFromEmbedderData (int index) |
Gets a 2-byte-aligned native pointer from the embedder data with the given index, which must have bees set by a previous call to SetAlignedPointerInEmbedderData with the same index. More... | |
void | SetAlignedPointerInEmbedderData (int index, void *value) |
Sets a 2-byte-aligned native pointer in the embedder data with the given index, growing the data as needed. More... | |
void | AllowCodeGenerationFromStrings (bool allow) |
Control whether code generation from strings is allowed. More... | |
bool | IsCodeGenerationFromStringsAllowed () |
Returns true if code generation from strings is allowed for the context. More... | |
void | SetErrorMessageForCodeGenerationFromStrings (Handle< String > message) |
Sets the error description for the exception that is thrown when code generation from strings is not allowed and 'eval' or the 'Function' constructor are called. More... | |
Static Public Member Functions | |
static Local< Context > | New (Isolate *isolate, ExtensionConfiguration *extensions=NULL, Handle< ObjectTemplate > global_template=Handle< ObjectTemplate >(), Handle< Value > global_object=Handle< Value >()) |
Creates a new context and returns a handle to the newly allocated context. More... | |
Private Member Functions | |
Local< Value > | SlowGetEmbedderData (int index) |
void * | SlowGetAlignedPointerFromEmbedderData (int index) |
Friends | |
class | Value |
class | Script |
class | Object |
class | Function |
A sandboxed execution context with its own set of built-in objects and functions.
void v8::Context::AllowCodeGenerationFromStrings | ( | bool | allow | ) |
Control whether code generation from strings is allowed.
Calling this method with false will disable 'eval' and the 'Function' constructor for code running in this context. If 'eval' or the 'Function' constructor are used an exception will be thrown.
If code generation from strings is not allowed the V8::AllowCodeGenerationFromStrings callback will be invoked if set before blocking the call to 'eval' or the 'Function' constructor. If that callback returns true, the call will be allowed, otherwise an exception will be thrown. If no callback is set an exception will be thrown.
Definition at line 5289 of file api.cc.
References ENTER_V8, v8::internal::Isolate::heap(), and v8::Utils::OpenHandle().
void v8::Context::DetachGlobal | ( | ) |
Detaches the global object from its context before the global object can be reused to create a new context.
Definition at line 5281 of file api.cc.
References v8::internal::Isolate::bootstrapper(), ENTER_V8, and v8::Utils::OpenHandle().
void v8::Context::Enter | ( | ) |
Enter this context.
After entering a context, all code compiled and run is compiled and run in this context. If another context is already entered, this old context is saved so it can be restored when the new context is exited.
Definition at line 612 of file api.cc.
References v8::internal::Isolate::context(), ENTER_V8, v8::internal::HandleScopeImplementer::EnterContext(), v8::internal::Isolate::handle_scope_implementer(), v8::Utils::OpenHandle(), v8::internal::HandleScopeImplementer::SaveContext(), and v8::internal::Isolate::set_context().
void v8::Context::Exit | ( | ) |
Exit this context.
Exiting the current context restores the context that was in place when entering the current context.
Definition at line 623 of file api.cc.
References v8::Utils::ApiCheck(), ENTER_V8, v8::internal::Isolate::handle_scope_implementer(), v8::internal::HandleScopeImplementer::LastEnteredContextWas(), v8::internal::HandleScopeImplementer::LeaveContext(), v8::Utils::OpenHandle(), v8::internal::HandleScopeImplementer::RestoreContext(), and v8::internal::Isolate::set_context().
|
inline |
Gets a 2-byte-aligned native pointer from the embedder data with the given index, which must have bees set by a previous call to SetAlignedPointerInEmbedderData with the same index.
Note that index 0 currently has a special meaning for Chrome's debugger.
Definition at line 6954 of file v8.h.
References I.
Referenced by SetAlignedPointerInEmbedderData().
Gets the embedder data with the given index, which must have been set by a previous call to SetEmbedderData with the same index.
Note that index 0 currently has a special meaning for Chrome's debugger.
Definition at line 6939 of file v8.h.
References v8::HandleScope::CreateHandle(), and I.
Referenced by SetEmbedderData().
v8::Isolate * v8::Context::GetIsolate | ( | ) |
Returns an isolate associated with a current context.
Definition at line 5261 of file api.cc.
References v8::Utils::OpenHandle().
Returns the security token of this context.
Definition at line 5252 of file api.cc.
References v8::Utils::OpenHandle(), and v8::Utils::ToLocal().
v8::Local< v8::Object > v8::Context::Global | ( | ) |
Returns the global proxy object.
Global proxy object is a thin wrapper whose prototype points to actual context's global object with the properties like Object, etc. This is done that way for security reasons (for more details see https://wiki.mozilla.org/Gecko:SplitWindow).
Please note that changes to global proxy object prototype most probably would break VM—v8 expects only global object as a prototype of global proxy object.
Definition at line 5267 of file api.cc.
References v8::Utils::OpenHandle(), and v8::Utils::ToLocal().
bool v8::Context::IsCodeGenerationFromStringsAllowed | ( | ) |
Returns true if code generation from strings is allowed for the context.
For more details see AllowCodeGenerationFromStrings(bool) documentation.
Definition at line 5298 of file api.cc.
References v8::Utils::OpenHandle().
|
static |
Creates a new context and returns a handle to the newly allocated context.
isolate | The isolate in which to create the context. |
extensions | An optional extension configuration containing the extensions to be installed in the newly created context. |
global_template | An optional object template from which the global object for the newly created context will be created. |
global_object | An optional global object to be reused for the newly created context. This global object must have been created by a previous call to Context::New with the same global template. The state of the global object will be completely reset and only object identify will remain. |
Definition at line 5217 of file api.cc.
References v8::internal::HandleScope::CloseAndEscape(), v8::CreateEnvironment(), v8::internal::Handle< T >::is_null(), LOG_API, NULL, ON_BAILOUT, and v8::Utils::ToLocal().
Referenced by v8::Shell::CreateEvaluationContext(), v8::Shell::InitializeDebugger(), main(), and v8::Shell::RealmCreate().
void v8::Context::SetAlignedPointerInEmbedderData | ( | int | index, |
void * | value | ||
) |
Sets a 2-byte-aligned native pointer in the embedder data with the given index, growing the data as needed.
Note that index 0 currently has a special meaning for Chrome's debugger.
Definition at line 702 of file api.cc.
References DCHECK_EQ, v8::EmbedderDataFor(), v8::EncodeAlignedAsSmi(), and GetAlignedPointerFromEmbedderData().
void v8::Context::SetEmbedderData | ( | int | index, |
v8::Handle< Value > | value | ||
) |
Sets the embedder data with the given index, growing the data as needed.
Note that index 0 currently has a special meaning for Chrome's debugger.
Definition at line 683 of file api.cc.
References DCHECK_EQ, v8::EmbedderDataFor(), GetEmbedderData(), v8::internal::Handle< T >::is_null(), and v8::Utils::OpenHandle().
Sets the error description for the exception that is thrown when code generation from strings is not allowed and 'eval' or the 'Function' constructor are called.
Definition at line 5304 of file api.cc.
References v8::Utils::OpenHandle().
Sets the security token for the context.
To access an object in another context, the security tokens must match.
Definition at line 5235 of file api.cc.
References ENTER_V8, and v8::Utils::OpenHandle().
|
private |
Definition at line 694 of file api.cc.
References v8::DecodeSmiToAligned(), v8::EmbedderDataFor(), v8::internal::Handle< T >::is_null(), and NULL.
Definition at line 674 of file api.cc.
References v8::EmbedderDataFor(), v8::internal::Handle< T >::is_null(), and v8::Utils::ToLocal().
void v8::Context::UseDefaultSecurityToken | ( | ) |
Restores the security token to the default value.
Definition at line 5244 of file api.cc.
References ENTER_V8, and v8::Utils::OpenHandle().