return;
}
- if (ObjectIsSealed(array)) {
- throw MakeTypeError("array_functions_change_sealed",
- ["Array.prototype.shift"]);
- }
+ if (ObjectIsSealed(array)) throw MakeTypeError(kArrayFunctionsOnSealed);
if (%IsObserved(array))
return ObservedArrayShift.call(array, len);
var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0;
if (del_count != num_elements_to_add && ObjectIsSealed(array)) {
- throw MakeTypeError("array_functions_change_sealed",
- ["Array.prototype.splice"]);
+ throw MakeTypeError(kArrayFunctionsOnSealed);
} else if (del_count > 0 && ObjectIsFrozen(array)) {
- throw MakeTypeError("array_functions_on_frozen",
- ["Array.prototype.splice"]);
+ throw MakeTypeError(kArrayFunctionsOnFrozen);
}
var changed_elements = del_count;
break find_initial;
}
}
- throw MakeTypeError('reduce_no_initial', []);
+ throw MakeTypeError(kReduceNoInitial);
}
var receiver = %GetDefaultReceiver(callback);
break find_initial;
}
}
- throw MakeTypeError('reduce_no_initial', []);
+ throw MakeTypeError(kReduceNoInitial);
}
var receiver = %GetDefaultReceiver(callback);
// This file contains date support implemented in JavaScript.
-// Helper function to throw error.
-function ThrowDateTypeError() {
- throw new $TypeError('this is not a Date object.');
-}
-
var timezone_cache_time = NAN;
var timezone_cache_timezone;
}
if ((end - i) > 0 && ObjectIsFrozen(array)) {
- throw MakeTypeError("array_functions_on_frozen",
- ["Array.prototype.fill"]);
+ throw MakeTypeError(kArrayFunctionsOnFrozen);
}
for (; i < end; i++)
function addBoundMethod(obj, methodName, implementation, length) {
function getter() {
if (!%IsInitializedIntlObject(this)) {
- throw new $TypeError('Method ' + methodName + ' called on a ' +
- 'non-object or on a wrong type of object.');
+ throw MakeTypeError(kMethodCalledOnWrongObject, methodName);
}
var internalName = '__bound' + methodName + '__';
if (this[internalName] === undefined) {
if (length === undefined || length === 2) {
boundMethod = function(x, y) {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
return implementation(that, x, y);
}
} else if (length === 1) {
boundMethod = function(x) {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
return implementation(that, x);
}
} else {
boundMethod = function() {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
// DateTimeFormat.format needs to be 0 arg method, but can stil
// receive optional dateValue param. If one was provided, pass it
*/
function supportedLocalesOf(service, locales, options) {
if (IS_NULL(service.match(GetServiceRE()))) {
- throw new $Error('Internal error, wrong service type: ' + service);
+ throw MakeError(kWrongServiceType, service);
}
// Provide defaults if matcher was not specified.
if (matcher !== undefined) {
matcher = GlobalString(matcher);
if (matcher !== 'lookup' && matcher !== 'best fit') {
- throw new $RangeError('Illegal value for localeMatcher:' + matcher);
+ throw MakeRangeError(kLocaleMatcher, matcher);
}
} else {
matcher = 'best fit';
* is out of range for that property it throws RangeError.
*/
function getGetOption(options, caller) {
- if (options === undefined) {
- throw new $Error('Internal ' + caller + ' error. ' +
- 'Default options are missing.');
- }
+ if (options === undefined) throw MakeError(kDefaultOptionsMissing, caller);
var getOption = function getOption(property, type, values, defaultValue) {
if (options[property] !== undefined) {
value = GlobalNumber(value);
break;
default:
- throw new $Error('Internal error. Wrong value type.');
+ throw MakeError(kWrongValueType);
}
if (values !== undefined && values.indexOf(value) === -1) {
- throw new $RangeError('Value ' + value + ' out of range for ' + caller +
- ' options property ' + property);
+ throw MakeRangeError(kValueOutOfRange, value, caller, property);
}
return value;
*/
function lookupMatcher(service, requestedLocales) {
if (IS_NULL(service.match(GetServiceRE()))) {
- throw new $Error('Internal error, wrong service type: ' + service);
+ throw MakeError(kWrongServiceType, service);
}
// Cache these, they don't ever change per service.
// null is typeof 'object' so we have to do extra check.
if (typeof localeID !== 'string' && typeof localeID !== 'object' ||
IS_NULL(localeID)) {
- throw new $TypeError('Language ID should be string or object.');
+ throw MakeTypeError(kLanguageID);
}
var localeString = GlobalString(localeID);
if (isValidLanguageTag(localeString) === false) {
- throw new $RangeError('Invalid language tag: ' + localeString);
+ throw MakeRangeError(kInvalidLanguageTag, localeString);
}
// This call will strip -kn but not -kn-true extensions.
// upgrade to ICU 4.9.
var tag = %CanonicalizeLanguageTag(localeString);
if (tag === 'invalid-tag') {
- throw new $RangeError('Invalid language tag: ' + localeString);
+ throw MakeRangeError(kInvalidLanguageTag, localeString);
}
return tag;
*/
function initializeCollator(collator, locales, options) {
if (%IsInitializedIntlObject(collator)) {
- throw new $TypeError('Trying to re-initialize Collator object.');
+ throw MakeTypeError(kReinitializeIntl, "Collator");
}
if (options === undefined) {
*/
%AddNamedProperty(Intl.Collator.prototype, 'resolvedOptions', function() {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
if (!%IsInitializedIntlObjectOfType(this, 'collator')) {
- throw new $TypeError('resolvedOptions method called on a non-object ' +
- 'or on a object that is not Intl.Collator.');
+ throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "Collator");
}
var coll = this;
*/
%AddNamedProperty(Intl.Collator, 'supportedLocalesOf', function(locales) {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
return supportedLocalesOf('collator', locales, %_Arguments(1));
if (value !== undefined) {
value = GlobalNumber(value);
if ($isNaN(value) || value < min || value > max) {
- throw new $RangeError(property + ' value is out of range.');
+ throw MakeRangeError(kPropertyValueOutOfRange, property);
}
return $floor(value);
}
*/
function initializeNumberFormat(numberFormat, locales, options) {
if (%IsInitializedIntlObject(numberFormat)) {
- throw new $TypeError('Trying to re-initialize NumberFormat object.');
+ throw MakeTypeError(kReinitializeIntl, "NumberFormat");
}
if (options === undefined) {
var currency = getOption('currency', 'string');
if (currency !== undefined && !isWellFormedCurrencyCode(currency)) {
- throw new $RangeError('Invalid currency code: ' + currency);
+ throw MakeRangeError(kInvalidCurrencyCode, currency);
}
if (internalOptions.style === 'currency' && currency === undefined) {
- throw new $TypeError('Currency code is required with currency style.');
+ throw MakeTypeError(kCurrencyCode);
}
var currencyDisplay = getOption(
*/
%AddNamedProperty(Intl.NumberFormat.prototype, 'resolvedOptions', function() {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
if (!%IsInitializedIntlObjectOfType(this, 'numberformat')) {
- throw new $TypeError('resolvedOptions method called on a non-object' +
- ' or on a object that is not Intl.NumberFormat.');
+ throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "NumberFormat");
}
var format = this;
*/
%AddNamedProperty(Intl.NumberFormat, 'supportedLocalesOf', function(locales) {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
return supportedLocalesOf('numberformat', locales, %_Arguments(1));
function initializeDateTimeFormat(dateFormat, locales, options) {
if (%IsInitializedIntlObject(dateFormat)) {
- throw new $TypeError('Trying to re-initialize DateTimeFormat object.');
+ throw MakeTypeError(kReinitializeIntl, "DateTimeFormat");
}
if (options === undefined) {
requestedLocale, {skeleton: ldmlString, timeZone: tz}, resolved);
if (tz !== undefined && tz !== resolved.timeZone) {
- throw new $RangeError('Unsupported time zone specified ' + tz);
+ throw MakeRangeError(kUnsupportedTimeZone, tz);
}
%MarkAsInitializedIntlObjectOfType(dateFormat, 'dateformat', formatter);
*/
%AddNamedProperty(Intl.DateTimeFormat.prototype, 'resolvedOptions', function() {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
if (!%IsInitializedIntlObjectOfType(this, 'dateformat')) {
- throw new $TypeError('resolvedOptions method called on a non-object or ' +
- 'on a object that is not Intl.DateTimeFormat.');
+ throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "DateTimeFormat");
}
var format = this;
*/
%AddNamedProperty(Intl.DateTimeFormat, 'supportedLocalesOf', function(locales) {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
return supportedLocalesOf('dateformat', locales, %_Arguments(1));
dateMs = GlobalNumber(dateValue);
}
- if (!$isFinite(dateMs)) {
- throw new $RangeError('Provided date is not in valid range.');
- }
+ if (!$isFinite(dateMs)) throw MakeRangeError(kDateRange);
return %InternalDateFormat(%GetImplFromInitializedIntlObject(formatter),
new GlobalDate(dateMs));
// We expect only _ and / beside ASCII letters.
// All inputs should conform to Area/Location from now on.
var match = GetTimezoneNameCheckRE().exec(tzID);
- if (IS_NULL(match)) {
- throw new $RangeError('Expected Area/Location for time zone, got ' + tzID);
- }
+ if (IS_NULL(match)) throw MakeRangeError(kExpectedLocation, tzID);
var result = toTitleCaseWord(match[1]) + '/' + toTitleCaseWord(match[2]);
var i = 3;
*/
function initializeBreakIterator(iterator, locales, options) {
if (%IsInitializedIntlObject(iterator)) {
- throw new $TypeError('Trying to re-initialize v8BreakIterator object.');
+ throw MakeTypeError(kReinitializeIntl, "v8BreakIterator");
}
if (options === undefined) {
%AddNamedProperty(Intl.v8BreakIterator.prototype, 'resolvedOptions',
function() {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
if (!%IsInitializedIntlObjectOfType(this, 'breakiterator')) {
- throw new $TypeError('resolvedOptions method called on a non-object or ' +
- 'on a object that is not Intl.v8BreakIterator.');
+ throw MakeTypeError(kResolvedOptionsCalledOnNonObject, "v8BreakIterator");
}
var segmenter = this;
%AddNamedProperty(Intl.v8BreakIterator, 'supportedLocalesOf',
function(locales) {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
return supportedLocalesOf('breakiterator', locales, %_Arguments(1));
*/
OverrideFunction(GlobalString.prototype, 'localeCompare', function(that) {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
if (IS_NULL_OR_UNDEFINED(this)) {
- throw new $TypeError('Method invoked on undefined or null value.');
+ throw MakeTypeError(kMethodInvokedOnNullOrUndefined);
}
var locales = %_Arguments(1);
*/
OverrideFunction(GlobalString.prototype, 'normalize', function(that) {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
var normalizationForm = NORMALIZATION_FORMS.indexOf(form);
if (normalizationForm === -1) {
- throw new $RangeError('The normalization form should be one of '
- + NORMALIZATION_FORMS.join(', ') + '.');
+ throw MakeRangeError(kNormalizationForm, NORMALIZATION_FORMS.join(', '));
}
return %StringNormalize(this, normalizationForm);
*/
OverrideFunction(GlobalNumber.prototype, 'toLocaleString', function() {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
if (!(this instanceof GlobalNumber) && typeof(this) !== 'number') {
- throw new $TypeError('Method invoked on an object that is not Number.');
+ throw MakeTypeError(kMethodInvokedOnWrongType, "Number");
}
var locales = %_Arguments(0);
*/
function toLocaleDateTime(date, locales, options, required, defaults, service) {
if (!(date instanceof GlobalDate)) {
- throw new $TypeError('Method invoked on an object that is not Date.');
+ throw MakeTypeError(kMethodInvokedOnWrongType, "Date");
}
if ($isNaN(date)) {
*/
OverrideFunction(GlobalDate.prototype, 'toLocaleString', function() {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
var locales = %_Arguments(0);
*/
OverrideFunction(GlobalDate.prototype, 'toLocaleDateString', function() {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
var locales = %_Arguments(0);
*/
OverrideFunction(GlobalDate.prototype, 'toLocaleTimeString', function() {
if (%_IsConstructCall()) {
- throw new $TypeError(ORDINARY_FUNCTION_CALLED_AS_CONSTRUCTOR);
+ throw MakeTypeError(kOrdinaryFunctionCalledAsConstructor);
}
var locales = %_Arguments(0);
# Macro for ES6 CheckObjectCoercible
# Will throw a TypeError of the form "[functionName] called on null or undefined".
-macro CHECK_OBJECT_COERCIBLE(arg, functionName) = if (IS_NULL_OR_UNDEFINED(arg) && !IS_UNDETECTABLE(arg)) throw MakeTypeError('called_on_null_or_undefined', [functionName]);
+macro CHECK_OBJECT_COERCIBLE(arg, functionName) = if (IS_NULL_OR_UNDEFINED(arg) && !IS_UNDETECTABLE(arg)) throw MakeTypeError(kCalledOnNullOrUndefined, functionName);
# Indices in bound function info retrieved by %BoundFunctionGetBindings(...).
const kBoundFunctionIndex = 0;
# Gets the value of a Date object. If arg is not a Date object
# a type error is thrown.
-macro CHECK_DATE(arg) = if (%_ClassOf(arg) !== 'Date') ThrowDateTypeError();
+macro CHECK_DATE(arg) = if (%_ClassOf(arg) !== 'Date') throw MakeTypeError(kDateType);
macro LOCAL_DATE_VALUE(arg) = (%_DateField(arg, 0) + %_DateField(arg, 21));
macro UTC_DATE_VALUE(arg) = (%_DateField(arg, 0));
#define MESSAGE_TEMPLATES(T) \
/* Error */ \
T(CyclicProto, "Cyclic __proto__ value") \
+ T(DefaultOptionsMissing, "Internal % error. Default options are missing.") \
+ T(Unsupported, "Not supported") \
+ T(WrongServiceType, "Internal error, wrong service type: %") \
+ T(WrongValueType, "Internal error. Wrong value type.") \
/* TypeError */ \
T(ApplyNonFunction, \
"Function.prototype.apply was called on %, which is a % and not a " \
"function") \
+ T(ArrayFunctionsOnFrozen, "Cannot modify frozen array elements") \
+ T(ArrayFunctionsOnSealed, "Cannot add/remove sealed array elements") \
T(CalledNonCallable, "% is not a function") \
T(CalledOnNonObject, "% called on non-object") \
+ T(CalledOnNullOrUndefined, "% called on null or undefined") \
+ T(CurrencyCode, "Currency code is required with currency style.") \
T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \
+ T(DateType, "this is not a Date object.") \
T(DefineDisallowed, "Cannot define property:%, object is not extensible.") \
T(GeneratorRunning, "Generator is already running") \
T(FunctionBind, "Bind must be called on a function") \
T(InstanceofNonobjectProto, \
"Function has non-object prototype '%' in instanceof check") \
T(InvalidInOperatorUse, "Cannot use 'in' operator to search for '%' in %") \
+ T(LanguageID, "Language ID should be string or object.") \
+ T(MethodCalledOnWrongObject, \
+ "Method % called on a non-object or on a wrong type of object.") \
+ T(MethodInvokedOnNullOrUndefined, \
+ "Method invoked on undefined or null value.") \
+ T(MethodInvokedOnWrongType, "Method invoked on an object that is not %.") \
T(NotAnIterator, "% is not an iterator") \
T(NotConstructor, "% is not a constructor") \
T(NotGeneric, "% is not generic") \
T(ObjectSetterExpectingFunction, \
"Object.prototype.__defineSetter__: Expecting function") \
T(ObjectSetterCallable, "Setter must be a function: %") \
+ T(OrdinaryFunctionCalledAsConstructor, \
+ "Function object that's not a constructor was created with new") \
T(PropertyDescObject, "Property description must be an object: %") \
T(PropertyNotFunction, "Property '%' of object % is not a function") \
T(ProtoObjectOrNull, "Object prototype may only be an Object or null: %") \
"Proxy handler % returned non-configurable descriptor for property '%' " \
"from '%' trap") \
T(RedefineDisallowed, "Cannot redefine property: %") \
+ T(ReduceNoInitial, "Reduce of empty array with no initial value") \
+ T(ReinitializeIntl, "Trying to re-initialize % object.") \
+ T(ResolvedOptionsCalledOnNonObject, \
+ "resolvedOptions method called on a non-object or on a object that is " \
+ "not Intl.%.") \
T(SymbolToPrimitive, \
"Cannot convert a Symbol wrapper object to a primitive value") \
T(SymbolToNumber, "Cannot convert a Symbol value to a number") \
T(WrongArgs, "%: Arguments list has wrong type") \
/* RangeError */ \
T(ArrayLengthOutOfRange, "defineProperty() array length out of range") \
+ T(DateRange, "Provided date is not in valid range.") \
+ T(ExpectedLocation, "Expected Area/Location for time zone, got %") \
+ T(InvalidCurrencyCode, "Invalid currency code: %") \
+ T(InvalidLanguageTag, "Invalid language tag: %") \
+ T(LocaleMatcher, "Illegal value for localeMatcher:%") \
+ T(NormalizationForm, "The normalization form should be one of %.") \
T(NumberFormatRange, "% argument must be between 0 and 20") \
+ T(PropertyValueOutOfRange, "% value is out of range.") \
T(StackOverflow, "Maximum call stack size exceeded") \
T(ToPrecisionFormatRange, "toPrecision() argument must be between 1 and 21") \
+ T(ToRadixFormatRange, "toString() radix argument must be between 2 and 36") \
+ T(UnsupportedTimeZone, "Unsupported time zone specified %") \
+ T(ValueOutOfRange, "Value % out of range for % options property %") \
/* SyntaxError */ \
T(ParenthesisInArgString, "Function arg string contains parenthesis") \
/* EvalError */ \
- T(CodeGenFromStrings, "%")
+ T(CodeGenFromStrings, "%") \
+ /* URIError */ \
+ T(URIMalformed, "URI malformed")
class MessageTemplate {
public:
illegal_invocation: ["Illegal invocation"],
no_setter_in_callback: ["Cannot set property ", "%0", " of ", "%1", " which has only a getter"],
flags_getter_non_object: ["RegExp.prototype.flags getter called on non-object ", "%0"],
- reduce_no_initial: ["Reduce of empty array with no initial value"],
value_and_accessor: ["Invalid property. A property cannot both have accessors and be writable or have a value, ", "%0"],
proto_object_or_null: ["Object prototype may only be an Object or null: ", "%0"],
non_extensible_proto: ["%0", " is not extensible"],
not_a_promise: ["%0", " is not a promise"],
resolver_not_a_function: ["Promise resolver ", "%0", " is not a function"],
promise_cyclic: ["Chaining cycle detected for promise ", "%0"],
- array_functions_on_frozen: ["Cannot modify frozen array elements"],
- array_functions_change_sealed: ["Cannot add/remove sealed array elements"],
first_argument_not_regexp: ["First argument to ", "%0", " must not be a regular expression"],
iterator_result_not_an_object: ["Iterator result ", "%0", " is not an object"],
iterator_value_not_an_object: ["Iterator value ", "%0", " is not an entry object"],
illegal_return: ["Illegal return statement"],
error_loading_debugger: ["Error loading debugger"],
circular_structure: ["Converting circular structure to JSON"],
- called_on_null_or_undefined: ["%0", " called on null or undefined"],
array_indexof_not_defined: ["Array.getIndexOf: Argument undefined"],
object_not_extensible: ["Can't add property ", "%0", ", object is not extensible"],
illegal_access: ["Illegal access"],
DONT_ENUM | DONT_DELETE | READ_ONLY);
%SetCode(Script, function(x) {
// Script objects can only be created by the VM.
- throw new $Error("Not supported");
+ throw MakeError(kUnsupported);
});
return MakeGenericError($EvalError, type, arg0, arg1, arg2);
}
+
+function MakeURIError() {
+ return MakeGenericError($URIError, kURIMalformed);
+}
+
// The embedded versions are called from unoptimized code, with embedded
// arguments. Those arguments cannot be arrays, which are context-dependent.
function MakeTypeErrorEmbedded(type, arg) {
var form = form ? TO_STRING_INLINE(form) : 'NFC';
var normalizationForm = NORMALIZATION_FORMS.indexOf(form);
if (normalizationForm === -1) {
- throw new $RangeError('The normalization form should be one of '
- + NORMALIZATION_FORMS.join(', ') + '.');
+ throw MakeRangeError(kNormalizationForm, NORMALIZATION_FORMS.join(', '));
}
return %_ValueOf(this);
function URIHexCharsToCharCode(highChar, lowChar) {
var highCode = HexValueOf(highChar);
var lowCode = HexValueOf(lowChar);
- if (highCode == -1 || lowCode == -1) {
- throw new $URIError("URI malformed");
- }
+ if (highCode == -1 || lowCode == -1) throw MakeURIError();
return (highCode << 4) | lowCode;
}
if (o0 < 0x80) {
value = o0;
} else if (o0 < 0xc2) {
- throw new $URIError("URI malformed");
+ throw MakeURIError();
} else {
var o1 = octets[1];
if (o0 < 0xe0) {
var a = o0 & 0x1f;
- if ((o1 < 0x80) || (o1 > 0xbf)) {
- throw new $URIError("URI malformed");
- }
+ if ((o1 < 0x80) || (o1 > 0xbf)) throw MakeURIError();
var b = o1 & 0x3f;
value = (a << 6) + b;
- if (value < 0x80 || value > 0x7ff) {
- throw new $URIError("URI malformed");
- }
+ if (value < 0x80 || value > 0x7ff) throw MakeURIError();
} else {
var o2 = octets[2];
if (o0 < 0xf0) {
var a = o0 & 0x0f;
- if ((o1 < 0x80) || (o1 > 0xbf)) {
- throw new $URIError("URI malformed");
- }
+ if ((o1 < 0x80) || (o1 > 0xbf)) throw MakeURIError();
var b = o1 & 0x3f;
- if ((o2 < 0x80) || (o2 > 0xbf)) {
- throw new $URIError("URI malformed");
- }
+ if ((o2 < 0x80) || (o2 > 0xbf)) throw MakeURIError();
var c = o2 & 0x3f;
value = (a << 12) + (b << 6) + c;
- if ((value < 0x800) || (value > 0xffff)) {
- throw new $URIError("URI malformed");
- }
+ if ((value < 0x800) || (value > 0xffff)) throw MakeURIError();
} else {
var o3 = octets[3];
if (o0 < 0xf8) {
var a = (o0 & 0x07);
- if ((o1 < 0x80) || (o1 > 0xbf)) {
- throw new $URIError("URI malformed");
- }
+ if ((o1 < 0x80) || (o1 > 0xbf)) throw MakeURIError();
var b = (o1 & 0x3f);
if ((o2 < 0x80) || (o2 > 0xbf)) {
- throw new $URIError("URI malformed");
+ throw MakeURIError();
}
var c = (o2 & 0x3f);
- if ((o3 < 0x80) || (o3 > 0xbf)) {
- throw new $URIError("URI malformed");
- }
+ if ((o3 < 0x80) || (o3 > 0xbf)) throw MakeURIError();
var d = (o3 & 0x3f);
value = (a << 18) + (b << 12) + (c << 6) + d;
- if ((value < 0x10000) || (value > 0x10ffff)) {
- throw new $URIError("URI malformed");
- }
+ if ((value < 0x10000) || (value > 0x10ffff)) throw MakeURIError();
} else {
- throw new $URIError("URI malformed");
+ throw MakeURIError();
}
}
}
}
- if (0xD800 <= value && value <= 0xDFFF) {
- throw new $URIError("URI malformed");
- }
+ if (0xD800 <= value && value <= 0xDFFF) throw MakeURIError();
if (value < 0x10000) {
%_TwoByteSeqStringSetChar(index++, value, result);
} else {
if (unescape(cc1)) {
array[index++] = cc1;
} else {
- if (cc1 >= 0xDC00 && cc1 <= 0xDFFF) throw new $URIError("URI malformed");
+ if (cc1 >= 0xDC00 && cc1 <= 0xDFFF) throw MakeURIError();
if (cc1 < 0xD800 || cc1 > 0xDBFF) {
index = URIEncodeSingle(cc1, array, index);
} else {
k++;
- if (k == uriLength) throw new $URIError("URI malformed");
+ if (k == uriLength) throw MakeURIError();
var cc2 = uri.charCodeAt(k);
- if (cc2 < 0xDC00 || cc2 > 0xDFFF) throw new $URIError("URI malformed");
+ if (cc2 < 0xDC00 || cc2 > 0xDFFF) throw MakeURIError();
index = URIEncodePair(cc1, cc2, array, index);
}
}
for ( ; k < uriLength; k++) {
var code = uri.charCodeAt(k);
if (code == 37) { // '%'
- if (k + 2 >= uriLength) throw new $URIError("URI malformed");
+ if (k + 2 >= uriLength) throw MakeURIError();
var cc = URIHexCharsToCharCode(uri.charCodeAt(k+1), uri.charCodeAt(k+2));
if (cc >> 7) break; // Assumption wrong, two-byte string.
if (reserved(cc)) {
for ( ; k < uriLength; k++) {
var code = uri.charCodeAt(k);
if (code == 37) { // '%'
- if (k + 2 >= uriLength) throw new $URIError("URI malformed");
+ if (k + 2 >= uriLength) throw MakeURIError();
var cc = URIHexCharsToCharCode(uri.charCodeAt(++k), uri.charCodeAt(++k));
if (cc >> 7) {
var n = 0;
while (((cc << ++n) & 0x80) != 0) { }
- if (n == 1 || n > 4) throw new $URIError("URI malformed");
+ if (n == 1 || n > 4) throw MakeURIError();
var octets = new GlobalArray(n);
octets[0] = cc;
- if (k + 3 * (n - 1) >= uriLength) throw new $URIError("URI malformed");
+ if (k + 3 * (n - 1) >= uriLength) throw MakeURIError();
for (var i = 1; i < n; i++) {
- if (uri.charAt(++k) != '%') throw new $URIError("URI malformed");
+ if (uri.charAt(++k) != '%') throw MakeURIError();
octets[i] = URIHexCharsToCharCode(uri.charCodeAt(++k),
uri.charCodeAt(++k));
}
// Convert the radix to an integer and check the range.
radix = TO_INTEGER(radix);
- if (radix < 2 || radix > 36) {
- throw new $RangeError('toString() radix argument must be between 2 and 36');
- }
+ if (radix < 2 || radix > 36) throw MakeRangeError(kToRadixFormatRange);
// Convert the number to a string in the given radix.
return %NumberToRadixString(number, radix);
}
}, "Function.prototype.apply was called on 1, which is a number " +
"and not a function", TypeError);
+// kArrayFunctionsOnFrozen
+test(function() {
+ var a = [1, 2];
+ Object.freeze(a);
+ a.splice(1, 1, [1]);
+}, "Cannot modify frozen array elements", TypeError);
+
+// kArrayFunctionsOnSealed
+test(function() {
+ var a = [1];
+ Object.seal(a);
+ a.shift();
+}, "Cannot add/remove sealed array elements", TypeError);
+
// kCalledNonCallable
test(function() {
[].forEach(1);
}, "1 is not a function", TypeError);
+// kCalledOnNonObject
+test(function() {
+ Object.defineProperty(1, "x", {});
+}, "Object.defineProperty called on non-object", TypeError);
+
+// kCalledOnNullOrUndefined
+test(function() {
+ Array.prototype.shift.call(null);
+}, "Array.prototype.shift called on null or undefined", TypeError);
+
// kCannotConvertToPrimitive
test(function() {
[].join(Object(Symbol(1)));
}, "Cannot convert object to primitive value", TypeError);
+// kDateType
+test(function() {
+ Date.prototype.setYear.call({}, 1);
+}, "this is not a Date object.", TypeError);
+
// kDefineDisallowed
test(function() {
"use strict";
Function.prototype.toString.call(1);
}, "Function.prototype.toString is not generic", TypeError);
-
// kObjectGetterExpectingFunction
test(function() {
({}).__defineGetter__("x", 0);
Object.defineProperty(o, "x", { value: 2 });
}, "Cannot redefine property: x", TypeError);
+// kReduceNoInitial
+test(function() {
+ [].reduce(function() {});
+}, "Reduce of empty array with no initial value", TypeError);
+
// kSymbolToPrimitive
test(function() {
1 + Object(Symbol());
Object.defineProperty([], "length", { value: 1E100 });
}, "defineProperty() array length out of range", RangeError);
-//kNumberFormatRange
+// kNormalizationForm
+test(function() {
+ "".normalize("ABC");
+}, "The normalization form should be one of NFC, NFD, NFKC, NFKD.", RangeError);
+
+// kNumberFormatRange
test(function() {
Number(1).toFixed(100);
}, "toFixed() digits argument must be between 0 and 20", RangeError);
test(function() {
Number(1).toPrecision(100);
}, "toPrecision() argument must be between 1 and 21", RangeError);
+
+// kToPrecisionFormatRange
+test(function() {
+ Number(1).toString(100);
+}, "toString() radix argument must be between 2 and 36", RangeError);
+
+
+// === URIError ===
+
+// kURIMalformed
+test(function() {
+ decodeURI("%%");
+}, "URI malformed", URIError);
EVAL_PATTERN = re.compile(r'\beval\s*\(')
WITH_PATTERN = re.compile(r'\bwith\s*\(')
-INVALID_ERROR_MESSAGE_PATTERN = re.compile(r'Make\w*Error\((k\w+),')
+INVALID_ERROR_MESSAGE_PATTERN = re.compile(r'Make\w*Error\(([kA-Z]\w+)')
+NEW_ERROR_PATTERN = re.compile(r'new \$\w*Error\((?!\))');
def Validate(lines):
# Because of simplified context setup, eval and with is not
invalid_error = INVALID_ERROR_MESSAGE_PATTERN.search(lines)
if invalid_error:
raise Error("Unknown error message template '%s'" % invalid_error.group(1))
+ if NEW_ERROR_PATTERN.search(lines):
+ raise Error("Error constructed without message template.")
# Pass lines through unchanged.
return lines