コード例 #1
0
bool invokeCallback(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext* scriptExecutionContext)
{
    v8::TryCatch exceptionCatcher;
    exceptionCatcher.SetVerbose(true);

    v8::Local<v8::Function> callbackFunction;
    if (callback->IsFunction()) {
        callbackFunction = v8::Local<v8::Function>::New(v8::Persistent<v8::Function>::Cast(callback));
    } else if (callback->IsObject()) {
        v8::Local<v8::Value> handleEventFunction = callback->Get(v8::String::NewSymbol("handleEvent"));
        if (handleEventFunction->IsFunction())
            callbackFunction = v8::Local<v8::Function>::Cast(handleEventFunction);
    } else
        return false;

    if (callbackFunction.IsEmpty())
        return false;

    v8::Handle<v8::Object> thisObject = v8::Context::GetCurrent()->Global();

    Frame* frame = scriptExecutionContext && scriptExecutionContext->isDocument() ? static_cast<Document*>(scriptExecutionContext)->frame() : 0;
    v8::Handle<v8::Value> result = V8Proxy::instrumentedCallFunction(frame, callbackFunction, thisObject, argc, argv);

    callbackReturnValue = !result.IsEmpty() && result->BooleanValue();
    return exceptionCatcher.HasCaught();
}
コード例 #2
0
bool invokeCallback(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue)
{
    // FIXME: If an exception was thrown by the callback, we should report it
    v8::TryCatch exceptionCatcher;

    v8::Local<v8::Function> callbackFunction;
    if (callback->IsFunction()) {
        callbackFunction = v8::Local<v8::Function>::New(v8::Persistent<v8::Function>::Cast(callback));
    } else if (callback->IsObject()) {
        v8::Local<v8::Value> handleEventFunction = callback->Get(v8::String::NewSymbol("handleEvent"));
        if (handleEventFunction->IsFunction()) {
            callbackFunction = v8::Local<v8::Function>::Cast(handleEventFunction);
        }
    } else
        return false;

    if (callbackFunction.IsEmpty())
        return false;

    v8::Handle<v8::Object> thisObject = v8::Context::GetCurrent()->Global();

    V8Proxy* proxy = V8Proxy::retrieve();
    ASSERT(proxy);

    v8::Handle<v8::Value> result = proxy->CallFunction(callbackFunction, thisObject, argc, argv);

    callbackReturnValue = result.IsEmpty() && result->IsBoolean() && result->BooleanValue();

    return exceptionCatcher.HasCaught();
}
コード例 #3
0
bool invokeCallback(v8::Persistent<v8::Object> callback, int argc, v8::Handle<v8::Value> argv[], bool& callbackReturnValue, ScriptExecutionContext* scriptExecutionContext)
{
    v8::TryCatch exceptionCatcher;

    v8::Local<v8::Function> callbackFunction;
    if (callback->IsFunction()) {
        callbackFunction = v8::Local<v8::Function>::New(v8::Persistent<v8::Function>::Cast(callback));
    } else if (callback->IsObject()) {
        v8::Local<v8::Value> handleEventFunction = callback->Get(v8::String::NewSymbol("handleEvent"));
        if (handleEventFunction->IsFunction())
            callbackFunction = v8::Local<v8::Function>::Cast(handleEventFunction);
    } else
        return false;

    if (callbackFunction.IsEmpty())
        return false;

    v8::Handle<v8::Object> thisObject = v8::Context::GetCurrent()->Global();

    v8::Handle<v8::Value> result = callbackFunction->Call(thisObject, argc, argv);
    callbackReturnValue = !result.IsEmpty() && result->BooleanValue();

    if (exceptionCatcher.HasCaught()) {
        v8::Local<v8::Message> message = exceptionCatcher.Message();
        scriptExecutionContext->reportException(toWebCoreString(message->Get()), message->GetLineNumber(), toWebCoreString(message->GetScriptResourceName()));
        return true;
    }

    return false;
}
コード例 #4
0
ファイル: utils.cpp プロジェクト: aaronpdennis/node-osmium
    v8::Handle<v8::Value> create_js_box(const osmium::Box& box) {
        v8::HandleScope scope;

        if (!box.valid()) {
            return scope.Close(v8::Undefined());
        }

        auto cf = module->Get(symbol_Coordinates);
        assert(cf->IsFunction());
        auto bf = module->Get(symbol_Box);
        assert(bf->IsFunction());

        v8::Local<v8::Value> argv_bl[2] = { v8::Number::New(box.bottom_left().lon()), v8::Number::New(box.bottom_left().lat()) };
        auto bottom_left = v8::Local<v8::Function>::Cast(cf)->NewInstance(2, argv_bl);

        v8::Local<v8::Value> argv_tr[2] = { v8::Number::New(box.top_right().lon()), v8::Number::New(box.top_right().lat()) };
        auto top_right = v8::Local<v8::Function>::Cast(cf)->NewInstance(2, argv_tr);

        v8::Local<v8::Value> argv_box[2] = { bottom_left, top_right };
        return scope.Close(v8::Local<v8::Function>::Cast(bf)->NewInstance(2, argv_box));
    }
コード例 #5
0
    v8::Handle<v8::Value> OSMNodeWrap::get_coordinates(v8::Local<v8::String> /* property */, const v8::AccessorInfo& info) {
        v8::HandleScope scope;

        auto cf = module->Get(v8::String::NewSymbol("Coordinates"));
        assert(cf->IsFunction());

        const osmium::Location& location = wrapped(info.This()).location();
        if (!location) {
            return scope.Close(v8::Local<v8::Function>::Cast(cf)->NewInstance());
        }

        v8::Local<v8::Value> lon = v8::Number::New(location.lon_without_check());
        v8::Local<v8::Value> lat = v8::Number::New(location.lat_without_check());
        v8::Local<v8::Value> argv[2] = { lon, lat };
        return scope.Close(v8::Local<v8::Function>::Cast(cf)->NewInstance(2, argv));
    }