本文整理汇总了C++中createRangeError函数的典型用法代码示例。如果您正苦于以下问题:C++ createRangeError函数的具体用法?C++ createRangeError怎么用?C++ createRangeError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createRangeError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: numberProtoFuncToFixed
// toFixed converts a number to a string, always formatting as an a decimal fraction.
// This method takes an argument specifying a number of decimal places to round the
// significand to. However when converting large values (1e+21 and above) this
// method will instead fallback to calling ToString.
EncodedTiValue JSC_HOST_CALL numberProtoFuncToFixed(TiExcState* exec)
{
// Get x (the double value of this, which should be a Number).
TiValue thisValue = exec->hostThisValue();
TiValue v = thisValue.getJSNumber();
if (!v)
return throwVMTypeError(exec);
double x = v.uncheckedGetNumber();
// Get the argument.
int decimalPlaces;
bool isUndefined; // This is ignored; undefined treated as 0.
if (!getIntegerArgumentInRange(exec, 0, 20, decimalPlaces, isUndefined))
return throwVMError(exec, createRangeError(exec, "toFixed() argument must be between 0 and 20"));
// 15.7.4.5.7 states "If x >= 10^21, then let m = ToString(x)"
// This also covers Ininity, and structure the check so that NaN
// values are also handled by numberToString
if (!(fabs(x) < 1e+21))
return TiValue::encode(jsString(exec, UString::number(x)));
// The check above will return false for NaN or Infinity, these will be
// handled by numberToString.
ASSERT(!isnan(x) && !isinf(x));
// Convert to decimal with rounding, and format as decimal.
NumberToStringBuffer buffer;
unsigned length = DecimalNumber(x, RoundingDecimalPlaces, decimalPlaces).toStringDecimal(buffer, WTI::NumberToStringBufferLength);
return TiValue::encode(jsString(exec, UString(buffer, length)));
}
示例2: numberProtoFuncToExponential
// toExponential converts a number to a string, always formatting as an expoential.
// This method takes an optional argument specifying a number of *decimal places*
// to round the significand to (or, put another way, this method optionally rounds
// to argument-plus-one significant figures).
EncodedTiValue JSC_HOST_CALL numberProtoFuncToExponential(TiExcState* exec)
{
// Get x (the double value of this, which should be a Number).
double x;
if (!toThisNumber(exec->hostThisValue(), x))
return throwVMTypeError(exec);
// Get the argument.
int decimalPlacesInExponent;
bool isUndefined;
if (!getIntegerArgumentInRange(exec, 0, 20, decimalPlacesInExponent, isUndefined))
return throwVMError(exec, createRangeError(exec, "toExponential() argument must be between 0 and 20"));
// Handle NaN and Infinity.
if (isnan(x) || isinf(x))
return TiValue::encode(jsString(exec, UString::number(x)));
// Round if the argument is not undefined, always format as exponential.
NumberToStringBuffer buffer;
unsigned length = isUndefined
? DecimalNumber(x).toStringExponential(buffer, WTI::NumberToStringBufferLength)
: DecimalNumber(x, RoundingSignificantFigures, decimalPlacesInExponent + 1).toStringExponential(buffer, WTI::NumberToStringBufferLength);
return TiValue::encode(jsString(exec, UString(buffer, length)));
}
示例3: normalizeHighWaterMark
static inline double normalizeHighWaterMark(ExecState& exec, JSObject& strategy)
{
JSValue jsHighWaterMark = getPropertyFromObject(exec, strategy, "highWaterMark");
if (exec.hadException())
return 0;
if (jsHighWaterMark.isUndefined())
return 1;
double highWaterMark = jsHighWaterMark.toNumber(&exec);
if (exec.hadException())
return 0;
if (std::isnan(highWaterMark)) {
throwVMError(&exec, createTypeError(&exec, ASCIILiteral("Value is NaN")));
return 0;
}
if (highWaterMark < 0) {
throwVMError(&exec, createRangeError(&exec, ASCIILiteral("Not a positive value")));
return 0;
}
return highWaterMark;
}
示例4: dateProtoFuncToISOString
EncodedJSValue JSC_HOST_CALL dateProtoFuncToISOString(ExecState* exec)
{
JSValue thisValue = exec->thisValue();
if (!thisValue.inherits(DateInstance::info()))
return throwVMTypeError(exec);
DateInstance* thisDateObj = asDateInstance(thisValue);
if (!std::isfinite(thisDateObj->internalNumber()))
return throwVMError(exec, createRangeError(exec, ASCIILiteral("Invalid Date")));
const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(exec);
if (!gregorianDateTime)
return JSValue::encode(jsNontrivialString(exec, String(ASCIILiteral("Invalid Date"))));
// Maximum amount of space we need in buffer: 7 (max. digits in year) + 2 * 5 (2 characters each for month, day, hour, minute, second) + 4 (. + 3 digits for milliseconds)
// 6 for formatting and one for null termination = 28. We add one extra character to allow us to force null termination.
char buffer[28];
// If the year is outside the bounds of 0 and 9999 inclusive we want to use the extended year format (ES 15.9.1.15.1).
int ms = static_cast<int>(fmod(thisDateObj->internalNumber(), msPerSecond));
if (ms < 0)
ms += msPerSecond;
int charactersWritten;
if (gregorianDateTime->year() > 9999 || gregorianDateTime->year() < 0)
charactersWritten = snprintf(buffer, sizeof(buffer), "%+07d-%02d-%02dT%02d:%02d:%02d.%03dZ", gregorianDateTime->year(), gregorianDateTime->month() + 1, gregorianDateTime->monthDay(), gregorianDateTime->hour(), gregorianDateTime->minute(), gregorianDateTime->second(), ms);
else
charactersWritten = snprintf(buffer, sizeof(buffer), "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", gregorianDateTime->year(), gregorianDateTime->month() + 1, gregorianDateTime->monthDay(), gregorianDateTime->hour(), gregorianDateTime->minute(), gregorianDateTime->second(), ms);
ASSERT(charactersWritten > 0 && static_cast<unsigned>(charactersWritten) < sizeof(buffer));
if (static_cast<unsigned>(charactersWritten) >= sizeof(buffer))
return JSValue::encode(jsEmptyString(exec));
return JSValue::encode(jsNontrivialString(exec, String(buffer, charactersWritten)));
}
示例5: numberProtoFuncToExponential
// toExponential converts a number to a string, always formatting as an expoential.
// This method takes an optional argument specifying a number of *decimal places*
// to round the significand to (or, put another way, this method optionally rounds
// to argument-plus-one significant figures).
EncodedJSValue JSC_HOST_CALL numberProtoFuncToExponential(ExecState* exec)
{
double x;
if (!toThisNumber(exec->thisValue(), x))
return throwVMTypeError(exec);
// Get the argument.
int decimalPlacesInExponent;
bool isUndefined;
if (!getIntegerArgumentInRange(exec, 0, 20, decimalPlacesInExponent, isUndefined))
return throwVMError(exec, createRangeError(exec, ASCIILiteral("toExponential() argument must be between 0 and 20")));
// Handle NaN and Infinity.
if (!std::isfinite(x))
return JSValue::encode(jsNontrivialString(exec, String::numberToStringECMAScript(x)));
// Round if the argument is not undefined, always format as exponential.
char buffer[WTF::NumberToStringBufferLength];
DoubleConversionStringBuilder builder(buffer, WTF::NumberToStringBufferLength);
const DoubleToStringConverter& converter = DoubleToStringConverter::EcmaScriptConverter();
builder.Reset();
isUndefined
? converter.ToExponential(x, -1, &builder)
: converter.ToExponential(x, decimalPlacesInExponent, &builder);
return JSValue::encode(jsString(exec, String(builder.Finalize())));
}
示例6: numberProtoFuncToFixed
// toFixed converts a number to a string, always formatting as an a decimal fraction.
// This method takes an argument specifying a number of decimal places to round the
// significand to. However when converting large values (1e+21 and above) this
// method will instead fallback to calling ToString.
EncodedJSValue JSC_HOST_CALL numberProtoFuncToFixed(ExecState* exec)
{
double x;
if (!toThisNumber(exec->thisValue(), x))
return throwVMTypeError(exec);
// Get the argument.
int decimalPlaces;
bool isUndefined; // This is ignored; undefined treated as 0.
if (!getIntegerArgumentInRange(exec, 0, 20, decimalPlaces, isUndefined))
return throwVMError(exec, createRangeError(exec, ASCIILiteral("toFixed() argument must be between 0 and 20")));
// 15.7.4.5.7 states "If x >= 10^21, then let m = ToString(x)"
// This also covers Ininity, and structure the check so that NaN
// values are also handled by numberToString
if (!(fabs(x) < 1e+21))
return JSValue::encode(jsString(exec, String::numberToStringECMAScript(x)));
// The check above will return false for NaN or Infinity, these will be
// handled by numberToString.
ASSERT(std::isfinite(x));
NumberToStringBuffer buffer;
return JSValue::encode(jsString(exec, String(numberToFixedWidthString(x, decimalPlaces, buffer))));
}
示例7: webAssemblyTableProtoFuncSet
static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState* exec)
{
VM& vm = exec->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
JSWebAssemblyTable* table = getTable(exec, vm, exec->thisValue());
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
JSValue value = exec->argument(1);
WebAssemblyFunction* wasmFunction;
WebAssemblyWrapperFunction* wasmWrapperFunction;
if (!value.isNull() && !isWebAssemblyHostFunction(vm, value, wasmFunction, wasmWrapperFunction))
return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, "WebAssembly.Table.prototype.set expects the second argument to be null or an instance of WebAssembly.Function"_s)));
uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
if (index >= table->length())
return JSValue::encode(throwException(exec, throwScope, createRangeError(exec, "WebAssembly.Table.prototype.set expects an integer less than the length of the table"_s)));
if (value.isNull())
table->clearFunction(index);
else {
ASSERT(value.isObject() && isWebAssemblyHostFunction(vm, jsCast<JSObject*>(value), wasmFunction, wasmWrapperFunction));
ASSERT(!!wasmFunction || !!wasmWrapperFunction);
if (wasmFunction)
table->setFunction(vm, index, wasmFunction);
else
table->setFunction(vm, index, wasmWrapperFunction);
}
return JSValue::encode(jsUndefined());
}
示例8: numberProtoFuncToString
EncodedJSValue JSC_HOST_CALL numberProtoFuncToString(ExecState* exec)
{
double doubleValue;
if (!toThisNumber(exec->thisValue(), doubleValue))
return throwVMTypeError(exec);
int32_t radix = extractRadixFromArgs(exec);
if (radix < 2 || radix > 36)
return throwVMError(exec, createRangeError(exec, ASCIILiteral("toString() radix argument must be between 2 and 36")));
int32_t integerValue = static_cast<int32_t>(doubleValue);
if (integerValue == doubleValue)
return integerValueToString(exec, radix, integerValue);
if (radix == 10) {
VM* vm = &exec->vm();
return JSValue::encode(jsString(vm, vm->numericStrings.add(doubleValue)));
}
if (!std::isfinite(doubleValue))
return JSValue::encode(jsNontrivialString(exec, String::numberToStringECMAScript(doubleValue)));
RadixBuffer s;
return JSValue::encode(jsString(exec, toStringWithRadix(s, doubleValue, radix)));
}
示例9: numberProtoFuncToPrecision
// toPrecision converts a number to a string, takeing an argument specifying a
// number of significant figures to round the significand to. For positive
// exponent, all values that can be represented using a decimal fraction will
// be, e.g. when rounding to 3 s.f. any value up to 999 will be formated as a
// decimal, whilst 1000 is converted to the exponential representation 1.00e+3.
// For negative exponents values >= 1e-6 are formated as decimal fractions,
// with smaller values converted to exponential representation.
EncodedTiValue JSC_HOST_CALL numberProtoFuncToPrecision(TiExcState* exec)
{
// Get x (the double value of this, which should be a Number).
TiValue thisValue = exec->hostThisValue();
TiValue v = thisValue.getJSNumber();
if (!v)
return throwVMTypeError(exec);
double x = v.uncheckedGetNumber();
// Get the argument.
int significantFigures;
bool isUndefined;
if (!getIntegerArgumentInRange(exec, 1, 21, significantFigures, isUndefined))
return throwVMError(exec, createRangeError(exec, "toPrecision() argument must be between 1 and 21"));
// To precision called with no argument is treated as ToString.
if (isUndefined)
return TiValue::encode(jsString(exec, UString::number(x)));
// Handle NaN and Infinity.
if (isnan(x) || isinf(x))
return TiValue::encode(jsString(exec, UString::number(x)));
// Convert to decimal with rounding.
DecimalNumber number(x, RoundingSignificantFigures, significantFigures);
// If number is in the range 1e-6 <= x < pow(10, significantFigures) then format
// as decimal. Otherwise, format the number as an exponential. Decimal format
// demands a minimum of (exponent + 1) digits to represent a number, for example
// 1234 (1.234e+3) requires 4 digits. (See ECMA-262 15.7.4.7.10.c)
NumberToStringBuffer buffer;
unsigned length = number.exponent() >= -6 && number.exponent() < significantFigures
? number.toStringDecimal(buffer, WTI::NumberToStringBufferLength)
: number.toStringExponential(buffer, WTI::NumberToStringBufferLength);
return TiValue::encode(jsString(exec, UString(buffer, length)));
}
示例10: getData
EncodedJSValue getData(ExecState* exec)
{
JSDataView* dataView = jsDynamicCast<JSDataView*>(exec->thisValue());
if (!dataView)
return throwVMError(exec, createTypeError(exec, "Receiver of DataView method must be a DataView"));
if (!exec->argumentCount())
return throwVMError(exec, createTypeError(exec, "Need at least one argument (the byteOffset)"));
unsigned byteOffset = exec->uncheckedArgument(0).toUInt32(exec);
if (exec->hadException())
return JSValue::encode(jsUndefined());
bool littleEndian = false;
unsigned elementSize = sizeof(typename Adaptor::Type);
if (elementSize > 1 && exec->argumentCount() >= 2) {
littleEndian = exec->uncheckedArgument(1).toBoolean(exec);
if (exec->hadException())
return JSValue::encode(jsUndefined());
}
unsigned byteLength = dataView->length();
if (elementSize > byteLength || byteOffset > byteLength - elementSize)
return throwVMError(exec, createRangeError(exec, "Out of bounds access"));
typename Adaptor::Type value = *reinterpret_cast<typename Adaptor::Type*>(static_cast<uint8_t*>(dataView->vector()) + byteOffset);
if (needToFlipBytesIfLittleEndian(littleEndian))
value = flipBytes(value);
return JSValue::encode(Adaptor::toJSValue(value));
}
示例11: constructArrayWithSizeQuirk
JSObject* constructArrayWithSizeQuirk(ExecState* exec, ArrayAllocationProfile* profile, JSGlobalObject* globalObject, JSValue length)
{
if (!length.isNumber())
return constructArray(exec, profile, globalObject, &length, 1);
uint32_t n = length.toUInt32(exec);
if (n != length.toNumber(exec))
return exec->vm().throwException(exec, createRangeError(exec, ASCIILiteral("Array size is not a small enough positive integer.")));
return constructEmptyArray(exec, profile, globalObject, n);
}
示例12: createRangeError
void RuntimeArray::putByIndex(JSCell* cell, ExecState* exec, unsigned index, JSValue value, bool)
{
RuntimeArray* thisObject = jsCast<RuntimeArray*>(cell);
if (index >= thisObject->getLength()) {
exec->vm().throwException(exec, createRangeError(exec, "Range error"));
return;
}
thisObject->getConcreteArray()->setValueAt(exec, index, value);
}
示例13: throwVMError
JSDataView* JSDataView::create(
ExecState* exec, Structure* structure, PassRefPtr<ArrayBuffer> passedBuffer,
unsigned byteOffset, unsigned byteLength)
{
RefPtr<ArrayBuffer> buffer = passedBuffer;
if (!ArrayBufferView::verifySubRangeLength(buffer, byteOffset, byteLength, sizeof(uint8_t))) {
throwVMError(exec, createRangeError(exec, ASCIILiteral("Length out of range of buffer")));
return nullptr;
}
if (!ArrayBufferView::verifyByteOffsetAlignment(byteOffset, sizeof(uint8_t))) {
exec->vm().throwException(exec, createRangeError(exec, ASCIILiteral("Byte offset is not aligned")));
return nullptr;
}
VM& vm = exec->vm();
ConstructionContext context(
structure, buffer, byteOffset, byteLength, ConstructionContext::DataView);
ASSERT(context);
JSDataView* result =
new (NotNull, allocateCell<JSDataView>(vm.heap)) JSDataView(vm, context, buffer.get());
result->finishCreation(vm);
return result;
}
示例14: DECLARE_THROW_SCOPE
bool RuntimeArray::putByIndex(JSCell* cell, ExecState* exec, unsigned index, JSValue value, bool)
{
VM& vm = exec->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
RuntimeArray* thisObject = jsCast<RuntimeArray*>(cell);
if (index >= thisObject->getLength()) {
throwException(exec, scope, createRangeError(exec, "Range error"));
return false;
}
return thisObject->getConcreteArray()->setValueAt(exec, index, value);
}
示例15: constructMap
static EncodedJSValue JSC_HOST_CALL constructMap(ExecState* exec)
{
// Until we have iterators we throw if we've been given
// any arguments that could require us to throw.
if (!exec->argument(0).isUndefinedOrNull())
return JSValue::encode(throwTypeError(exec, ASCIILiteral("Map constructor does not accept arguments")));
if (!exec->argument(1).isUndefined())
return throwVMError(exec, createRangeError(exec, WTF::ASCIILiteral("Invalid comparator function")));
JSGlobalObject* globalObject = asInternalFunction(exec->callee())->globalObject();
Structure* mapStructure = globalObject->mapStructure();
return JSValue::encode(JSMap::create(exec, mapStructure));
}