本文整理汇总了C++中contextScope函数的典型用法代码示例。如果您正苦于以下问题:C++ contextScope函数的具体用法?C++ contextScope怎么用?C++ contextScope使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了contextScope函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: contextScope
PassRefPtr<InspectorValue> ScriptValue::toInspectorValue(ScriptState* scriptState) const
{
v8::HandleScope handleScope;
// v8::Object::GetPropertyNames() expects current context to be not null.
v8::Context::Scope contextScope(scriptState->context());
return v8ToInspectorValue(v8ValueRaw(), InspectorValue::maxDepth);
}
开发者ID:Channely,项目名称:know-your-chrome,代码行数:7,代码来源:ScriptValue.cpp
示例2: contextScope
bool Script::runString(std::string const& code, std::string const& filename)
{
v8::HandleScope scope;
v8::Context::Scope contextScope(m_context);
v8::TryCatch tryCatch;
// Create a v8 string to hold the source
v8::Handle<v8::String> source = v8::String::New(code.c_str(), code.size());
// Compile the script
v8::Handle<v8::Script> script = v8::Script::Compile(source, v8::String::New(filename.c_str()));
if (script.IsEmpty())
{
v8::String::Utf8Value error(tryCatch.Exception());
v8::Handle<v8::Message> message = tryCatch.Message();
std::cerr << "+----" << std::endl;
std::cerr << "| Error in " << filename.c_str() << ":" << *error << std::endl;
std::cerr << "| (" << message->GetLineNumber() << "):" << *v8::String::Utf8Value(message->GetSourceLine()) << std::endl;
std::cerr << "+----" << std::endl;
return false;
}
// Finally we run the script
v8::Handle<v8::Value> result = script->Run();
if (result.IsEmpty())
{
v8::String::Utf8Value error(tryCatch.Exception());
std::cerr << "Script Error: " << *error << std::endl;
return false;
}
return true;
}
开发者ID:caivega,项目名称:canvas-cpp,代码行数:34,代码来源:Script.cpp
示例3: scope
void Runtime::runMainScript()
{
v8::HandleScope scope(v8::Isolate::GetCurrent());
v8::Handle<v8::Context> context = v8::Context::New(
v8::Isolate::GetCurrent());
v8::Context::Scope contextScope(context);
m_sip = new JsSIPObject(m_sipFactory);
m_sip->createObjectInstance(context->Global(), "sip");
v8::TryCatch tryCatch;
std::string mainScript;
loadMainScript(mainScript);
v8::Handle<v8::Script> script = v8::Script::Compile(
v8::String::New(mainScript.c_str()),
v8::String::New(m_scriptFileName.c_str()));
if (script.IsEmpty())
{
throw Exception(JsProxyBase::toString(tryCatch.Exception()).c_str());
}
v8::Handle<v8::Value> result = script->Run();
if (result.IsEmpty())
{
// TODO: add log
v8::String::Utf8Value stackTrace(tryCatch.StackTrace());
if (stackTrace.length() > 0)
{
throw Exception(*stackTrace);
}
throw Exception(JsProxyBase::toString(tryCatch.Exception()).c_str());
}
}
开发者ID:mustaphamond,项目名称:jessip,代码行数:31,代码来源:Runtime.cpp
示例4: contextScope
void WorkerScriptDebugServer::addListener(ScriptDebugListener* listener, WorkerContext* workerContext)
{
v8::HandleScope scope;
v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext();
v8::Context::Scope contextScope(debuggerContext);
if (!m_listenersMap.size()) {
// FIXME: synchronize access to this code.
ensureDebuggerScriptCompiled();
ASSERT(!m_debuggerScript.get()->IsUndefined());
v8::Debug::SetDebugEventListener2(&WorkerScriptDebugServer::v8DebugEventCallback, v8::External::New(this));
}
m_listenersMap.set(workerContext, listener);
WorkerContextExecutionProxy* proxy = workerContext->script()->proxy();
if (!proxy)
return;
v8::Handle<v8::Context> context = proxy->context();
v8::Handle<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast(m_debuggerScript.get()->Get(v8::String::New("getWorkerScripts")));
v8::Handle<v8::Value> argv[] = { v8::Handle<v8::Value>() };
v8::Handle<v8::Value> value = getScriptsFunction->Call(m_debuggerScript.get(), 0, argv);
if (value.IsEmpty())
return;
ASSERT(!value->IsUndefined() && value->IsArray());
v8::Handle<v8::Array> scriptsArray = v8::Handle<v8::Array>::Cast(value);
for (unsigned i = 0; i < scriptsArray->Length(); ++i)
dispatchDidParseSource(listener, v8::Handle<v8::Object>::Cast(scriptsArray->Get(v8::Integer::New(i))));
}
开发者ID:Xertz,项目名称:EAWebKit,代码行数:29,代码来源:WorkerScriptDebugServer.cpp
示例5: scope
/**
* Assign a variable to the javascript context
*
* @param params array of parameters:
* - string name of property to assign required
* - mixed property value to assign required
* - integer property attributes optional
*
* The property attributes can be one of the following values
*
* - ReadOnly
* - DontEnum
* - DontDelete
*
* If not specified, the property will be writable, enumerable and
* deletable.
*/
void Context::assign(Php::Parameters ¶ms)
{
// create a local "scope" and "enter" our context
v8::HandleScope scope(isolate());
v8::Context::Scope contextScope(_context);
// retrieve the global object from the context
v8::Local<v8::Object> global(_context->Global());
// the attribute for the newly assigned property
v8::PropertyAttribute attribute(v8::None);
// if an attribute was given, assign it
if (params.size() > 2)
{
// check the attribute that was selected
switch ((int16_t)params[2])
{
case v8::None: attribute = v8::None; break;
case v8::ReadOnly: attribute = v8::ReadOnly; break;
case v8::DontDelete: attribute = v8::DontDelete; break;
case v8::DontEnum: attribute = v8::DontEnum; break;
}
}
// and store the value
global->ForceSet(value(params[0]), value(params[1]), attribute);
}
开发者ID:hanigamal,项目名称:PHP-JS,代码行数:45,代码来源:context.cpp
示例6: handleScope
// Install the constructor in the global scope so Path2Ds can be constructed
// in JS.
void Path2D::AddToGlobal(Global* global) {
gGlobal = global;
// Create a stack-allocated handle scope.
HandleScope handleScope(gGlobal->getIsolate());
Handle<Context> context = gGlobal->getContext();
// Enter the scope so all operations take place in the scope.
Context::Scope contextScope(context);
Local<FunctionTemplate> constructor = FunctionTemplate::New(
gGlobal->getIsolate(), Path2D::ConstructPath);
constructor->InstanceTemplate()->SetInternalFieldCount(1);
ADD_METHOD("closePath", ClosePath);
ADD_METHOD("moveTo", MoveTo);
ADD_METHOD("lineTo", LineTo);
ADD_METHOD("quadraticCurveTo", QuadraticCurveTo);
ADD_METHOD("bezierCurveTo", BezierCurveTo);
ADD_METHOD("arc", Arc);
ADD_METHOD("rect", Rect);
ADD_METHOD("oval", Oval);
ADD_METHOD("conicTo", ConicTo);
context->Global()->Set(String::NewFromUtf8(
gGlobal->getIsolate(), "Path2D"), constructor->GetFunction());
}
开发者ID:Adenilson,项目名称:skia,代码行数:30,代码来源:Path2D.cpp
示例7: contextScope
String JavaScriptCallFrame::functionName() const
{
v8::HandleScope handleScope;
v8::Context::Scope contextScope(m_debuggerContext.get());
v8::Handle<v8::Value> result = m_callFrame.get()->Get(v8String("functionName"));
return toWebCoreStringWithNullOrUndefinedCheck(result);
}
开发者ID:0omega,项目名称:platform_external_webkit,代码行数:7,代码来源:JavaScriptCallFrame.cpp
示例8: isolateScope
bool JSONParser::parse(const String& json)
{
v8::Isolate* isolate = v8::Isolate::New();
const v8::Isolate::Scope isolateScope(isolate);
v8::HandleScope handleScope;
v8::Handle<v8::ObjectTemplate> globalTemplate = v8::ObjectTemplate::New();
#ifdef V8_NEW_CONTEXT_TAKES_ISOLATE
v8::Handle<v8::Context> context = v8::Context::New(isolate, 0, globalTemplate);
#else
v8::Handle<v8::Context> context = v8::Context::New(0, globalTemplate);
#endif
v8::Context::Scope contextScope(context);
v8::Handle<v8::Object> global = context->Global();
v8::Handle<v8::Object> JSON = global->Get(v8::String::New("JSON"))->ToObject();
v8::Handle<v8::Function> JSON_parse = v8::Handle<v8::Function>::Cast(JSON->Get(v8::String::New("parse")));
v8::Handle<v8::Value> data = v8::String::New(json.constData(), json.size());
v8::Handle<v8::Value> value = JSON_parse->Call(JSON, 1, &data);
mRoot = v8ValueToValue(value);
//isolate->Dispose();
return isValid();
}
开发者ID:Silex,项目名称:rtags,代码行数:26,代码来源:JSONParser.cpp
示例9: eventListenerHandlerLocation
bool eventListenerHandlerLocation(Document* document, EventListener* listener, String& sourceName, String& scriptId, int& lineNumber)
{
if (listener->type() != EventListener::JSEventListenerType)
return false;
v8::HandleScope scope(toIsolate(document));
V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>(listener);
v8::Handle<v8::Context> context = toV8Context(document, v8Listener->world());
v8::Context::Scope contextScope(context);
v8::Local<v8::Object> object = v8Listener->getListenerObject(document);
if (object.IsEmpty())
return false;
v8::Handle<v8::Function> function = eventListenerEffectiveFunction(scope.GetIsolate(), object);
if (function.IsEmpty())
return false;
v8::Handle<v8::Function> originalFunction = getBoundFunction(function);
int scriptIdValue = originalFunction->ScriptId();
scriptId = String::number(scriptIdValue);
v8::ScriptOrigin origin = originalFunction->GetScriptOrigin();
if (!origin.ResourceName().IsEmpty() && origin.ResourceName()->IsString())
sourceName = toCoreString(origin.ResourceName().As<v8::String>());
else
sourceName = "";
lineNumber = originalFunction->GetScriptLineNumber();
return true;
}
开发者ID:kublaj,项目名称:blink,代码行数:26,代码来源:ScriptEventListener.cpp
示例10: TEST_F
TEST_F(AnimationAnimationTest, TimingInputDirection)
{
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope contextScope(context);
Timing timing;
Timing::PlaybackDirection defaultPlaybackDirection = Timing::PlaybackDirectionNormal;
EXPECT_EQ(defaultPlaybackDirection, timing.direction);
applyTimingInputString(timing, isolate, "direction", "normal");
EXPECT_EQ(Timing::PlaybackDirectionNormal, timing.direction);
timing.direction = defaultPlaybackDirection;
applyTimingInputString(timing, isolate, "direction", "reverse");
EXPECT_EQ(Timing::PlaybackDirectionReverse, timing.direction);
timing.direction = defaultPlaybackDirection;
applyTimingInputString(timing, isolate, "direction", "alternate");
EXPECT_EQ(Timing::PlaybackDirectionAlternate, timing.direction);
timing.direction = defaultPlaybackDirection;
applyTimingInputString(timing, isolate, "direction", "alternate-reverse");
EXPECT_EQ(Timing::PlaybackDirectionAlternateReverse, timing.direction);
timing.direction = defaultPlaybackDirection;
applyTimingInputString(timing, isolate, "direction", "rubbish");
EXPECT_EQ(defaultPlaybackDirection, timing.direction);
timing.direction = defaultPlaybackDirection;
applyTimingInputNumber(timing, isolate, "direction", 2);
EXPECT_EQ(defaultPlaybackDirection, timing.direction);
timing.direction = defaultPlaybackDirection;
}
开发者ID:wangshijun,项目名称:Blink,代码行数:35,代码来源:AnimationTest.cpp
示例11: ASSERT
// Create the utility context for holding JavaScript functions used internally
// which are not visible to JavaScript executing on the page.
void V8Proxy::createUtilityContext()
{
ASSERT(m_utilityContext.IsEmpty());
v8::HandleScope scope;
v8::Handle<v8::ObjectTemplate> globalTemplate = v8::ObjectTemplate::New();
m_utilityContext = v8::Context::New(0, globalTemplate);
v8::Context::Scope contextScope(m_utilityContext);
// Compile JavaScript function for retrieving the source line of the top
// JavaScript stack frame.
DEFINE_STATIC_LOCAL(const char*, frameSourceLineSource,
("function frameSourceLine(exec_state) {"
" return exec_state.frame(0).sourceLine();"
"}"));
v8::Script::Compile(v8::String::New(frameSourceLineSource))->Run();
// Compile JavaScript function for retrieving the source name of the top
// JavaScript stack frame.
DEFINE_STATIC_LOCAL(const char*, frameSourceNameSource,
("function frameSourceName(exec_state) {"
" var frame = exec_state.frame(0);"
" if (frame.func().resolved() && "
" frame.func().script() && "
" frame.func().script().name()) {"
" return frame.func().script().name();"
" }"
"}"));
v8::Script::Compile(v8::String::New(frameSourceNameSource))->Run();
}
开发者ID:325116067,项目名称:semc-qsd8x50,代码行数:32,代码来源:V8Proxy.cpp
示例12: disconnectEventListeners
void V8Proxy::clearForNavigation()
{
disconnectEventListeners();
if (!context().IsEmpty()) {
v8::HandleScope handle;
clearDocumentWrapper();
v8::Context::Scope contextScope(context());
// Clear the document wrapper cache before turning on access checks on
// the old DOMWindow wrapper. This way, access to the document wrapper
// will be protected by the security checks on the DOMWindow wrapper.
clearDocumentWrapperCache();
// Turn on access check on the old DOMWindow wrapper.
v8::Handle<v8::Object> wrapper = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::DOMWINDOW, m_global);
ASSERT(!wrapper.IsEmpty());
wrapper->TurnOnAccessCheck();
// Separate the context from its global object.
context()->DetachGlobal();
disposeContextHandles();
}
}
开发者ID:jackiekaon,项目名称:owb-mirror,代码行数:25,代码来源:V8Proxy.cpp
示例13: handleScope
PassRefPtr<JSONValue> ScriptValue::toJSONValue(ScriptState* scriptState) const
{
v8::HandleScope handleScope(scriptState->isolate());
// v8::Object::GetPropertyNames() expects current context to be not null.
v8::Context::Scope contextScope(scriptState->context());
return v8ToJSONValue(v8Value(), JSONValue::maxDepth, scriptState->isolate());
}
开发者ID:Tkkg1994,项目名称:Platfrom-kccat6,代码行数:7,代码来源:ScriptValue.cpp
示例14: contextScope
void V8Proxy::updateDocumentWrapperCache()
{
v8::HandleScope handleScope;
v8::Context::Scope contextScope(context());
// If the document has no frame, NodeToV8Object might get the
// document wrapper for a document that is about to be deleted.
// If the ForceSet below causes a garbage collection, the document
// might get deleted and the global handle for the document
// wrapper cleared. Using the cleared global handle will lead to
// crashes. In this case we clear the cache and let the DOMWindow
// accessor handle access to the document.
if (!m_frame->document()->frame()) {
clearDocumentWrapperCache();
return;
}
v8::Handle<v8::Value> documentWrapper = V8DOMWrapper::convertNodeToV8Object(m_frame->document());
// If instantiation of the document wrapper fails, clear the cache
// and let the DOMWindow accessor handle access to the document.
if (documentWrapper.IsEmpty()) {
clearDocumentWrapperCache();
return;
}
context()->Global()->ForceSet(v8::String::New("document"), documentWrapper, static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
}
开发者ID:jackiekaon,项目名称:owb-mirror,代码行数:27,代码来源:V8Proxy.cpp
示例15: contextScope
InjectedScript InjectedScriptManager::injectedScriptFor(ScriptState* inspectedScriptState)
{
v8::HandleScope handleScope;
v8::Local<v8::Context> context = inspectedScriptState->context();
v8::Context::Scope contextScope(context);
v8::Local<v8::Object> global = context->Global();
// Skip proxy object. The proxy object will survive page navigation while we need
// an object whose lifetime consides with that of the inspected context.
global = v8::Local<v8::Object>::Cast(global->GetPrototype());
v8::Handle<v8::String> key = V8HiddenPropertyName::devtoolsInjectedScript();
v8::Local<v8::Value> val = global->GetHiddenValue(key);
if (!val.IsEmpty() && val->IsObject())
return InjectedScript(ScriptObject(inspectedScriptState, v8::Local<v8::Object>::Cast(val)), m_inspectedStateAccessCheck);
if (!m_inspectedStateAccessCheck(inspectedScriptState))
return InjectedScript();
pair<long, ScriptObject> injectedScript = injectScript(injectedScriptSource(), inspectedScriptState);
InjectedScript result(injectedScript.second, m_inspectedStateAccessCheck);
m_idToInjectedScript.set(injectedScript.first, result);
global->SetHiddenValue(key, injectedScript.second.v8Object());
return result;
}
开发者ID:xiaolu31,项目名称:webkit-node,代码行数:25,代码来源:V8InjectedScriptManager.cpp
示例16: contextScope
ScriptValue InjectedScriptHost::nodeAsScriptValue(ScriptState* state, Node* node)
{
v8::HandleScope scope;
v8::Local<v8::Context> context = state->context();
v8::Context::Scope contextScope(context);
return ScriptValue(toV8(node));
}
开发者ID:paul99,项目名称:third_party,代码行数:8,代码来源:V8InjectedScriptHostCustom.cpp
示例17: contextScope
void ScriptDebugServer::ensureDebuggerScriptCompiled()
{
if (m_debuggerScript.get().IsEmpty()) {
v8::HandleScope scope;
v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext();
v8::Context::Scope contextScope(debuggerContext);
m_debuggerScript.set(v8::Handle<v8::Object>::Cast(v8::Script::Compile(v8String(m_debuggerScriptSource))->Run()));
}
}
开发者ID:UIKit0,项目名称:WebkitAIR,代码行数:9,代码来源:ScriptDebugServer.cpp
示例18: contextScope
int JavaScriptCallFrame::column() const
{
v8::HandleScope handleScope;
v8::Context::Scope contextScope(m_debuggerContext.get());
v8::Handle<v8::Value> result = m_callFrame.get()->Get(v8String("column"));
if (result->IsInt32())
return result->Int32Value();
return 0;
}
开发者ID:kcomkar,项目名称:webkit,代码行数:9,代码来源:JavaScriptCallFrame.cpp
示例19: handleScope
int JavaScriptCallFrame::column() const
{
v8::HandleScope handleScope(m_isolate);
v8::Context::Scope contextScope(m_debuggerContext.newLocal(m_isolate));
v8::Handle<v8::Value> result = m_callFrame.newLocal(m_isolate)->Get(v8::String::NewSymbol("column"));
if (result->IsInt32())
return result->Int32Value();
return 0;
}
开发者ID:chunywang,项目名称:blink-crosswalk,代码行数:9,代码来源:JavaScriptCallFrame.cpp
注:本文中的contextScope函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论