unsigned Signature::hash() const { uint32_t sizeToHash = allocatedSize(argumentCount()) / sizeof(allocationSizeRoundsUpTo); // Assumes over-allocated memory was zero-initialized, and rounded-up to allocationSizeRoundsUpTo so that a wider hash can be performed. ASSERT(sizeToHash * sizeof(allocationSizeRoundsUpTo) == allocatedSize(argumentCount())); unsigned accumulator = 0xa1bcedd8u; const auto* pos = reinterpret_cast<const allocationSizeRoundsUpTo*>(this); for (uint32_t i = 0; i < sizeToHash; ++i) accumulator = WTF::pairIntHash(accumulator, WTF::IntHash<allocationSizeRoundsUpTo>::hash(*pos)); return accumulator; }
bool ArgList_TokenData::compare(const TokenData *other) const { const ArgList_TokenData *o = static_cast<const ArgList_TokenData *>(other); if (argumentCount() != o->argumentCount()) return false; foreach (int i, bRangeD(0, argumentCount() - 1)) { if (!argument(i)->compare(o->argument(i))) return false; } return true; }
void SemanticAnalysisVisitor::visit(ast::FunctionCall& functionCall) { functionCall.visitOperand(*this); functionCall.visitArguments(*this); // FIXME: try/catch for undefined functions auto functionSymbol = symbolTable.findFunction(functionCall.operandSymbol()->getName()); functionCall.setSymbol(functionSymbol); auto& arguments = functionCall.getArgumentList(); if (arguments.size() == functionSymbol.argumentCount()) { auto& declaredArguments = functionSymbol.arguments(); for (std::size_t i { 0 }; i < arguments.size(); ++i) { const auto& declaredArgument = declaredArguments.at(i); const auto& actualArgument = arguments.at(i)->getResultSymbol(); typeCheck(actualArgument->getType(), *declaredArgument, functionCall.getContext()); } auto& returnType = functionSymbol.returnType(); if (!returnType.isVoid()) { functionCall.setResultSymbol(symbolTable.createTemporarySymbol(std::unique_ptr<ast::FundamentalType> { returnType.clone() })); } } else { semanticError("no match for function " + functionSymbol.getType().toString(), functionCall.getContext()); } }
ArgumentDesc *ActionDesc::argumentAt(NPT_Ordinal index) const { if (index < argumentCount()) { return *m_private->m_argumentList.GetItem(index); } return NULL; }
Value FunSubstring::evaluate() const { String s = argument(0).evaluate().toString(); double doublePos = argument(1).evaluate().toNumber(); if (std::isnan(doublePos)) return emptyString(); long pos = static_cast<long>(FunRound::round(doublePos)); bool haveLength = argumentCount() == 3; long len = -1; if (haveLength) { double doubleLen = argument(2).evaluate().toNumber(); if (std::isnan(doubleLen)) return emptyString(); len = static_cast<long>(FunRound::round(doubleLen)); } if (pos > long(s.length())) return emptyString(); if (pos < 1) { if (haveLength) { len -= 1 - pos; if (len < 1) return emptyString(); } pos = 1; } return s.substring(pos - 1, len); }
String ScriptCallContext::argumentStringAt(unsigned index, bool checkForNullOrUndefined) { if (index >= argumentCount()) return String(); return ToWebCoreString(m_args[index]); }
/*! Returns the function argument at the given \a index. If \a index >= argumentCount(), a QScriptValue of the primitive type Undefined is returned. \sa argumentCount() */ QScriptValue QScriptContext::argument(int index) const { if (index < 0) return QScriptValue(); if (index >= argumentCount()) return QScriptValue(QScriptValue::UndefinedValue); QScriptValue v = argumentsObject().property(index); return v; }
Value FunNormalizeSpace::evaluate() const { if (!argumentCount()) { String s = Value(Expression::evaluationContext().node.get()).toString(); return s.simplifyWhiteSpace(); } String s = argument(0).evaluate().toString(); return s.simplifyWhiteSpace(); }
bool ScriptArguments::getFirstArgumentAsString(String& result) const { if (!argumentCount()) return false; const ScriptValue& value = argumentAt(0); ScriptState::Scope scope(m_scriptState.get()); result = V8ValueStringBuilder::toString(value.v8Value(), value.isolate()); return true; }
String Signature::toString() const { String result(makeString(returnType())); result.append(" ("); for (SignatureArgCount arg = 0; arg < argumentCount(); ++arg) { if (arg) result.append(", "); result.append(makeString(argument(arg))); } result.append(')'); return result; }
Value FunConcat::evaluate() const { StringBuilder result; result.reserveCapacity(1024); for (unsigned i = 0, count = argumentCount(); i < count; ++i) { String str(argument(i).evaluate().toString()); result.append(str); } return result.toString(); }
bool ScriptArguments::getFirstArgumentAsString(String& result) { if (!argumentCount()) return false; if (!globalState()) { ASSERT_NOT_REACHED(); return false; } result = argumentAt(0).toString(globalState()); return true; }
Value FunNamespaceURI::evaluate() const { if (argumentCount() > 0) { Value a = argument(0).evaluate(); if (!a.isNodeSet()) return emptyString(); Node* node = a.toNodeSet().firstNode(); return node ? node->namespaceURI().string() : emptyString(); } return evaluationContext().node->namespaceURI().string(); }
Value FunName::evaluate() const { if (argumentCount() > 0) { Value a = argument(0).evaluate(); if (!a.isNodeSet()) return emptyString(); Node* node = a.toNodeSet().firstNode(); return node ? expandedName(node) : emptyString(); } return expandedName(evaluationContext().node.get()); }
/*! \since 4.4 Returns a string representation of this context. This is useful for debugging. \sa backtrace() */ QString QScriptContext::toString() const { QScriptContextInfo info(this); QString result; QString functionName = info.functionName(); if (functionName.isEmpty()) { if (parentContext()) { const JSC::CallFrame *frame = QScriptEnginePrivate::frameForContext(this); if (info.functionType() == QScriptContextInfo::ScriptFunction) result.append(QLatin1String("<anonymous>")); else if(frame->callerFrame()->hasHostCallFrameFlag()) result.append(QLatin1String("<eval>")); else result.append(QLatin1String("<native>")); } else { result.append(QLatin1String("<global>")); } } else { result.append(functionName); } QStringList parameterNames = info.functionParameterNames(); result.append(QLatin1Char('(')); for (int i = 0; i < argumentCount(); ++i) { if (i > 0) result.append(QLatin1String(", ")); if (i < parameterNames.count()) { result.append(parameterNames.at(i)); result.append(QLatin1String(" = ")); } QScriptValue arg = argument(i); if (arg.isString()) result.append(QLatin1Char('\'')); result.append(arg.toString()); if (arg.isString()) result.append(QLatin1Char('\'')); } result.append(QLatin1Char(')')); QString fileName = info.fileName(); int lineNumber = info.lineNumber(); result.append(QLatin1String(" at ")); if (!fileName.isEmpty()) { result.append(fileName); result.append(QLatin1Char(':')); } result.append(QString::number(lineNumber)); return result; }
bool ScriptArguments::getFirstArgumentAsString(String& result, bool checkForNullOrUndefined) { if (!argumentCount()) return false; const ScriptValue& value = argumentAt(0); ScriptState::Scope scope(m_scriptState.get()); if (checkForNullOrUndefined && (value.isNull() || value.isUndefined())) return false; // We intentionally ignore an exception that can be thrown in ToString(). v8::TryCatch block; v8::Handle<v8::String> string = value.v8Value()->ToString(); result = string.IsEmpty() ? String() : toCoreString(string); return true; }
bool ScriptArguments::getFirstArgumentAsString(String& result, bool checkForNullOrUndefined) { if (!argumentCount()) return false; const ScriptValue& value = argumentAt(0); if (checkForNullOrUndefined && (value.isNull() || value.isUndefined())) return false; if (!globalState()) { ASSERT_NOT_REACHED(); return false; } result = value.toString(globalState()); return true; }
/*! \since 4.4 Returns a string representation of this context. This is useful for debugging. \sa backtrace() */ QString QScriptContext::toString() const { QScriptContextInfo info(this); QString result; QString functionName = info.functionName(); if (functionName.isEmpty()) { if (parentContext()) { if (info.functionType() == QScriptContextInfo::ScriptFunction) result.append(QLatin1String("<anonymous>")); else result.append(QLatin1String("<native>")); } else { result.append(QLatin1String("<global>")); } } else { result.append(functionName); } QStringList parameterNames = info.functionParameterNames(); result.append(QLatin1String(" (")); for (int i = 0; i < argumentCount(); ++i) { if (i > 0) result.append(QLatin1String(", ")); if (i < parameterNames.count()) { result.append(parameterNames.at(i)); result.append(QLatin1Char('=')); } QScriptValue arg = argument(i); result.append(safeValueToString(arg)); } result.append(QLatin1String(")")); QString fileName = info.fileName(); int lineNumber = info.lineNumber(); result.append(QLatin1String(" at ")); if (!fileName.isEmpty()) { result.append(fileName); result.append(QLatin1Char(':')); } result.append(QString::number(lineNumber)); return result; }
void CallFrame::dump(PrintStream& out) { if (CodeBlock* codeBlock = this->codeBlock()) { out.print(codeBlock->inferredName(), "#", codeBlock->hashAsStringIfPossible(), " [", codeBlock->jitType(), "]"); out.print("("); thisValue().dumpForBacktrace(out); for (size_t i = 0; i < argumentCount(); ++i) { out.print(", "); JSValue value = argument(i); value.dumpForBacktrace(out); } out.print(")"); return; } out.print(returnPC()); }
Value FunNumber::evaluate() const { if (!argumentCount()) return Value(Expression::evaluationContext().node.get()).toNumber(); return argument(0).evaluate().toNumber(); }
Value FunStringLength::evaluate() const { if (!argumentCount()) return Value(Expression::evaluationContext().node.get()).toString().length(); return argument(0).evaluate().toString().length(); }
NPT_Cardinal ActionDesc::outputArgumentCount() const { return argumentCount() - m_private->m_inputArgumentCount; }