Example #1
0
void V8Geolocation::watchPositionMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    bool succeeded = false;

    ExceptionState exceptionState(ExceptionState::ExecutionContext, "watchCurrentPosition", "Geolocation", info.Holder(), info.GetIsolate());

    OwnPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<V8PositionCallback>(info[0], 1, succeeded, info.GetIsolate(), exceptionState);
    if (!succeeded)
        return;
    ASSERT(positionCallback);

    // Argument is optional (hence undefined is allowed), and null is allowed.
    OwnPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCallback<V8PositionErrorCallback>(info[1], 2, succeeded, info.GetIsolate(), exceptionState, CallbackAllowUndefined | CallbackAllowNull);
    if (!succeeded)
        return;

    RefPtrWillBeRawPtr<PositionOptions> positionOptions = createPositionOptions(info[2], info.GetIsolate(), succeeded);
    if (!succeeded)
        return;
    ASSERT(positionOptions);

    Geolocation* geolocation = V8Geolocation::toNative(info.Holder());
    int watchId = geolocation->watchPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.release());
    v8SetReturnValue(info, watchId);
}
Example #2
0
JSValue JSGeolocation::watchPosition(ExecState* exec)
{
    // Arguments: PositionCallback, (optional)PositionErrorCallback, (optional)PositionOptions

    RefPtr<PositionCallback> positionCallback = createFunctionOnlyCallback<JSPositionCallback>(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(0));
    if (exec->hadException())
        return jsUndefined();
    ASSERT(positionCallback);

    RefPtr<PositionErrorCallback> positionErrorCallback = createFunctionOnlyCallback<JSPositionErrorCallback>(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), exec->argument(1), CallbackAllowUndefined | CallbackAllowNull);
    if (exec->hadException())
        return jsUndefined();

    RefPtr<PositionOptions> positionOptions = createPositionOptions(exec, exec->argument(2));
    if (exec->hadException())
        return jsUndefined();
    ASSERT(positionOptions);

    int watchID = m_impl->watchPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.release());
    return jsNumber(watchID);
}
Example #3
0
JSValue JSGeolocation::watchPosition(ExecState* exec, const ArgList& args)
{
    // Arguments: PositionCallback, (optional)PositionErrorCallback, (optional)PositionOptions

    RefPtr<PositionCallback> positionCallback = createPositionCallback(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), args.at(0));
    if (exec->hadException())
        return jsUndefined();
    ASSERT(positionCallback);

    RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(exec, static_cast<JSDOMGlobalObject*>(exec->lexicalGlobalObject()), args.at(1));
    if (exec->hadException())
        return jsUndefined();

    RefPtr<PositionOptions> positionOptions = createPositionOptions(exec, args.at(2));
    if (exec->hadException())
        return jsUndefined();
    ASSERT(positionOptions);

    int watchID = m_impl->watchPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.release());
    return jsNumber(exec, watchID);
}
JSValue JSGeolocation::getCurrentPosition(ExecState& state)
{
    // Arguments: PositionCallback, (optional)PositionErrorCallback, (optional)PositionOptions

    auto positionCallback = createFunctionOnlyCallback<JSPositionCallback>(&state, globalObject(), state.argument(0));
    if (state.hadException())
        return jsUndefined();
    ASSERT(positionCallback);

    auto positionErrorCallback = createFunctionOnlyCallback<JSPositionErrorCallback>(&state, globalObject(), state.argument(1), CallbackAllowUndefined | CallbackAllowNull);
    if (state.hadException())
        return jsUndefined();

    auto positionOptions = createPositionOptions(&state, state.argument(2));
    if (state.hadException())
        return jsUndefined();
    ASSERT(positionOptions);

    wrapped().getCurrentPosition(WTFMove(positionCallback), WTFMove(positionErrorCallback), WTFMove(positionOptions));
    return jsUndefined();
}
JSValue* JSGeolocation::getCurrentPosition(ExecState* exec, const ArgList& args)
{
    // Arguments: PositionCallback, (optional)PositionErrorCallback, (optional)PositionOptions
    RefPtr<PositionCallback> positionCallback;
    JSObject* object = args.at(exec, 0)->getObject();
    if (exec->hadException())
        return jsUndefined();
    if (!object) {
        setDOMException(exec, TYPE_MISMATCH_ERR);
        return jsUndefined();
    }

    if (Frame* frame = toJSDOMWindow(exec->lexicalGlobalObject())->impl()->frame())
        positionCallback = JSCustomPositionCallback::create(object, frame);

    RefPtr<PositionErrorCallback> positionErrorCallback;
    if (!args.at(exec, 1)->isUndefinedOrNull()) {
        JSObject* object = args.at(exec, 1)->getObject();
        if (!object) {
            setDOMException(exec, TYPE_MISMATCH_ERR);
            return jsUndefined();
        }

        if (Frame* frame = toJSDOMWindow(exec->lexicalGlobalObject())->impl()->frame())
            positionErrorCallback = JSCustomPositionErrorCallback::create(object, frame);
    }

    RefPtr<PositionOptions> positionOptions;
    if (!args.at(exec, 2)->isUndefinedOrNull()) {
        positionOptions = createPositionOptions(exec, args.at(exec, 2));
        if (exec->hadException())
            return jsUndefined();
    }

    m_impl->getCurrentPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.get());

    return jsUndefined();
}
v8::Handle<v8::Value> V8Geolocation::watchPositionCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.Geolocation.watchPosition()");

    bool succeeded = false;

    RefPtr<PositionCallback> positionCallback = createPositionCallback(args[0], succeeded);
    if (!succeeded)
        return v8::Undefined();
    ASSERT(positionCallback);

    RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(args[1], succeeded);
    if (!succeeded)
        return v8::Undefined();

    RefPtr<PositionOptions> positionOptions = createPositionOptions(args[2], succeeded);
    if (!succeeded)
        return v8::Undefined();
    ASSERT(positionOptions);

    Geolocation* geolocation = V8DOMWrapper::convertToNativeObject<Geolocation>(V8ClassIndex::GEOLOCATION, args.Holder());
    int watchId = geolocation->watchPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.release());
    return v8::Number::New(watchId);
}
v8::Handle<v8::Value> V8Geolocation::getCurrentPositionCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.Geolocation.getCurrentPosition()");

    bool succeeded = false;

    RefPtr<PositionCallback> positionCallback = createPositionCallback(args[0], succeeded);
    if (!succeeded)
        return v8::Undefined();
    ASSERT(positionCallback);

    RefPtr<PositionErrorCallback> positionErrorCallback = createPositionErrorCallback(args[1], succeeded);
    if (!succeeded)
        return v8::Undefined();

    RefPtr<PositionOptions> positionOptions = createPositionOptions(args[2], succeeded);
    if (!succeeded)
        return v8::Undefined();
    ASSERT(positionOptions);

    Geolocation* geolocation = V8Geolocation::toNative(args.Holder());
    geolocation->getCurrentPosition(positionCallback.release(), positionErrorCallback.release(), positionOptions.release());
    return v8::Undefined();
}