JSValue JSC_HOST_CALL regExpProtoFuncCompile(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { if (!thisValue.isObject(&RegExpObject::info)) return throwError(exec, TypeError); RefPtr<RegExp> regExp; JSValue arg0 = args.at(0); JSValue arg1 = args.at(1); if (arg0.isObject(&RegExpObject::info)) { if (!arg1.isUndefined()) return throwError(exec, TypeError, "Cannot supply flags when constructing one RegExp from another."); regExp = asRegExpObject(arg0)->regExp(); } else { UString pattern = args.isEmpty() ? UString("") : arg0.toString(exec); UString flags = arg1.isUndefined() ? UString("") : arg1.toString(exec); regExp = RegExp::create(&exec->globalData(), pattern, flags); } if (!regExp->isValid()) return throwError(exec, SyntaxError, UString("Invalid regular expression: ").append(regExp->errorMessage())); asRegExpObject(thisValue)->setRegExp(regExp.release()); asRegExpObject(thisValue)->setLastIndex(0); return jsUndefined(); }
// Shared implementation used by test and exec. bool RegExpObject::match(ExecState* exec, const ArgList& args) { RegExpConstructor* regExpConstructor = exec->lexicalGlobalObject()->regExpConstructor(); UString input = args.isEmpty() ? regExpConstructor->input() : args.at(0).toString(exec); if (input.isNull()) { throwError(exec, GeneralError, "No input to " + toString(exec) + "."); return false; } if (!regExp()->global()) { int position; int length; regExpConstructor->performMatch(d->regExp.get(), input, 0, position, length); return position >= 0; } if (d->lastIndex < 0 || d->lastIndex > input.size()) { d->lastIndex = 0; return false; } int position; int length = 0; regExpConstructor->performMatch(d->regExp.get(), input, static_cast<int>(d->lastIndex), position, length); if (position < 0) { d->lastIndex = 0; return false; } d->lastIndex = position + length; return true; }
static JSValue setNewValueFromTimeArgs(ExecState* exec, JSValue thisValue, const ArgList& args, int numArgsToUse, bool inputIsUTC) { if (!thisValue.isObject(&DateInstance::info)) return throwError(exec, TypeError); DateInstance* thisDateObj = asDateInstance(thisValue); double milli = thisDateObj->internalNumber(); if (args.isEmpty() || isnan(milli)) { JSValue result = jsNaN(exec); thisDateObj->setInternalValue(result); return result; } double secs = floor(milli / msPerSecond); double ms = milli - secs * msPerSecond; GregorianDateTime t; thisDateObj->msToGregorianDateTime(milli, inputIsUTC, t); if (!fillStructuresUsingTimeArgs(exec, args, numArgsToUse, &ms, &t)) { JSValue result = jsNaN(exec); thisDateObj->setInternalValue(result); return result; } JSValue result = jsNumber(exec, gregorianDateTimeToMS(t, ms, inputIsUTC)); thisDateObj->setInternalValue(result); return result; }
JSValue JSXMLHttpRequest::send(ExecState* exec, const ArgList& args) { ExceptionCode ec = 0; if (args.isEmpty()) impl()->send(ec); else { JSValue val = args.at(0); if (val.isUndefinedOrNull()) impl()->send(ec); else if (val.inherits(&JSDocument::s_info)) impl()->send(toDocument(val), ec); else if (val.inherits(&JSBlob::s_info)) impl()->send(toBlob(val), ec); else impl()->send(val.toString(exec), ec); } int signedLineNumber; intptr_t sourceID; UString sourceURL; JSValue function; exec->interpreter()->retrieveLastCaller(exec, signedLineNumber, sourceID, sourceURL, function); impl()->setLastSendLineNumber(signedLineNumber >= 0 ? signedLineNumber : 0); impl()->setLastSendURL(sourceURL); setDOMException(exec, ec); return jsUndefined(); }
void Console::dirxml(ExecState* exec, const ArgList& args) { if (args.isEmpty()) return; Page* page = this->page(); if (!page) return; page->inspectorController()->addMessageToConsole(JSMessageSource, NodeMessageLevel, exec, args, 0, String()); }
JSValue* stringProtoFuncMatch(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) { UString s = thisValue->toThisString(exec); JSValue* a0 = args.at(exec, 0); UString u = s; RefPtr<RegExp> reg; RegExpObject* imp = 0; if (a0->isObject() && static_cast<JSObject *>(a0)->inherits(&RegExpObject::info)) reg = static_cast<RegExpObject *>(a0)->regExp(); else { /* * ECMA 15.5.4.12 String.prototype.search (regexp) * If regexp is not an object whose [[Class]] property is "RegExp", it is * replaced with the result of the expression new RegExp(regexp). */ reg = RegExp::create(exec, a0->toString(exec)); } RegExpConstructor* regExpObj = exec->lexicalGlobalObject()->regExpConstructor(); int pos; int matchLength; regExpObj->performMatch(reg.get(), u, 0, pos, matchLength); if (!(reg->global())) { // case without 'g' flag is handled like RegExp.prototype.exec if (pos < 0) return jsNull(); return regExpObj->arrayOfMatches(exec); } // return array of matches ArgList list; int lastIndex = 0; while (pos >= 0) { list.append(jsSubstring(exec, u, pos, matchLength)); lastIndex = pos; pos += matchLength == 0 ? 1 : matchLength; regExpObj->performMatch(reg.get(), u, pos, pos, matchLength); } if (imp) imp->setLastIndex(lastIndex); if (list.isEmpty()) { // if there are no matches at all, it's important to return // Null instead of an empty array, because this matches // other browsers and because Null is a false value. return jsNull(); } return constructArray(exec, list); }
void Console::warn(ExecState* exec, const ArgList& args) { if (args.isEmpty()) return; Page* page = this->page(); if (!page) return; String message = args.at(exec, 0)->toString(exec); KURL url; unsigned lineNumber; retrieveLastCaller(exec, url, lineNumber); page->chrome()->client()->addMessageToConsole(message, lineNumber, url.prettyURL()); page->inspectorController()->addMessageToConsole(JSMessageSource, WarningMessageLevel, exec, args, lineNumber, url.string()); printToStandardOut(WarningMessageLevel, exec, args, url); }
JSValue JSC_HOST_CALL dateProtoFuncSetYear(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { if (!thisValue.isObject(&DateInstance::info)) return throwError(exec, TypeError); const bool utc = false; DateInstance* thisDateObj = asDateInstance(thisValue); if (args.isEmpty()) { JSValue result = jsNaN(exec); thisDateObj->setInternalValue(result); return result; } double milli = thisDateObj->internalNumber(); double ms = 0; GregorianDateTime t; if (isnan(milli)) // Based on ECMA 262 B.2.5 (setYear) // the time must be reset to +0 if it is NaN. thisDateObj->msToGregorianDateTime(0, true, t); else { double secs = floor(milli / msPerSecond); ms = milli - secs * msPerSecond; thisDateObj->msToGregorianDateTime(milli, utc, t); } bool ok = true; int32_t year = args.at(0).toInt32(exec, ok); if (!ok) { JSValue result = jsNaN(exec); thisDateObj->setInternalValue(result); return result; } t.year = (year > 99 || year < 0) ? year - 1900 : year; JSValue result = jsNumber(exec, gregorianDateTimeToMS(t, ms, utc)); thisDateObj->setInternalValue(result); return result; }
static JSValue setNewValueFromDateArgs(ExecState* exec, JSValue thisValue, const ArgList& args, int numArgsToUse, bool inputIsUTC) { if (!thisValue.isObject(&DateInstance::info)) return throwError(exec, TypeError); DateInstance* thisDateObj = asDateInstance(thisValue); if (args.isEmpty()) { JSValue result = jsNaN(exec); thisDateObj->setInternalValue(result); return result; } double milli = thisDateObj->internalNumber(); double ms = 0; GregorianDateTime t; if (numArgsToUse == 3 && isnan(milli)) // Based on ECMA 262 15.9.5.40 - .41 (set[UTC]FullYear) // the time must be reset to +0 if it is NaN. thisDateObj->msToGregorianDateTime(0, true, t); else { double secs = floor(milli / msPerSecond); ms = milli - secs * msPerSecond; thisDateObj->msToGregorianDateTime(milli, inputIsUTC, t); } if (!fillStructuresUsingDateArgs(exec, args, numArgsToUse, &ms, &t)) { JSValue result = jsNaN(exec); thisDateObj->setInternalValue(result); return result; } JSValue result = jsNumber(exec, gregorianDateTimeToMS(t, ms, inputIsUTC)); thisDateObj->setInternalValue(result); return result; }
bool RegExpObject::match(ExecState* exec, const ArgList& args) { RegExpConstructor* regExpObj = exec->lexicalGlobalObject()->regExpConstructor(); UString input; if (!args.isEmpty()) input = args.at(exec, 0)->toString(exec); else { input = regExpObj->input(); if (input.isNull()) { throwError(exec, GeneralError, "No input."); return false; } } bool global = get(exec, exec->propertyNames().global)->toBoolean(exec); int lastIndex = 0; if (global) { if (d->lastIndex < 0 || d->lastIndex > input.size()) { d->lastIndex = 0; return false; } lastIndex = static_cast<int>(d->lastIndex); } int foundIndex; int foundLength; regExpObj->performMatch(d->regExp.get(), input, lastIndex, foundIndex, foundLength); if (global) { lastIndex = foundIndex < 0 ? 0 : foundIndex + foundLength; d->lastIndex = lastIndex; } return foundIndex >= 0; }
// ECMA 15.7.2 static JSValue JSC_HOST_CALL callNumberConstructor(ExecState* exec, JSObject*, JSValue, const ArgList& args) { return jsNumber(exec, args.isEmpty() ? 0 : args.at(0).toNumber(exec)); }
// ECMA 15.7.2 static JSValuePtr callNumberConstructor(ExecState* exec, JSObject*, JSValuePtr, const ArgList& args) { return jsNumber(exec, args.isEmpty() ? 0 : args.at(exec, 0).toNumber(exec)); }
JSValue JSSQLTransaction::executeSql(ExecState* exec, const ArgList& args) { if (args.isEmpty()) { setDOMException(exec, SYNTAX_ERR); return jsUndefined(); } String sqlStatement = args.at(0).toString(exec); if (exec->hadException()) return jsUndefined(); // Now assemble the list of SQL arguments Vector<SQLValue> sqlValues; if (!args.at(1).isUndefinedOrNull()) { JSObject* object = args.at(1).getObject(); if (!object) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } JSValue lengthValue = object->get(exec, exec->propertyNames().length); if (exec->hadException()) return jsUndefined(); unsigned length = lengthValue.toUInt32(exec); if (exec->hadException()) return jsUndefined(); for (unsigned i = 0 ; i < length; ++i) { JSValue value = object->get(exec, i); if (exec->hadException()) return jsUndefined(); if (value.isNull()) sqlValues.append(SQLValue()); else if (value.isNumber()) sqlValues.append(value.uncheckedGetNumber()); else { // Convert the argument to a string and append it sqlValues.append(value.toString(exec)); if (exec->hadException()) return jsUndefined(); } } } RefPtr<SQLStatementCallback> callback; if (!args.at(2).isUndefinedOrNull()) { JSObject* object = args.at(2).getObject(); if (!object) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } callback = JSCustomSQLStatementCallback::create(object, static_cast<JSDOMGlobalObject*>(exec->dynamicGlobalObject())); } RefPtr<SQLStatementErrorCallback> errorCallback; if (!args.at(3).isUndefinedOrNull()) { JSObject* object = args.at(3).getObject(); if (!object) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } errorCallback = JSCustomSQLStatementErrorCallback::create(object, static_cast<JSDOMGlobalObject*>(exec->dynamicGlobalObject())); } ExceptionCode ec = 0; m_impl->executeSQL(sqlStatement, sqlValues, callback.release(), errorCallback.release(), ec); setDOMException(exec, ec); return jsUndefined(); }
// ECMA 15.5.1 static JSValue JSC_HOST_CALL callStringConstructor(ExecState* exec, JSObject*, JSValue, const ArgList& args) { if (args.isEmpty()) return jsEmptyString(exec); return jsString(exec, args.at(0).toString(exec)); }