Example #1
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);
}
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();
}