Beispiel #1
0
JSValue JSC_HOST_CALL functionClearSamplingFlags(ExecState* exec, JSObject*, JSValue, const ArgList& args)
{
    for (unsigned i = 0; i < args.size(); ++i) {
        unsigned flag = static_cast<unsigned>(args.at(i).toNumber(exec));
        if ((flag >= 1) && (flag <= 32))
            SamplingFlags::clearFlag(flag);
    }
    return jsNull();
}
JSValue JSXMLHttpRequest::setRequestHeader(ExecState* exec, const ArgList& args)
{
    if (args.size() < 2)
        return throwError(exec, SyntaxError, "Not enough arguments");

    ExceptionCode ec = 0;
    impl()->setRequestHeader(args.at(0).toString(exec), args.at(1).toString(exec), ec);
    setDOMException(exec, ec);
    return jsUndefined();
}
JSValue JSXMLHttpRequest::getResponseHeader(ExecState* exec, const ArgList& args)
{
    if (args.size() < 1)
        return throwError(exec, SyntaxError, "Not enough arguments");

    ExceptionCode ec = 0;
    JSValue header = jsStringOrNull(exec, impl()->getResponseHeader(args.at(0).toString(exec), ec));
    setDOMException(exec, ec);
    return header;
}
JSValue JSInjectedScriptHost::selectDatabase(ExecState*, const ArgList& args)
{
    if (args.size() < 1)
        return jsUndefined();

    Database* database = toDatabase(args.at(0));
    if (database)
        impl()->selectDatabase(database);
    return jsUndefined();
}
JSValuePtr JSClipboard::setData(ExecState* exec, const ArgList& args)
{
    Clipboard* clipboard = impl();

    // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments. 
    if (args.size() != 2)
        return throwError(exec, SyntaxError, "setData: Invalid number of arguments");

    return jsBoolean(clipboard->setData(args.at(exec, 0).toString(exec), args.at(exec, 1).toString(exec)));
}
void
CBCI2000Controller::execute( ArgList& ioArgs )
{
  std::string command = ioArgs.GetString( 1 );
  int exitCode = 0,
      result = mBCI2000.Execute( command, &exitCode );
  if( ioArgs.size() > 2 )
    ioArgs.SetInt( 1, exitCode );
  ioArgs.SetString( 2, com::DualString( mBCI2000.Result() ).ToWin() );
  ioArgs.SetInt( 0, result );
}
Beispiel #7
0
bool on_command( const ArgList& args )
{
   /* @source command? */
   if (!_stricmp( args[ 0 ].c_str( ), "source" ))
   {
      if (args.size( ) > 2)
         system_errspeak( "Error: Too many arguments for @source <file>" );
      else if (args.size( ) == 1)
         system_errspeak( "Expected a file to source." );
      else
         source( args[ 1 ] );

      return true;
   }
   /* @console command? */
   else if (!_stricmp( args[ 0 ].c_str( ), "console" ))
   {
      if (args.size( ) > 2)
         system_errspeak( "Error: Too many arguments for @console on|off" );
      else if (args.size( ) == 1)
         system_speak( "Expected either 'on' or 'off'." );
      else
      {
         if (args[ 1 ] == "on")
            toggle_console( true );
         else if (args[ 1 ] == "off")
            toggle_console( false );
         else
            system_errspeak( "Expected either 'on' or 'off'." );
      }

      return true;
   }
   /* @echo command? */
   else if (!_stricmp( args[ 0 ].c_str( ), "echo" ))
   {
      if (args.size( ) > 1)
      {
         string s = args[ 1 ];
         for (size_t i = 2; i < args.size( ); ++i)
         {
            s += " ";
            s += args[ i ];
         }

         system_speak( s );
      }

      return true;
   }
   /* @version command? */
   else if (!_stricmp( args[ 0 ].c_str( ), "version" ))
   {
      system_speak( "Furnarchy " F2VER_SZ );
      return true;
   }


   return false;
}
QString Interpreter::printProc(const ProcInfo *info, int level)
{
    ArgList list;
    QString print;
    QStringList sections;
    int i, j;

    print = QString(info->procName) + "(";
    if (getArgs(info, &list)<0)
        return "";
    for (i=0; i<(int)list.size(); i++)
    {
        if (i>0)
            print +=  ", ";
	j = i;
        print += printArgType(&info->argTypes[i], i) + " " + list[j].first;
    }
    print += ")\n";

    if (level>0)
    {
        sections = getSections("", info->procInfo);
        if (sections.size()>0)
            print += sections[0] + "\n";
        print += "Parameters:\n";
        if (list.size()==0)
            print += "<NONE>\n";
        for (i=0; i<(int)list.size(); i++)
        {
            print += "   " + list[i].first + ": ";
            print += list[i].second + "\n";
        }
        sections = getSections("@r", info->procInfo);
        print += "Returns:\n";
        for (i=0; i<sections.size(); i++)
            print += "   " + sections[i] + "\n";
    }

    return print;
}
// HTMLCollections are strange objects, they support both get and call,
// so that document.forms.item(0) and document.forms(0) both work.
static JSValue JSC_HOST_CALL callHTMLCollection(ExecState* exec, JSObject* function, JSValue, const ArgList& args)
{
    if (args.size() < 1)
        return jsUndefined();

    // Do not use thisObj here. It can be the JSHTMLDocument, in the document.forms(i) case.
    JSHTMLCollection* jsCollection = static_cast<JSHTMLCollection*>(function);
    HTMLCollection* collection = jsCollection->impl();

    // Also, do we need the TypeError test here ?

    if (args.size() == 1) {
        // Support for document.all(<index>) etc.
        bool ok;
        UString string = args.at(0).toString(exec);
        unsigned index = string.toUInt32(&ok, false);
        if (ok)
            return toJS(exec, jsCollection->globalObject(), collection->item(index));

        // Support for document.images('<name>') etc.
        return getNamedItems(exec, jsCollection, Identifier(exec, string));
    }

    // The second arg, if set, is the index of the item we want
    bool ok;
    UString string = args.at(0).toString(exec);
    unsigned index = args.at(1).toString(exec).toUInt32(&ok, false);
    if (ok) {
        String pstr = string;
        Node* node = collection->namedItem(pstr);
        while (node) {
            if (!index)
                return toJS(exec, jsCollection->globalObject(), node);
            node = collection->nextNamedItem(pstr);
            --index;
        }
    }

    return jsUndefined();
}
JSValue JSCanvasRenderingContext2D::strokeRect(ExecState* exec, const ArgList& args)
{ 
    CanvasRenderingContext2D* context = impl();
    
    if (args.size() <= 4)
        context->strokeRect(args.at(0).toFloat(exec), args.at(1).toFloat(exec),
                            args.at(2).toFloat(exec), args.at(3).toFloat(exec));
    else
        context->strokeRect(args.at(0).toFloat(exec), args.at(1).toFloat(exec),
                            args.at(2).toFloat(exec), args.at(3).toFloat(exec), args.at(4).toFloat(exec));

    return jsUndefined();    
}
Beispiel #11
0
JSValuePtr functionPrint(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args)
{
    for (unsigned i = 0; i < args.size(); ++i) {
        if (i != 0)
            putchar(' ');
        
        printf("%s", args.at(exec, i)->toString(exec).UTF8String().c_str());
    }
    
    putchar('\n');
    fflush(stdout);
    return jsUndefined();
}
JSValue JSInjectedScriptHost::pushNodePathToFrontend(ExecState* exec, const ArgList& args)
{
    if (args.size() < 3)
        return jsUndefined();

    Node* node = toNode(args.at(0));
    if (!node)
        return jsUndefined();

    bool withChildren = args.at(1).toBoolean(exec);
    bool selectInUI = args.at(2).toBoolean(exec);
    return jsNumber(exec, impl()->pushNodePathToFrontend(node, withChildren, selectInUI));
}
JSValue JSInjectedScriptHost::selectDOMStorage(ExecState*, const ArgList& args)
{
    if (args.size() < 1)
        return jsUndefined();
    InspectorController* ic = impl()->inspectorController();
    if (!ic)
        return jsUndefined();

    Storage* storage = toStorage(args.at(0));
    if (storage)
        impl()->selectDOMStorage(storage);
    return jsUndefined();
}
// Custom functions
JSValue JSWebSocket::send(ExecState* exec, const ArgList& args)
{
    if (args.size() < 1)
        return throwError(exec, SyntaxError, "Not enough arguments");

    const String& msg = args.at(0).toString(exec);
    if (exec->hadException())
        return throwError(exec, SyntaxError, "bad message data.");
    ExceptionCode ec = 0;
    JSValue ret = jsBoolean(impl()->send(msg, ec));
    setDOMException(exec, ec);
    return ret;
}
Beispiel #15
0
AJValue JSC_HOST_CALL functionPrint(ExecState* exec, AJObject*, AJValue, const ArgList& args)
{
    for (unsigned i = 0; i < args.size(); ++i) {
        if (i)
            putchar(' ');

        printf("%s", args.at(i).toString(exec).UTF8String().data());
    }

    putchar('\n');
    fflush(stdout);
    return jsUndefined();
}
JSValue JSDOMWindow::postMessage(ExecState* exec, const ArgList& args)
{
    DOMWindow* window = impl();

    DOMWindow* source = asJSDOMWindow(exec->lexicalGlobalObject())->impl();
    String message = args.at(0).toString(exec);

    if (exec->hadException())
        return jsUndefined();

    MessagePort* messagePort = (args.size() == 2) ? 0 : toMessagePort(args.at(1));

    String targetOrigin = valueToStringWithUndefinedOrNullCheck(exec, args.at((args.size() == 2) ? 1 : 2));
    if (exec->hadException())
        return jsUndefined();

    ExceptionCode ec = 0;
    window->postMessage(message, messagePort, targetOrigin, source, ec);
    setDOMException(exec, ec);

    return jsUndefined();
}
JSValuePtr JSDatabase::transaction(ExecState* exec, const ArgList& args)
{
    JSObject* object;
    
    if (!(object = args.at(exec, 0).getObject())) {
        setDOMException(exec, TYPE_MISMATCH_ERR);
        return jsUndefined();
    }        
 
    Frame* frame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame();
    if (!frame)
        return jsUndefined();
    
    RefPtr<SQLTransactionCallback> callback(JSCustomSQLTransactionCallback::create(object, frame));
    RefPtr<SQLTransactionErrorCallback> errorCallback;
    
    if (args.size() > 1 && !args.at(exec, 1).isNull()) {
        if (!(object = args.at(exec, 1).getObject())) {
            setDOMException(exec, TYPE_MISMATCH_ERR);
            return jsUndefined();
        }

        errorCallback = JSCustomSQLTransactionErrorCallback::create(object, frame);
    }

    RefPtr<VoidCallback> successCallback;
    if (args.size() > 2 && !args.at(exec, 2).isNull()) {
        successCallback = toVoidCallback(exec, args.at(exec, 2));
        if (!successCallback) {
            setDOMException(exec, TYPE_MISMATCH_ERR);
            return jsUndefined();
        }
    }
    
    m_impl->transaction(callback.release(), errorCallback.release(), successCallback.release());

    return jsUndefined();
}
Beispiel #18
0
	bool needsDispatch(const ArgList& evaluated_args) const
	{
	    if (!isInternalGeneric())
		return false;
	    switch(evaluated_args.size()) {
	    case 0:
		return false;
	    case 1:
		return needsDispatch(evaluated_args.get(0));
	    default:
		return needsDispatch(evaluated_args.get(0),
				     evaluated_args.get(1));
	    }
	}
JSValue JSInjectedScriptHost::databaseForId(ExecState* exec, const ArgList& args)
{
    if (args.size() < 1)
        return jsUndefined();

    InspectorController* ic = impl()->inspectorController();
    if (!ic)
        return jsUndefined();

    Database* database = impl()->databaseForId(args.at(0).toInt32(exec));
    if (!database)
        return jsUndefined();
    return toJS(exec, database);
}
static String writeHelper(ExecState* exec, const ArgList& args)
{
    // DOM only specifies single string argument, but NS & IE allow multiple
    // or no arguments.

    unsigned size = args.size();
    if (size == 1)
        return args.at(exec, 0)->toString(exec);

    Vector<UChar> result;
    for (unsigned i = 0; i < size; ++i)
        append(result, args.at(exec, i)->toString(exec));
    return String::adopt(result);
}
JSValuePtr JSClipboard::getData(ExecState* exec, const ArgList& args)
{
    // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments.
    if (args.size() != 1)
        return throwError(exec, SyntaxError, "getData: Invalid number of arguments");

    Clipboard* clipboard = impl();

    bool success;
    String result = clipboard->getData(args.at(exec, 0).toString(exec), success);
    if (!success)
        return jsUndefined();

    return jsString(exec, result);
}
Beispiel #22
0
JSValue JSC_HOST_CALL mathProtoFuncMin(ExecState* exec, JSObject*, JSValue, const ArgList& args)
{
    unsigned argsCount = args.size();
    double result = +Inf;
    for (unsigned k = 0; k < argsCount; ++k) {
        double val = args.at(k).toNumber(exec);
        if (isnan(val)) {
            result = NaN;
            break;
        }
        if (val < result || (val == 0 && result == 0 && signbit(val)))
            result = val;
    }
    return jsNumber(exec, result);
}
Beispiel #23
0
static void printToStandardOut(MessageLevel level, ExecState* exec, const ArgList& args, const KURL& url)
{
    if (!Console::shouldPrintExceptions())
        return;

    printSourceURLAndLine(url.prettyURL(), 0);
    printMessageSourceAndLevelPrefix(JSMessageSource, level);

    for (size_t i = 0; i < args.size(); ++i) {
        UString argAsString = args.at(exec, i)->toString(exec);
        printf(" %s", argAsString.UTF8String().c_str());
    }

    printf("\n");
}
JSValue JSClipboard::setData(ExecState* exec, const ArgList& args)
{
    // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments. 
    if (args.size() != 2)
        return throwError(exec, SyntaxError, "setData: Invalid number of arguments");
	
	Clipboard* const clipboard = impl();

    String const mimeType(ustringToString(args.at(0).toString(exec)));
    if (mimeType == ClipboardApolloHelper::BITMAP_TYPE) {
        Node* const node = toNode(args.at(1));
        return node ? jsBoolean(clipboard->setData(mimeType, node)) : jsBoolean(false);
    } else {
        return jsBoolean(clipboard->setData(mimeType, args.at(1)));
    }
}
Beispiel #25
0
void Console::count(ExecState* exec, const ArgList& args)
{
    Page* page = this->page();
    if (!page)
        return;

    KURL url;
    unsigned lineNumber;
    retrieveLastCaller(exec, url, lineNumber);

    UString title;
    if (args.size() >= 1)
        title = valueToStringWithUndefinedOrNullCheck(exec, args.at(exec, 0));

    page->inspectorController()->count(title, lineNumber, url.string());
}
JSValue JSInjectedScriptHost::nodeForId(ExecState* exec, const ArgList& args)
{
    if (args.size() < 1)
        return jsUndefined();

    Node* node = impl()->nodeForId(args.at(0).toInt32(exec));
    if (!node)
        return jsUndefined();

    InspectorController* ic = impl()->inspectorController();
    if (!ic)
        return jsUndefined();

    JSLock lock(SilenceAssertionsOnly);
    return toJS(exec, node);
}
Beispiel #27
0
// ECMA 10.1.8
Arguments::Arguments(ExecState* exec, JSFunction* func, const ArgList& args, JSActivation* act)
    : JSObject(exec->lexicalGlobalObject()->objectPrototype())
    , _activationObject(act)
    , indexToNameMap(func, args)
{
    putDirect(exec->propertyNames().callee, func, DontEnum);
    putDirect(exec, exec->propertyNames().length, args.size(), DontEnum);
  
    int i = 0;
    ArgList::const_iterator end = args.end();
    for (ArgList::const_iterator it = args.begin(); it != end; ++it, ++i) {
        Identifier name = Identifier::from(exec, i);
        if (!indexToNameMap.isMapped(name))
            putDirect(name, *it, DontEnum);
    }
}
JSValue JSInjectedScriptHost::reportDidDispatchOnInjectedScript(ExecState* exec, const ArgList& args)
{
    if (args.size() < 3)
        return jsUndefined();
    
    if (!args.at(0).isInt32())
        return jsUndefined();
    int callId = args.at(0).asInt32();
    
    RefPtr<SerializedScriptValue> result(SerializedScriptValue::create(exec, args.at(1)));
    
    bool isException;
    if (!args.at(2).getBoolean(isException))
        return jsUndefined();
    impl()->reportDidDispatchOnInjectedScript(callId, result.get(), isException);
    return jsUndefined();
}
Beispiel #29
0
// ECMA 10.1.8
Arguments::Arguments(ExecState* exec, JSFunction* function, const ArgList& args, JSActivation* activation)
    : JSObject(exec->lexicalGlobalObject()->objectPrototype())
    , d(new ArgumentsData(activation, function, args))
{
    ASSERT(activation);

    putDirect(exec->propertyNames().callee, function, DontEnum);
    putDirect(exec->propertyNames().length, jsNumber(exec, args.size()), DontEnum);
  
    int i = 0;
    ArgList::const_iterator end = args.end();
    for (ArgList::const_iterator it = args.begin(); it != end; ++it, ++i) {
        Identifier name = Identifier::from(exec, i);
        if (!d->indexToNameMap.isMapped(name))
            putDirect(name, (*it).jsValue(exec), DontEnum);
    }
}
JSValue JSCanvasRenderingContext2D::putImageData(ExecState* exec, const ArgList& args)
{
    // putImageData has two variants
    // putImageData(ImageData, x, y)
    // putImageData(ImageData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight)
    CanvasRenderingContext2D* context = impl();

    ExceptionCode ec = 0;
    if (args.size() >= 7)
        context->putImageData(toImageData(args.at(0)), args.at(1).toFloat(exec), args.at(2).toFloat(exec), 
                              args.at(3).toFloat(exec), args.at(4).toFloat(exec), args.at(5).toFloat(exec), args.at(6).toFloat(exec), ec);
    else
        context->putImageData(toImageData(args.at(0)), args.at(1).toFloat(exec), args.at(2).toFloat(exec), ec);

    setDOMException(exec, ec);
    return jsUndefined();
}