2008-09-09 20:08:45 +00:00
|
|
|
// Copyright 2006-2008 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// The infrastructure used for (localized) message reporting in V8.
|
|
|
|
//
|
|
|
|
// Note: there's a big unresolved issue about ownership of the data
|
|
|
|
// structures used by this framework.
|
|
|
|
|
|
|
|
#ifndef V8_MESSAGES_H_
|
|
|
|
#define V8_MESSAGES_H_
|
|
|
|
|
|
|
|
// Forward declaration of MessageLocation.
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
class MessageLocation;
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
|
|
|
|
class V8Message {
|
|
|
|
public:
|
|
|
|
V8Message(char* type,
|
|
|
|
v8::internal::Handle<v8::internal::JSArray> args,
|
|
|
|
const v8::internal::MessageLocation* loc) :
|
|
|
|
type_(type), args_(args), loc_(loc) { }
|
|
|
|
char* type() const { return type_; }
|
|
|
|
v8::internal::Handle<v8::internal::JSArray> args() const { return args_; }
|
|
|
|
const v8::internal::MessageLocation* loc() const { return loc_; }
|
|
|
|
private:
|
|
|
|
char* type_;
|
|
|
|
v8::internal::Handle<v8::internal::JSArray> const args_;
|
|
|
|
const v8::internal::MessageLocation* loc_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
struct Language;
|
|
|
|
class SourceInfo;
|
|
|
|
|
|
|
|
class MessageLocation {
|
|
|
|
public:
|
2015-01-21 13:40:32 +00:00
|
|
|
MessageLocation(Handle<Script> script, int start_pos, int end_pos,
|
|
|
|
Handle<JSFunction> function = Handle<JSFunction>())
|
2008-07-03 15:10:15 +00:00
|
|
|
: script_(script),
|
|
|
|
start_pos_(start_pos),
|
2015-01-21 13:40:32 +00:00
|
|
|
end_pos_(end_pos),
|
|
|
|
function_(function) {}
|
2008-09-09 18:55:41 +00:00
|
|
|
MessageLocation() : start_pos_(-1), end_pos_(-1) { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
Handle<Script> script() const { return script_; }
|
|
|
|
int start_pos() const { return start_pos_; }
|
|
|
|
int end_pos() const { return end_pos_; }
|
2015-01-21 13:40:32 +00:00
|
|
|
Handle<JSFunction> function() const { return function_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Handle<Script> script_;
|
|
|
|
int start_pos_;
|
|
|
|
int end_pos_;
|
2015-01-21 13:40:32 +00:00
|
|
|
Handle<JSFunction> function_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A message handler is a convenience interface for accessing the list
|
|
|
|
// of message listeners registered in an environment
|
|
|
|
class MessageHandler {
|
|
|
|
public:
|
2008-09-09 18:55:41 +00:00
|
|
|
// Returns a message object for the API to use.
|
2011-02-02 13:31:52 +00:00
|
|
|
static Handle<JSMessageObject> MakeMessageObject(
|
2013-06-04 10:30:05 +00:00
|
|
|
Isolate* isolate,
|
2011-02-02 13:31:52 +00:00
|
|
|
const char* type,
|
|
|
|
MessageLocation* loc,
|
|
|
|
Vector< Handle<Object> > args,
|
|
|
|
Handle<JSArray> stack_frames);
|
2008-09-09 18:55:41 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Report a formatted message (needs JS allocation).
|
2011-04-07 19:52:24 +00:00
|
|
|
static void ReportMessage(Isolate* isolate,
|
|
|
|
MessageLocation* loc,
|
|
|
|
Handle<Object> message);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-02-15 09:27:10 +00:00
|
|
|
static void DefaultMessageReport(Isolate* isolate,
|
|
|
|
const MessageLocation* loc,
|
2008-07-03 15:10:15 +00:00
|
|
|
Handle<Object> message_obj);
|
2013-02-25 14:46:09 +00:00
|
|
|
static Handle<String> GetMessage(Isolate* isolate, Handle<Object> data);
|
2013-02-15 09:27:10 +00:00
|
|
|
static SmartArrayPointer<char> GetLocalizedMessage(Isolate* isolate,
|
|
|
|
Handle<Object> data);
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
2015-04-16 07:01:20 +00:00
|
|
|
|
2015-04-28 08:53:12 +00:00
|
|
|
class CallSite {
|
|
|
|
public:
|
|
|
|
CallSite(Handle<Object> receiver, Handle<JSFunction> fun, int pos)
|
|
|
|
: receiver_(receiver), fun_(fun), pos_(pos) {}
|
|
|
|
|
|
|
|
Handle<Object> GetFileName(Isolate* isolate);
|
|
|
|
Handle<Object> GetFunctionName(Isolate* isolate);
|
|
|
|
Handle<Object> GetScriptNameOrSourceUrl(Isolate* isolate);
|
2015-05-05 13:55:28 +00:00
|
|
|
Handle<Object> GetMethodName(Isolate* isolate);
|
2015-04-28 08:53:12 +00:00
|
|
|
// Return 1-based line number, including line offset.
|
|
|
|
int GetLineNumber(Isolate* isolate);
|
|
|
|
// Return 1-based column number, including column offset if first line.
|
|
|
|
int GetColumnNumber(Isolate* isolate);
|
|
|
|
bool IsNative(Isolate* isolate);
|
|
|
|
bool IsToplevel(Isolate* isolate);
|
|
|
|
bool IsEval(Isolate* isolate);
|
2015-05-05 13:55:28 +00:00
|
|
|
bool IsConstructor(Isolate* isolate);
|
2015-04-28 08:53:12 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Handle<Object> receiver_;
|
|
|
|
Handle<JSFunction> fun_;
|
|
|
|
int pos_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-04-21 09:03:24 +00:00
|
|
|
#define MESSAGE_TEMPLATES(T) \
|
|
|
|
/* Error */ \
|
|
|
|
T(CyclicProto, "Cyclic __proto__ value") \
|
2015-04-24 10:22:00 +00:00
|
|
|
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.") \
|
2015-04-21 09:03:24 +00:00
|
|
|
/* TypeError */ \
|
|
|
|
T(ApplyNonFunction, \
|
|
|
|
"Function.prototype.apply was called on %, which is a % and not a " \
|
|
|
|
"function") \
|
2015-04-24 10:22:00 +00:00
|
|
|
T(ArrayFunctionsOnFrozen, "Cannot modify frozen array elements") \
|
|
|
|
T(ArrayFunctionsOnSealed, "Cannot add/remove sealed array elements") \
|
2015-04-21 09:03:24 +00:00
|
|
|
T(CalledNonCallable, "% is not a function") \
|
|
|
|
T(CalledOnNonObject, "% called on non-object") \
|
2015-04-24 10:22:00 +00:00
|
|
|
T(CalledOnNullOrUndefined, "% called on null or undefined") \
|
2015-04-21 09:03:24 +00:00
|
|
|
T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \
|
2015-05-05 07:57:37 +00:00
|
|
|
T(ConstructorNotFunction, "Constructor % requires 'new'") \
|
|
|
|
T(CurrencyCode, "Currency code is required with currency style.") \
|
2015-05-06 07:51:56 +00:00
|
|
|
T(DataViewNotArrayBuffer, \
|
|
|
|
"First argument to DataView constructor must be an ArrayBuffer") \
|
2015-04-24 10:22:00 +00:00
|
|
|
T(DateType, "this is not a Date object.") \
|
2015-04-21 09:03:24 +00:00
|
|
|
T(DefineDisallowed, "Cannot define property:%, object is not extensible.") \
|
2015-04-30 16:22:00 +00:00
|
|
|
T(FirstArgumentNotRegExp, \
|
|
|
|
"First argument to % must not be a regular expression") \
|
2015-05-05 07:57:37 +00:00
|
|
|
T(FlagsGetterNonObject, \
|
|
|
|
"RegExp.prototype.flags getter called on non-object %") \
|
2015-04-21 09:03:24 +00:00
|
|
|
T(FunctionBind, "Bind must be called on a function") \
|
2015-04-30 16:22:00 +00:00
|
|
|
T(GeneratorRunning, "Generator is already running") \
|
2015-04-21 09:03:24 +00:00
|
|
|
T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %") \
|
|
|
|
T(InstanceofFunctionExpected, \
|
|
|
|
"Expecting a function in instanceof check, but got %") \
|
|
|
|
T(InstanceofNonobjectProto, \
|
|
|
|
"Function has non-object prototype '%' in instanceof check") \
|
2015-05-06 07:51:56 +00:00
|
|
|
T(InvalidArgument, "invalid_argument") \
|
2015-04-21 09:03:24 +00:00
|
|
|
T(InvalidInOperatorUse, "Cannot use 'in' operator to search for '%' in %") \
|
2015-05-05 07:57:37 +00:00
|
|
|
T(IteratorResultNotAnObject, "Iterator result % is not an object") \
|
|
|
|
T(IteratorValueNotAnObject, "Iterator value % is not an entry object") \
|
2015-04-24 10:22:00 +00:00
|
|
|
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 %.") \
|
2015-04-21 09:03:24 +00:00
|
|
|
T(NotAnIterator, "% is not an iterator") \
|
2015-05-06 07:51:56 +00:00
|
|
|
T(NotAPromise, "% is not a promise") \
|
2015-04-21 09:03:24 +00:00
|
|
|
T(NotConstructor, "% is not a constructor") \
|
|
|
|
T(NotGeneric, "% is not generic") \
|
|
|
|
T(NotIterable, "% is not iterable") \
|
2015-05-05 07:57:37 +00:00
|
|
|
T(NotTypedArray, "this is not a typed array.") \
|
2015-04-21 09:03:24 +00:00
|
|
|
T(ObjectGetterExpectingFunction, \
|
|
|
|
"Object.prototype.__defineGetter__: Expecting function") \
|
|
|
|
T(ObjectGetterCallable, "Getter must be a function: %") \
|
|
|
|
T(ObjectSetterExpectingFunction, \
|
|
|
|
"Object.prototype.__defineSetter__: Expecting function") \
|
|
|
|
T(ObjectSetterCallable, "Setter must be a function: %") \
|
2015-05-05 07:57:37 +00:00
|
|
|
T(ObserveCallbackFrozen, \
|
|
|
|
"Object.observe cannot deliver to a frozen function object") \
|
|
|
|
T(ObserveGlobalProxy, "% cannot be called on the global proxy object") \
|
|
|
|
T(ObserveInvalidAccept, \
|
|
|
|
"Third argument to Object.observe must be an array of strings.") \
|
|
|
|
T(ObserveNonFunction, "Object.% cannot deliver to non-function") \
|
|
|
|
T(ObserveNonObject, "Object.% cannot % non-object") \
|
|
|
|
T(ObserveNotifyNonNotifier, "notify called on non-notifier object") \
|
|
|
|
T(ObservePerformNonFunction, "Cannot perform non-function") \
|
|
|
|
T(ObservePerformNonString, "Invalid non-string changeType") \
|
|
|
|
T(ObserveTypeNonString, \
|
|
|
|
"Invalid changeRecord with non-string 'type' property") \
|
2015-04-24 10:22:00 +00:00
|
|
|
T(OrdinaryFunctionCalledAsConstructor, \
|
|
|
|
"Function object that's not a constructor was created with new") \
|
2015-05-06 07:51:56 +00:00
|
|
|
T(PromiseCyclic, "Chaining cycle detected for promise %") \
|
2015-04-21 09:03:24 +00:00
|
|
|
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: %") \
|
2015-05-06 07:51:56 +00:00
|
|
|
T(ProxyHandlerNonObject, "Proxy.% called with non-object as handler") \
|
2015-04-21 09:03:24 +00:00
|
|
|
T(ProxyHandlerReturned, "Proxy handler % returned % from '%' trap") \
|
|
|
|
T(ProxyHandlerTrapMissing, "Proxy handler % has no '%' trap") \
|
|
|
|
T(ProxyHandlerTrapMustBeCallable, \
|
|
|
|
"Proxy handler %0 has non-callable '%' trap") \
|
|
|
|
T(ProxyNonObjectPropNames, "Trap '%' returned non-object %") \
|
2015-05-06 07:51:56 +00:00
|
|
|
T(ProxyProtoNonObject, "Proxy.create called with no-object as prototype") \
|
2015-04-21 09:03:24 +00:00
|
|
|
T(ProxyPropNotConfigurable, \
|
|
|
|
"Proxy handler % returned non-configurable descriptor for property '%' " \
|
|
|
|
"from '%' trap") \
|
2015-05-06 07:51:56 +00:00
|
|
|
T(ProxyRepeatedPropName, "Trap '%' returned repeated property name '%'") \
|
|
|
|
T(ProxyTrapFunctionExpected, \
|
|
|
|
"Proxy.createFunction called with non-function for '%' trap") \
|
2015-04-21 09:03:24 +00:00
|
|
|
T(RedefineDisallowed, "Cannot redefine property: %") \
|
2015-04-24 10:22:00 +00:00
|
|
|
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.%.") \
|
2015-05-06 07:51:56 +00:00
|
|
|
T(ResolverNotAFunction, "Promise resolver % is not a function") \
|
2015-04-21 09:03:24 +00:00
|
|
|
T(SymbolToPrimitive, \
|
|
|
|
"Cannot convert a Symbol wrapper object to a primitive value") \
|
|
|
|
T(SymbolToNumber, "Cannot convert a Symbol value to a number") \
|
|
|
|
T(SymbolToString, "Cannot convert a Symbol value to a string") \
|
|
|
|
T(UndefinedOrNullToObject, "Cannot convert undefined or null to object") \
|
|
|
|
T(ValueAndAccessor, \
|
|
|
|
"Invalid property. A property cannot both have accessors and be " \
|
|
|
|
"writable or have a value, %") \
|
|
|
|
T(WithExpression, "% has no properties") \
|
|
|
|
T(WrongArgs, "%: Arguments list has wrong type") \
|
|
|
|
/* RangeError */ \
|
|
|
|
T(ArrayLengthOutOfRange, "defineProperty() array length out of range") \
|
2015-04-24 10:22:00 +00:00
|
|
|
T(DateRange, "Provided date is not in valid range.") \
|
|
|
|
T(ExpectedLocation, "Expected Area/Location for time zone, got %") \
|
2015-05-06 07:51:56 +00:00
|
|
|
T(InvalidArrayBufferLength, "Invalid array buffer length") \
|
|
|
|
T(InvalidArrayLength, "Invalid array length") \
|
2015-04-30 16:22:00 +00:00
|
|
|
T(InvalidCodePoint, "Invalid code point %") \
|
|
|
|
T(InvalidCountValue, "Invalid count value") \
|
2015-04-24 10:22:00 +00:00
|
|
|
T(InvalidCurrencyCode, "Invalid currency code: %") \
|
2015-05-06 07:51:56 +00:00
|
|
|
T(InvalidDataViewAccessorOffset, \
|
|
|
|
"Offset is outside the bounds of the DataView") \
|
|
|
|
T(InvalidDataViewLength, "Invalid data view length") \
|
|
|
|
T(InvalidDataViewOffset, "Start offset is outside the bounds of the buffer") \
|
2015-04-24 10:22:00 +00:00
|
|
|
T(InvalidLanguageTag, "Invalid language tag: %") \
|
2015-05-06 07:51:56 +00:00
|
|
|
T(InvalidStringLength, "Invalid string length") \
|
2015-04-30 16:22:00 +00:00
|
|
|
T(InvalidTimeValue, "Invalid time value") \
|
2015-05-06 07:51:56 +00:00
|
|
|
T(InvalidTypedArrayAlignment, "% of % should be a multiple of %") \
|
|
|
|
T(InvalidTypedArrayLength, "Invalid typed array length") \
|
|
|
|
T(InvalidTypedArrayOffset, "Start offset is too large:") \
|
2015-04-24 10:22:00 +00:00
|
|
|
T(LocaleMatcher, "Illegal value for localeMatcher:%") \
|
|
|
|
T(NormalizationForm, "The normalization form should be one of %.") \
|
2015-04-21 09:03:24 +00:00
|
|
|
T(NumberFormatRange, "% argument must be between 0 and 20") \
|
2015-04-24 10:22:00 +00:00
|
|
|
T(PropertyValueOutOfRange, "% value is out of range.") \
|
2015-04-21 09:03:24 +00:00
|
|
|
T(StackOverflow, "Maximum call stack size exceeded") \
|
|
|
|
T(ToPrecisionFormatRange, "toPrecision() argument must be between 1 and 21") \
|
2015-04-24 10:22:00 +00:00
|
|
|
T(ToRadixFormatRange, "toString() radix argument must be between 2 and 36") \
|
2015-05-06 07:51:56 +00:00
|
|
|
T(TypedArraySetNegativeOffset, "Start offset is negative") \
|
|
|
|
T(TypedArraySetSourceTooLarge, "Source is too large") \
|
2015-04-24 10:22:00 +00:00
|
|
|
T(UnsupportedTimeZone, "Unsupported time zone specified %") \
|
|
|
|
T(ValueOutOfRange, "Value % out of range for % options property %") \
|
2015-04-21 09:03:24 +00:00
|
|
|
/* SyntaxError */ \
|
|
|
|
T(ParenthesisInArgString, "Function arg string contains parenthesis") \
|
|
|
|
/* EvalError */ \
|
2015-04-24 10:22:00 +00:00
|
|
|
T(CodeGenFromStrings, "%") \
|
|
|
|
/* URIError */ \
|
|
|
|
T(URIMalformed, "URI malformed")
|
2015-04-16 07:01:20 +00:00
|
|
|
|
|
|
|
class MessageTemplate {
|
|
|
|
public:
|
|
|
|
enum Template {
|
|
|
|
#define TEMPLATE(NAME, STRING) k##NAME,
|
|
|
|
MESSAGE_TEMPLATES(TEMPLATE)
|
|
|
|
#undef TEMPLATE
|
|
|
|
kLastMessage
|
|
|
|
};
|
|
|
|
|
|
|
|
static MaybeHandle<String> FormatMessage(int template_index,
|
|
|
|
Handle<String> arg0,
|
|
|
|
Handle<String> arg1,
|
|
|
|
Handle<String> arg2);
|
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_MESSAGES_H_
|