v8::Handle<v8::Value> V8Clipboard::clearDataCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.Clipboard.clearData()");
    Clipboard* clipboard = V8Clipboard::toNative(args.Holder());

    if (!args.Length()) {
        clipboard->clearAllData();
        return v8::Undefined();
    }

    if (args.Length() != 1)
        return throwError("clearData: Invalid number of arguments", V8Proxy::SyntaxError);

    String type = toWebCoreString(args[0]);
    clipboard->clearData(type);
    return v8::Undefined();
}
void V8Clipboard::clearDataMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
{
    Clipboard* clipboard = V8Clipboard::toNative(args.Holder());

    if (!args.Length()) {
        clipboard->clearAllData();
        return;
    }

    if (args.Length() != 1) {
        throwError(v8SyntaxError, "clearData: Invalid number of arguments", args.GetIsolate());
        return;
    }

    String type = toWebCoreString(args[0]);
    clipboard->clearData(type);
}
JSValue JSClipboard::clearData(ExecState* exec)
{
    Clipboard* clipboard = impl();

    if (!exec->argumentCount()) {
        clipboard->clearAllData();
        return jsUndefined();
    }

    if (exec->argumentCount() == 1) {
        clipboard->clearData(ustringToString(exec->argument(0).toString(exec)->value(exec)));
        return jsUndefined();
    }

    // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments. 
    return throwError(exec, createSyntaxError(exec, "clearData: Invalid number of arguments"));
}
JSValuePtr JSClipboard::clearData(ExecState* exec, const ArgList& args)
{
    Clipboard* clipboard = impl();

    if (args.size() == 0) {
        clipboard->clearAllData();
        return jsUndefined();
    }

    if (args.size() == 1) {
        clipboard->clearData(args.at(exec, 0).toString(exec));
        return jsUndefined();
    }

    // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments. 
    return throwError(exec, SyntaxError, "clearData: Invalid number of arguments");
}
void V8Clipboard::clearDataMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
{
    Clipboard* clipboard = V8Clipboard::toNative(args.Holder());

    if (!args.Length()) {
        clipboard->clearAllData();
        return;
    }

    if (args.Length() != 1) {
        throwError(v8SyntaxError, "clearData: Invalid number of arguments", args.GetIsolate());
        return;
    }

    V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, type, args[0]);
    clipboard->clearData(type);
}
Beispiel #6
0
JSValue* JSClipboardPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
{
    if (!thisObj->inherits(&JSClipboard::info))
        return throwError(exec, TypeError);

    Clipboard* clipboard = static_cast<JSClipboard*>(thisObj)->impl();
    switch (id) {
        case JSClipboard::ClearData:
            if (args.size() == 0) {
                clipboard->clearAllData();
                return jsUndefined();
            } else if (args.size() == 1) {
                clipboard->clearData(args[0]->toString(exec));
                return jsUndefined();
            } else
                return throwError(exec, SyntaxError, "clearData: Invalid number of arguments");
        case JSClipboard::GetData:
        {
            if (args.size() == 1) {
                bool success;
                String result = clipboard->getData(args[0]->toString(exec), success);
                if (success)
                    return jsString(result);
                return jsUndefined();
            } else
                return throwError(exec, SyntaxError, "getData: Invalid number of arguments");
        }
        case JSClipboard::SetData:
            if (args.size() == 2)
                return jsBoolean(clipboard->setData(args[0]->toString(exec), args[1]->toString(exec)));
            return throwError(exec, SyntaxError, "setData: Invalid number of arguments");
        case JSClipboard::SetDragImage:
        {
            if (!clipboard->isForDragging())
                return jsUndefined();

            if (args.size() != 3)
                return throwError(exec, SyntaxError, "setDragImage: Invalid number of arguments");

            int x = args[1]->toInt32(exec);
            int y = args[2]->toInt32(exec);

            // See if they passed us a node
            Node* node = toNode(args[0]);
            if (!node)
                return throwError(exec, TypeError);

            if (!node->isElementNode())
                return throwError(exec, SyntaxError, "setDragImageFromElement: Invalid first argument");

            if (static_cast<Element*>(node)->hasLocalName(imgTag) &&
                !node->inDocument())
                clipboard->setDragImage(static_cast<HTMLImageElement*>(node)->cachedImage(), IntPoint(x, y));
            else
                clipboard->setDragImageElement(node, IntPoint(x, y));

            return jsUndefined();
        }
    }
    return jsUndefined();
}