当前位置: 首页>>代码示例>>C++>>正文


C++ Handle::Global方法代码示例

本文整理汇总了C++中v8::Handle::Global方法的典型用法代码示例。如果您正苦于以下问题:C++ Handle::Global方法的具体用法?C++ Handle::Global怎么用?C++ Handle::Global使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在v8::Handle的用法示例。


在下文中一共展示了Handle::Global方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: callListenerFunction

void V8AbstractEventListener::invokeEventHandler(v8::Handle<v8::Context> v8Context, Event* event, v8::Handle<v8::Value> jsEvent)
{
    // We push the event being processed into the global object, so that it can be exposed by DOMWindow's bindings.
    v8::Local<v8::String> eventSymbol = v8::String::NewSymbol("event");
    v8::Local<v8::Value> returnValue;

    // In beforeunload/unload handlers, we want to avoid sleeps which do tight loops of calling Date.getTime().
    if (event->type() == "beforeunload" || event->type() == "unload")
        DateExtension::get()->setAllowSleep(false);

    {
        // Catch exceptions thrown in the event handler so they do not propagate to javascript code that caused the event to fire.
        v8::TryCatch tryCatch;
        tryCatch.SetVerbose(true);

        // Save the old 'event' property so we can restore it later.
        v8::Local<v8::Value> savedEvent = v8Context->Global()->GetHiddenValue(eventSymbol);
        tryCatch.Reset();

        // Make the event available in the global object, so DOMWindow can expose it.
        v8Context->Global()->SetHiddenValue(eventSymbol, jsEvent);
        tryCatch.Reset();

        // Call the event handler.
        tryCatch.SetVerbose(false); // We do not want to report the exception to the inspector console.
        returnValue = callListenerFunction(jsEvent, event);
        if (!tryCatch.CanContinue())
            return;

        // If an error occurs while handling the event, it should be reported.
        if (tryCatch.HasCaught()) {
            reportException(0, tryCatch);
            tryCatch.Reset();
        }

        // Restore the old event. This must be done for all exit paths through this method.
        tryCatch.SetVerbose(true);
        if (savedEvent.IsEmpty())
            v8Context->Global()->SetHiddenValue(eventSymbol, v8::Undefined());
        else
            v8Context->Global()->SetHiddenValue(eventSymbol, savedEvent);
        tryCatch.Reset();
    }

    if (event->type() == "beforeunload" || event->type() == "unload")
        DateExtension::get()->setAllowSleep(true);

    ASSERT(!V8Proxy::handleOutOfMemory() || returnValue.IsEmpty());

    if (returnValue.IsEmpty())
        return;

    if (!returnValue->IsNull() && !returnValue->IsUndefined() && event->storesResultAsString())
        event->storeResult(toWebCoreString(returnValue));

    // Prevent default action if the return value is false;
    // FIXME: Add example, and reference to bug entry.
    if (m_isAttribute && returnValue->IsBoolean() && !returnValue->BooleanValue())
        event->preventDefault();
}
开发者ID:jackiekaon,项目名称:owb-mirror,代码行数:60,代码来源:V8AbstractEventListener.cpp

示例2: sendToCtrlServer

    int sendToCtrlServer(MsgHeader *mh, Buffer *buffer) {
        DBG("sendToCtrlServer E: cmd=%d token=%lld", mh->cmd(), mh->token());

        int status = STATUS_OK;
        v8::HandleScope handle_scope;
        v8::TryCatch try_catch;
        try_catch.SetVerbose(true);

        // Get the onRilRequest Function
        v8::Handle<v8::String> name = v8::String::New("onCtrlServerCmd");
        v8::Handle<v8::Value> onCtrlServerCmdFunctionValue =
                context_->Global()->Get(name);
        v8::Handle<v8::Function> onCtrlServerCmdFunction =
                v8::Handle<v8::Function>::Cast(onCtrlServerCmdFunctionValue);

        // Create the CmdValue and TokenValue
        v8::Handle<v8::Value> v8CmdValue = v8::Number::New(mh->cmd());
        v8::Handle<v8::Value> v8TokenValue = v8::Number::New(mh->token());

        // Invoke onRilRequest
        const int argc = 3;
        v8::Handle<v8::Value> buf;
        if (mh->length_data() == 0) {
            buf = v8::Undefined();
        } else {
            buf = buffer->handle_;
        }
        v8::Handle<v8::Value> argv[argc] = {
                v8CmdValue, v8TokenValue, buf };
        v8::Handle<v8::Value> result =
            onCtrlServerCmdFunction->Call(context_->Global(), argc, argv);
        if (try_catch.HasCaught()) {
            ReportException(&try_catch);
            status = STATUS_ERR;
        } else {
            v8::String::Utf8Value result_string(result);
            DBG("sendToCtrlServer result=%s", ToCString(result_string));
            status = STATUS_OK;
        }

        if (status != STATUS_OK) {
            LOGE("sendToCtrlServer Error: status=%d", status);
            // An error report complete now
            mh->set_length_data(0);
            mh->set_status(ril_proto::CTRL_STATUS_ERR);
            g_ctrl_server->WriteMessage(mh, NULL);
        }

        DBG("sendToCtrlServer X: status=%d", status);
        return status;
    }
开发者ID:ACSOP,项目名称:android_hardware_ril,代码行数:51,代码来源:ctrl_server.cpp

示例3: executeUtilityFunction

String DebuggerAgentImpl::executeUtilityFunction(
    v8::Handle<v8::Context> context,
    int callId,
    const char* object,
    const String &functionName,
    const String& jsonArgs,
    bool async,
    String* exception)
{
    v8::HandleScope scope;
    ASSERT(!context.IsEmpty());
    if (context.IsEmpty()) {
        *exception = "No window context.";
        return "";
    }
    v8::Context::Scope contextScope(context);

    DebuggerAgentManager::UtilityContextScope utilityScope;

    v8::Handle<v8::Object> dispatchObject = v8::Handle<v8::Object>::Cast(
        context->Global()->Get(v8::String::New(object)));

    v8::Handle<v8::Value> dispatchFunction = dispatchObject->Get(v8::String::New("dispatch"));
    ASSERT(dispatchFunction->IsFunction());
    v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(dispatchFunction);

    v8::Handle<v8::String> functionNameWrapper = v8::Handle<v8::String>(
        v8::String::New(functionName.utf8().data()));
    v8::Handle<v8::String> jsonArgsWrapper = v8::Handle<v8::String>(
        v8::String::New(jsonArgs.utf8().data()));
    v8::Handle<v8::Number> callIdWrapper = v8::Handle<v8::Number>(
        v8::Number::New(async ? callId : 0));

    v8::Handle<v8::Value> args[] = {
        functionNameWrapper,
        jsonArgsWrapper,
        callIdWrapper
    };

    v8::TryCatch tryCatch;
    v8::Handle<v8::Value> resObj = function->Call(context->Global(), 3, args);
    if (tryCatch.HasCaught()) {
        v8::Local<v8::Message> message = tryCatch.Message();
        if (message.IsEmpty())
            *exception = "Unknown exception";
        else
            *exception = WebCore::toWebCoreString(message->Get());
        return "";
    }
    return WebCore::toWebCoreStringWithNullCheck(resObj);
}
开发者ID:mikedougherty,项目名称:webkit,代码行数:51,代码来源:DebuggerAgentImpl.cpp

示例4:

void V8Proxy::installHiddenObjectPrototype(v8::Handle<v8::Context> context)
{
    v8::Handle<v8::String> objectString = v8::String::New("Object");
    v8::Handle<v8::String> prototypeString = v8::String::New("prototype");
    v8::Handle<v8::String> hiddenObjectPrototypeString = V8HiddenPropertyName::objectPrototype();
    // Bail out if allocation failed.
    if (objectString.IsEmpty() || prototypeString.IsEmpty() || hiddenObjectPrototypeString.IsEmpty())
        return;

    v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(context->Global()->Get(objectString));
    v8::Handle<v8::Value> objectPrototype = object->Get(prototypeString);

    context->Global()->SetHiddenValue(hiddenObjectPrototypeString, objectPrototype);
}
开发者ID:jackiekaon,项目名称:owb-mirror,代码行数:14,代码来源:V8Proxy.cpp

示例5: TRI_InitV8Shell

void TRI_InitV8Shell (v8::Handle<v8::Context> context) {
  v8::HandleScope scope;

  // .............................................................................
  // create the global functions
  // .............................................................................

  context->Global()->Set(v8::String::New("processCsvFile"),
                         v8::FunctionTemplate::New(JS_ProcessCsvFile)->GetFunction(),
                         v8::ReadOnly);

  context->Global()->Set(v8::String::New("processJsonFile"),
                         v8::FunctionTemplate::New(JS_ProcessJsonFile)->GetFunction(),
                         v8::ReadOnly);
}
开发者ID:mokerjoke,项目名称:ArangoDB,代码行数:15,代码来源:v8-shell.cpp

示例6: debug_checkCurrentContextX

//This function just prints out all properties associated with context ctx has
//additional parameter additionalMessage which prints out at the top of this
//function's debugging message.  additionalMessage arose as a nice way to print
//the context multiple times and still be able to keep straight which printout
//was associated with which call to debug_checkCurrentContextX by specifying
//unique additionalMessages each time the function was called.
void debug_checkCurrentContextX(v8::Handle<v8::Context> ctx, std::string additionalMessage)
{
    v8::HandleScope handle_scope;
    std::cout<<"\n\n\nDoing checkCurrentContext with value passed in of: "<<additionalMessage<<"\n\n";
    printAllPropertyNames(ctx->Global());
    std::cout<<"\n\n";
}
开发者ID:AsherBond,项目名称:sirikata,代码行数:13,代码来源:JSObjectsUtils.cpp

示例7: TRI_AddGlobalFunctionVocbase

void TRI_AddGlobalFunctionVocbase (v8::Handle<v8::Context> context,
                                   const char* const name,
                                   v8::Handle<v8::Function> func,
                                   const bool isHidden) {
  // all global functions are read-only
  if (isHidden) {
    context->Global()->Set(TRI_V8_SYMBOL(name),
                           func,
                           static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum));
  }
  else {
    context->Global()->Set(TRI_V8_SYMBOL(name),
                           func,
                           v8::ReadOnly);
  }
}
开发者ID:,项目名称:,代码行数:16,代码来源:

示例8: dialogCreated

inline void DialogHandler::dialogCreated(DOMWindow* dialogFrame)
{
    m_dialogContext = V8Proxy::context(dialogFrame->frame());
    if (m_dialogContext.IsEmpty())
        return;
    if (m_dialogArguments.IsEmpty())
        return;
    v8::Context::Scope scope(m_dialogContext);
    m_dialogContext->Global()->Set(v8::String::New("dialogArguments"), m_dialogArguments);
}
开发者ID:,项目名称:,代码行数:10,代码来源:

示例9: dialogCreated

inline void DialogHandler::dialogCreated(DOMWindow* dialogFrame)
{
    m_dialogContext = dialogFrame->frame() ? dialogFrame->frame()->script()->currentWorldContext() : v8::Local<v8::Context>();
    if (m_dialogContext.IsEmpty())
        return;
    if (m_dialogArguments.IsEmpty())
        return;
    v8::Context::Scope scope(m_dialogContext);
    m_dialogContext->Global()->Set(v8::String::NewSymbol("dialogArguments"), m_dialogArguments);
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_external_chromium_org_third_party_WebKit,代码行数:10,代码来源:V8WindowCustom.cpp

示例10: scope

inline v8::Handle<v8::Value> DialogHandler::returnValue() const
{
    if (m_dialogContext.IsEmpty())
        return v8::Undefined();
    v8::Context::Scope scope(m_dialogContext);
    v8::Handle<v8::Value> returnValue = m_dialogContext->Global()->Get(v8::String::NewSymbol("returnValue"));
    if (returnValue.IsEmpty())
        return v8::Undefined();
    return returnValue;
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_external_chromium_org_third_party_WebKit,代码行数:10,代码来源:V8WindowCustom.cpp

示例11: scope

inline v8::Handle<v8::Value> DialogHandler::returnValue(v8::Isolate* isolate) const
{
    if (m_dialogContext.IsEmpty())
        return v8::Undefined(isolate);
    v8::Context::Scope scope(m_dialogContext);
    v8::Handle<v8::Value> returnValue = m_dialogContext->Global()->Get(v8AtomicString(isolate, "returnValue"));
    if (returnValue.IsEmpty())
        return v8::Undefined(isolate);
    return returnValue;
}
开发者ID:jeremyroman,项目名称:blink,代码行数:10,代码来源:V8WindowCustom.cpp

示例12: CustomElementBindingMap

V8PerContextData::V8PerContextData(v8::Handle<v8::Context> context)
    : m_isolate(context->GetIsolate())
    , m_wrapperBoilerplates(m_isolate)
    , m_constructorMap(m_isolate)
    , m_contextHolder(adoptPtr(new gin::ContextHolder(m_isolate)))
    , m_context(m_isolate, context)
    , m_customElementBindings(adoptPtr(new CustomElementBindingMap()))
{
    m_contextHolder->SetContext(context);

    v8::Context::Scope contextScope(context);
    ASSERT(m_errorPrototype.isEmpty());
    v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(context->Global()->Get(v8AtomicString(m_isolate, "Error")));
    ASSERT(!object.IsEmpty());
    v8::Handle<v8::Value> prototypeValue = object->Get(v8AtomicString(m_isolate, "prototype"));
    ASSERT(!prototypeValue.IsEmpty());
    m_errorPrototype.set(m_isolate, prototypeValue);

    m_functionConstructor.set(m_isolate, v8::Handle<v8::Function>::Cast(context->Global()->Get(v8AtomicString(m_isolate, "Function"))));
}
开发者ID:dalecurtis,项目名称:mojo,代码行数:20,代码来源:V8PerContextData.cpp

示例13: dialogCreated

inline void DialogHandler::dialogCreated(DOMWindow* dialogFrame, v8::Isolate* isolate)
{
    // FIXME: It's wrong to use the current world. Instead we should use the world
    // from which the modal dialog was requested.
    m_dialogContext = dialogFrame->frame() ? toV8Context(isolate, dialogFrame->frame(), DOMWrapperWorld::current(isolate)) : v8::Local<v8::Context>();
    if (m_dialogContext.IsEmpty())
        return;
    if (m_dialogArguments.IsEmpty())
        return;
    v8::Context::Scope scope(m_dialogContext);
    m_dialogContext->Global()->Set(v8AtomicString(isolate, "dialogArguments"), m_dialogArguments);
}
开发者ID:jeremyroman,项目名称:blink,代码行数:12,代码来源:V8WindowCustom.cpp

示例14:

bool V8DOMWindowShell::installHiddenObjectPrototype(v8::Handle<v8::Context> context)
{
    v8::Handle<v8::String> objectString = v8::String::New("Object");
    v8::Handle<v8::String> prototypeString = v8::String::New("prototype");
    v8::Handle<v8::String> hiddenObjectPrototypeString = V8HiddenPropertyName::objectPrototype();
    // Bail out if allocation failed.
    if (objectString.IsEmpty() || prototypeString.IsEmpty() || hiddenObjectPrototypeString.IsEmpty())
        return false;

    v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(context->Global()->Get(objectString));
    // Bail out if fetching failed.
    if (object.IsEmpty())
        return false;
    v8::Handle<v8::Value> objectPrototype = object->Get(prototypeString);
    // Bail out if fetching failed.
    if (objectPrototype.IsEmpty())
        return false;

    context->Global()->SetHiddenValue(hiddenObjectPrototypeString, objectPrototype);

    return true;
}
开发者ID:azrul2202,项目名称:WebKit-Smartphone,代码行数:22,代码来源:V8DOMWindowShell.cpp

示例15: callOnRilRequest

int callOnRilRequest(v8::Handle<v8::Context> context, int cmd,
                   const void *buffer, RIL_Token t) {
    DBG("callOnRilRequest E: cmd=%d", cmd);

    int status;
    v8::HandleScope handle_scope;
    v8::TryCatch try_catch;

    // Get the onRilRequest Function
    v8::Handle<v8::String> name = v8::String::New("onRilRequest");
    v8::Handle<v8::Value> onRilRequestFunctionValue = context->Global()->Get(name);
    v8::Handle<v8::Function> onRilRequestFunction =
        v8::Handle<v8::Function>::Cast(onRilRequestFunctionValue);

    // Create the cmd and token
    v8::Handle<v8::Value> v8RequestValue = v8::Number::New(cmd);
    v8::Handle<v8::Value> v8TokenValue = v8::Number::New(int64_t(t));

    // Invoke onRilRequest
    const int argc = 3;
    v8::Handle<v8::Value> argv[argc] = {
            v8RequestValue, v8TokenValue, ((Buffer *)buffer)->handle_ };
    v8::Handle<v8::Value> result =
        onRilRequestFunction->Call(context->Global(), argc, argv);
    if (try_catch.HasCaught()) {
        ALOGE("callOnRilRequest error");
        ReportException(&try_catch);
        status = STATUS_ERR;
    } else {
        v8::String::Utf8Value result_string(result);
        DBG("callOnRilRequest result=%s", ToCString(result_string));
        status = STATUS_OK;
    }

    DBG("callOnRilRequest X: status=%d", status);
    return status;
}
开发者ID:0omega,项目名称:platform_hardware_ril,代码行数:37,代码来源:requests.cpp


注:本文中的v8::Handle::Global方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。