Line data Source code
1 : // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : // The infrastructure used for (localized) message reporting in V8.
6 : //
7 : // Note: there's a big unresolved issue about ownership of the data
8 : // structures used by this framework.
9 :
10 : #ifndef V8_MESSAGES_H_
11 : #define V8_MESSAGES_H_
12 :
13 : #include <memory>
14 :
15 : #include "src/handles.h"
16 : #include "src/list.h"
17 :
18 : namespace v8 {
19 : namespace internal {
20 :
21 : // Forward declarations.
22 : class AbstractCode;
23 : class FrameArray;
24 : class JSMessageObject;
25 : class LookupIterator;
26 : class SharedFunctionInfo;
27 : class SourceInfo;
28 :
29 : class MessageLocation {
30 : public:
31 : MessageLocation(Handle<Script> script, int start_pos, int end_pos);
32 : MessageLocation(Handle<Script> script, int start_pos, int end_pos,
33 : Handle<SharedFunctionInfo> shared);
34 : MessageLocation();
35 :
36 : Handle<Script> script() const { return script_; }
37 : int start_pos() const { return start_pos_; }
38 : int end_pos() const { return end_pos_; }
39 : Handle<SharedFunctionInfo> shared() const { return shared_; }
40 :
41 : private:
42 : Handle<Script> script_;
43 : int start_pos_;
44 : int end_pos_;
45 : Handle<SharedFunctionInfo> shared_;
46 : };
47 :
48 : class StackFrameBase {
49 : public:
50 272907 : virtual ~StackFrameBase() {}
51 :
52 : virtual Handle<Object> GetReceiver() const = 0;
53 : virtual Handle<Object> GetFunction() const = 0;
54 :
55 : virtual Handle<Object> GetFileName() = 0;
56 : virtual Handle<Object> GetFunctionName() = 0;
57 : virtual Handle<Object> GetScriptNameOrSourceUrl() = 0;
58 : virtual Handle<Object> GetMethodName() = 0;
59 : virtual Handle<Object> GetTypeName() = 0;
60 : virtual Handle<Object> GetEvalOrigin();
61 :
62 : virtual int GetPosition() const = 0;
63 : // Return 1-based line number, including line offset.
64 : virtual int GetLineNumber() = 0;
65 : // Return 1-based column number, including column offset if first line.
66 : virtual int GetColumnNumber() = 0;
67 :
68 : virtual bool IsNative() = 0;
69 : virtual bool IsToplevel() = 0;
70 : virtual bool IsEval();
71 : virtual bool IsConstructor() = 0;
72 : virtual bool IsStrict() const = 0;
73 :
74 : virtual MaybeHandle<String> ToString() = 0;
75 :
76 : protected:
77 272907 : StackFrameBase() {}
78 0 : explicit StackFrameBase(Isolate* isolate) : isolate_(isolate) {}
79 : Isolate* isolate_;
80 :
81 : private:
82 : virtual bool HasScript() const = 0;
83 : virtual Handle<Script> GetScript() const = 0;
84 : };
85 :
86 : class JSStackFrame : public StackFrameBase {
87 : public:
88 : JSStackFrame(Isolate* isolate, Handle<Object> receiver,
89 : Handle<JSFunction> function, Handle<AbstractCode> code,
90 : int offset);
91 90969 : virtual ~JSStackFrame() {}
92 :
93 345 : Handle<Object> GetReceiver() const override { return receiver_; }
94 : Handle<Object> GetFunction() const override;
95 :
96 : Handle<Object> GetFileName() override;
97 : Handle<Object> GetFunctionName() override;
98 : Handle<Object> GetScriptNameOrSourceUrl() override;
99 : Handle<Object> GetMethodName() override;
100 : Handle<Object> GetTypeName() override;
101 :
102 : int GetPosition() const override;
103 : int GetLineNumber() override;
104 : int GetColumnNumber() override;
105 :
106 : bool IsNative() override;
107 : bool IsToplevel() override;
108 : bool IsConstructor() override;
109 1155 : bool IsStrict() const override { return is_strict_; }
110 :
111 : MaybeHandle<String> ToString() override;
112 :
113 : private:
114 : JSStackFrame();
115 : void FromFrameArray(Isolate* isolate, Handle<FrameArray> array, int frame_ix);
116 :
117 : bool HasScript() const override;
118 : Handle<Script> GetScript() const override;
119 :
120 : Handle<Object> receiver_;
121 : Handle<JSFunction> function_;
122 : Handle<AbstractCode> code_;
123 : int offset_;
124 :
125 : bool force_constructor_;
126 : bool is_strict_;
127 :
128 : friend class FrameArrayIterator;
129 : };
130 :
131 : class WasmStackFrame : public StackFrameBase {
132 : public:
133 181938 : virtual ~WasmStackFrame() {}
134 :
135 0 : Handle<Object> GetReceiver() const override { return wasm_instance_; }
136 : Handle<Object> GetFunction() const override;
137 :
138 240 : Handle<Object> GetFileName() override { return Null(); }
139 : Handle<Object> GetFunctionName() override;
140 0 : Handle<Object> GetScriptNameOrSourceUrl() override { return Null(); }
141 0 : Handle<Object> GetMethodName() override { return Null(); }
142 0 : Handle<Object> GetTypeName() override { return Null(); }
143 :
144 : int GetPosition() const override;
145 180 : int GetLineNumber() override { return wasm_func_index_; }
146 0 : int GetColumnNumber() override { return -1; }
147 :
148 162 : bool IsNative() override { return false; }
149 0 : bool IsToplevel() override { return false; }
150 0 : bool IsConstructor() override { return false; }
151 390 : bool IsStrict() const override { return false; }
152 : bool IsInterpreted() const { return code_.is_null(); }
153 :
154 : MaybeHandle<String> ToString() override;
155 :
156 : protected:
157 : Handle<Object> Null() const;
158 :
159 : bool HasScript() const override;
160 : Handle<Script> GetScript() const override;
161 :
162 : // TODO(wasm): Use proper typing.
163 : Handle<Object> wasm_instance_;
164 : uint32_t wasm_func_index_;
165 : Handle<AbstractCode> code_; // null handle for interpreted frames.
166 : int offset_;
167 :
168 : private:
169 : WasmStackFrame();
170 : void FromFrameArray(Isolate* isolate, Handle<FrameArray> array, int frame_ix);
171 :
172 : friend class FrameArrayIterator;
173 : friend class AsmJsWasmStackFrame;
174 : };
175 :
176 : class AsmJsWasmStackFrame : public WasmStackFrame {
177 : public:
178 90969 : virtual ~AsmJsWasmStackFrame() {}
179 :
180 : Handle<Object> GetReceiver() const override;
181 : Handle<Object> GetFunction() const override;
182 :
183 : Handle<Object> GetFileName() override;
184 : Handle<Object> GetScriptNameOrSourceUrl() override;
185 :
186 : int GetPosition() const override;
187 : int GetLineNumber() override;
188 : int GetColumnNumber() override;
189 :
190 : MaybeHandle<String> ToString() override;
191 :
192 : private:
193 : friend class FrameArrayIterator;
194 : AsmJsWasmStackFrame();
195 : void FromFrameArray(Isolate* isolate, Handle<FrameArray> array, int frame_ix);
196 :
197 : bool is_at_number_conversion_;
198 : };
199 :
200 : class FrameArrayIterator {
201 : public:
202 : FrameArrayIterator(Isolate* isolate, Handle<FrameArray> array,
203 : int frame_ix = 0);
204 :
205 : StackFrameBase* Frame();
206 :
207 : bool HasNext() const;
208 : void Next();
209 :
210 : private:
211 : Isolate* isolate_;
212 :
213 : Handle<FrameArray> array_;
214 : int next_frame_ix_;
215 :
216 : WasmStackFrame wasm_frame_;
217 : AsmJsWasmStackFrame asm_wasm_frame_;
218 : JSStackFrame js_frame_;
219 : };
220 :
221 : // Determines how stack trace collection skips frames.
222 : enum FrameSkipMode {
223 : // Unconditionally skips the first frame. Used e.g. when the Error constructor
224 : // is called, in which case the first frame is always a BUILTIN_EXIT frame.
225 : SKIP_FIRST,
226 : // Skip all frames until a specified caller function is seen.
227 : SKIP_UNTIL_SEEN,
228 : SKIP_NONE,
229 : };
230 :
231 : class ErrorUtils : public AllStatic {
232 : public:
233 : static MaybeHandle<Object> Construct(
234 : Isolate* isolate, Handle<JSFunction> target, Handle<Object> new_target,
235 : Handle<Object> message, FrameSkipMode mode, Handle<Object> caller,
236 : bool suppress_detailed_trace);
237 :
238 : static MaybeHandle<String> ToString(Isolate* isolate, Handle<Object> recv);
239 :
240 : static MaybeHandle<Object> MakeGenericError(
241 : Isolate* isolate, Handle<JSFunction> constructor, int template_index,
242 : Handle<Object> arg0, Handle<Object> arg1, Handle<Object> arg2,
243 : FrameSkipMode mode);
244 :
245 : // Formats a textual stack trace from the given structured stack trace.
246 : // Note that this can call arbitrary JS code through Error.prepareStackTrace.
247 : static MaybeHandle<Object> FormatStackTrace(Isolate* isolate,
248 : Handle<JSObject> error,
249 : Handle<Object> stack_trace);
250 : };
251 :
252 : #define MESSAGE_TEMPLATES(T) \
253 : /* Error */ \
254 : T(None, "") \
255 : T(CyclicProto, "Cyclic __proto__ value") \
256 : T(Debugger, "Debugger: %") \
257 : T(DebuggerLoading, "Error loading debugger") \
258 : T(DefaultOptionsMissing, "Internal % error. Default options are missing.") \
259 : T(UncaughtException, "Uncaught %") \
260 : T(Unsupported, "Not supported") \
261 : T(WrongServiceType, "Internal error, wrong service type: %") \
262 : T(WrongValueType, "Internal error. Wrong value type.") \
263 : /* TypeError */ \
264 : T(ApplyNonFunction, \
265 : "Function.prototype.apply was called on %, which is a % and not a " \
266 : "function") \
267 : T(ArrayBufferTooShort, \
268 : "Derived ArrayBuffer constructor created a buffer which was too small") \
269 : T(ArrayBufferSpeciesThis, \
270 : "ArrayBuffer subclass returned this from species constructor") \
271 : T(ArrayFunctionsOnFrozen, "Cannot modify frozen array elements") \
272 : T(ArrayFunctionsOnSealed, "Cannot add/remove sealed array elements") \
273 : T(AtomicsWaitNotAllowed, "Atomics.wait cannot be called in this context") \
274 : T(CalledNonCallable, "% is not a function") \
275 : T(CalledOnNonObject, "% called on non-object") \
276 : T(CalledOnNullOrUndefined, "% called on null or undefined") \
277 : T(CallSiteExpectsFunction, \
278 : "CallSite expects wasm object as first or function as second argument, " \
279 : "got <%, %>") \
280 : T(CallSiteMethod, "CallSite method % expects CallSite as receiver") \
281 : T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \
282 : T(CannotPreventExt, "Cannot prevent extensions") \
283 : T(CannotFreeze, "Cannot freeze") \
284 : T(CannotFreezeArrayBufferView, \
285 : "Cannot freeze array buffer views with elements") \
286 : T(CannotSeal, "Cannot seal") \
287 : T(CircularStructure, "Converting circular structure to JSON") \
288 : T(ConstructAbstractClass, "Abstract class % not directly constructable") \
289 : T(ConstAssign, "Assignment to constant variable.") \
290 : T(ConstructorNonCallable, \
291 : "Class constructor % cannot be invoked without 'new'") \
292 : T(ConstructorNotFunction, "Constructor % requires 'new'") \
293 : T(ConstructorNotReceiver, "The .constructor property is not an object") \
294 : T(CurrencyCode, "Currency code is required with currency style.") \
295 : T(CyclicModuleDependency, "Detected cycle while resolving name '%'") \
296 : T(DataViewNotArrayBuffer, \
297 : "First argument to DataView constructor must be an ArrayBuffer") \
298 : T(DateType, "this is not a Date object.") \
299 : T(DebuggerFrame, "Debugger: Invalid frame index.") \
300 : T(DebuggerType, "Debugger: Parameters have wrong types.") \
301 : T(DeclarationMissingInitializer, "Missing initializer in % declaration") \
302 : T(DefineDisallowed, "Cannot define property %, object is not extensible") \
303 : T(DetachedOperation, "Cannot perform % on a detached ArrayBuffer") \
304 : T(DuplicateTemplateProperty, "Object template has duplicate property '%'") \
305 : T(ExtendsValueNotConstructor, \
306 : "Class extends value % is not a constructor or null") \
307 : T(FirstArgumentNotRegExp, \
308 : "First argument to % must not be a regular expression") \
309 : T(FunctionBind, "Bind must be called on a function") \
310 : T(GeneratorRunning, "Generator is already running") \
311 : T(IllegalInvocation, "Illegal invocation") \
312 : T(ImmutablePrototypeSet, \
313 : "Immutable prototype object '%' cannot have their prototype set") \
314 : T(ImportCallNotNewExpression, "Cannot use new with import") \
315 : T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %") \
316 : T(InstanceofNonobjectProto, \
317 : "Function has non-object prototype '%' in instanceof check") \
318 : T(InvalidArgument, "invalid_argument") \
319 : T(InvalidInOperatorUse, "Cannot use 'in' operator to search for '%' in %") \
320 : T(InvalidRegExpExecResult, \
321 : "RegExp exec method returned something other than an Object or null") \
322 : T(IteratorResultNotAnObject, "Iterator result % is not an object") \
323 : T(IteratorValueNotAnObject, "Iterator value % is not an entry object") \
324 : T(LanguageID, "Language ID should be string or object.") \
325 : T(MethodCalledOnWrongObject, \
326 : "Method % called on a non-object or on a wrong type of object.") \
327 : T(MethodInvokedOnNullOrUndefined, \
328 : "Method invoked on undefined or null value.") \
329 : T(MethodInvokedOnWrongType, "Method invoked on an object that is not %.") \
330 : T(NoAccess, "no access") \
331 : T(NonCallableInInstanceOfCheck, \
332 : "Right-hand side of 'instanceof' is not callable") \
333 : T(NonCoercible, "Cannot match against 'undefined' or 'null'.") \
334 : T(NonExtensibleProto, "% is not extensible") \
335 : T(NonObjectInInstanceOfCheck, \
336 : "Right-hand side of 'instanceof' is not an object") \
337 : T(NonObjectPropertyLoad, "Cannot read property '%' of %") \
338 : T(NonObjectPropertyStore, "Cannot set property '%' of %") \
339 : T(NoSetterInCallback, "Cannot set property % of % which has only a getter") \
340 : T(NotAnIterator, "% is not an iterator") \
341 : T(NotAPromise, "% is not a promise") \
342 : T(NotConstructor, "% is not a constructor") \
343 : T(NotDateObject, "this is not a Date object.") \
344 : T(NotGeneric, "% requires that 'this' be a %") \
345 : T(NotIterable, "% is not iterable") \
346 : T(NotPropertyName, "% is not a valid property name") \
347 : T(NotTypedArray, "this is not a typed array.") \
348 : T(NotSuperConstructor, "Super constructor % of % is not a constructor") \
349 : T(NotSuperConstructorAnonymousClass, \
350 : "Super constructor % of anonymous class is not a constructor") \
351 : T(NotIntegerSharedTypedArray, "% is not an integer shared typed array.") \
352 : T(NotInt32SharedTypedArray, "% is not an int32 shared typed array.") \
353 : T(ObjectGetterExpectingFunction, \
354 : "Object.prototype.__defineGetter__: Expecting function") \
355 : T(ObjectGetterCallable, "Getter must be a function: %") \
356 : T(ObjectNotExtensible, "Cannot add property %, object is not extensible") \
357 : T(ObjectSetterExpectingFunction, \
358 : "Object.prototype.__defineSetter__: Expecting function") \
359 : T(ObjectSetterCallable, "Setter must be a function: %") \
360 : T(OrdinaryFunctionCalledAsConstructor, \
361 : "Function object that's not a constructor was created with new") \
362 : T(PromiseCyclic, "Chaining cycle detected for promise %") \
363 : T(PromiseExecutorAlreadyInvoked, \
364 : "Promise executor has already been invoked with non-undefined arguments") \
365 : T(PromiseNonCallable, "Promise resolve or reject function is not callable") \
366 : T(PropertyDescObject, "Property description must be an object: %") \
367 : T(PropertyNotFunction, \
368 : "'%' returned for property '%' of object '%' is not a function") \
369 : T(ProtoObjectOrNull, "Object prototype may only be an Object or null: %") \
370 : T(PrototypeParentNotAnObject, \
371 : "Class extends value does not have valid prototype property %") \
372 : T(ProxyConstructNonObject, \
373 : "'construct' on proxy: trap returned non-object ('%')") \
374 : T(ProxyDefinePropertyNonConfigurable, \
375 : "'defineProperty' on proxy: trap returned truish for defining " \
376 : "non-configurable property '%' which is either non-existant or " \
377 : "configurable in the proxy target") \
378 : T(ProxyDefinePropertyNonExtensible, \
379 : "'defineProperty' on proxy: trap returned truish for adding property '%' " \
380 : " to the non-extensible proxy target") \
381 : T(ProxyDefinePropertyIncompatible, \
382 : "'defineProperty' on proxy: trap returned truish for adding property '%' " \
383 : " that is incompatible with the existing property in the proxy target") \
384 : T(ProxyDeletePropertyNonConfigurable, \
385 : "'deleteProperty' on proxy: trap returned truish for property '%' which " \
386 : "is non-configurable in the proxy target") \
387 : T(ProxyGetNonConfigurableData, \
388 : "'get' on proxy: property '%' is a read-only and " \
389 : "non-configurable data property on the proxy target but the proxy " \
390 : "did not return its actual value (expected '%' but got '%')") \
391 : T(ProxyGetNonConfigurableAccessor, \
392 : "'get' on proxy: property '%' is a non-configurable accessor " \
393 : "property on the proxy target and does not have a getter function, but " \
394 : "the trap did not return 'undefined' (got '%')") \
395 : T(ProxyGetOwnPropertyDescriptorIncompatible, \
396 : "'getOwnPropertyDescriptor' on proxy: trap returned descriptor for " \
397 : "property '%' that is incompatible with the existing property in the " \
398 : "proxy target") \
399 : T(ProxyGetOwnPropertyDescriptorInvalid, \
400 : "'getOwnPropertyDescriptor' on proxy: trap returned neither object nor " \
401 : "undefined for property '%'") \
402 : T(ProxyGetOwnPropertyDescriptorNonConfigurable, \
403 : "'getOwnPropertyDescriptor' on proxy: trap reported non-configurability " \
404 : "for property '%' which is either non-existant or configurable in the " \
405 : "proxy target") \
406 : T(ProxyGetOwnPropertyDescriptorNonExtensible, \
407 : "'getOwnPropertyDescriptor' on proxy: trap returned undefined for " \
408 : "property '%' which exists in the non-extensible proxy target") \
409 : T(ProxyGetOwnPropertyDescriptorUndefined, \
410 : "'getOwnPropertyDescriptor' on proxy: trap returned undefined for " \
411 : "property '%' which is non-configurable in the proxy target") \
412 : T(ProxyGetPrototypeOfInvalid, \
413 : "'getPrototypeOf' on proxy: trap returned neither object nor null") \
414 : T(ProxyGetPrototypeOfNonExtensible, \
415 : "'getPrototypeOf' on proxy: proxy target is non-extensible but the " \
416 : "trap did not return its actual prototype") \
417 : T(ProxyHandlerOrTargetRevoked, \
418 : "Cannot create proxy with a revoked proxy as target or handler") \
419 : T(ProxyHasNonConfigurable, \
420 : "'has' on proxy: trap returned falsish for property '%' which exists in " \
421 : "the proxy target as non-configurable") \
422 : T(ProxyHasNonExtensible, \
423 : "'has' on proxy: trap returned falsish for property '%' but the proxy " \
424 : "target is not extensible") \
425 : T(ProxyIsExtensibleInconsistent, \
426 : "'isExtensible' on proxy: trap result does not reflect extensibility of " \
427 : "proxy target (which is '%')") \
428 : T(ProxyNonObject, \
429 : "Cannot create proxy with a non-object as target or handler") \
430 : T(ProxyOwnKeysMissing, \
431 : "'ownKeys' on proxy: trap result did not include '%'") \
432 : T(ProxyOwnKeysNonExtensible, \
433 : "'ownKeys' on proxy: trap returned extra keys but proxy target is " \
434 : "non-extensible") \
435 : T(ProxyPreventExtensionsExtensible, \
436 : "'preventExtensions' on proxy: trap returned truish but the proxy target " \
437 : "is extensible") \
438 : T(ProxyPrivate, "Cannot pass private property name to proxy trap") \
439 : T(ProxyRevoked, "Cannot perform '%' on a proxy that has been revoked") \
440 : T(ProxySetFrozenData, \
441 : "'set' on proxy: trap returned truish for property '%' which exists in " \
442 : "the proxy target as a non-configurable and non-writable data property " \
443 : "with a different value") \
444 : T(ProxySetFrozenAccessor, \
445 : "'set' on proxy: trap returned truish for property '%' which exists in " \
446 : "the proxy target as a non-configurable and non-writable accessor " \
447 : "property without a setter") \
448 : T(ProxySetPrototypeOfNonExtensible, \
449 : "'setPrototypeOf' on proxy: trap returned truish for setting a new " \
450 : "prototype on the non-extensible proxy target") \
451 : T(ProxyTrapReturnedFalsish, "'%' on proxy: trap returned falsish") \
452 : T(ProxyTrapReturnedFalsishFor, \
453 : "'%' on proxy: trap returned falsish for property '%'") \
454 : T(RedefineDisallowed, "Cannot redefine property: %") \
455 : T(RedefineExternalArray, \
456 : "Cannot redefine a property of an object with external array elements") \
457 : T(ReduceNoInitial, "Reduce of empty array with no initial value") \
458 : T(RegExpFlags, \
459 : "Cannot supply flags when constructing one RegExp from another") \
460 : T(RegExpInvalidReplaceString, "Invalid replacement string: '%'") \
461 : T(RegExpNonObject, "% getter called on non-object %") \
462 : T(RegExpNonRegExp, "% getter called on non-RegExp object") \
463 : T(ResolverNotAFunction, "Promise resolver % is not a function") \
464 : T(RestrictedFunctionProperties, \
465 : "'caller' and 'arguments' are restricted function properties and cannot " \
466 : "be accessed in this context.") \
467 : T(ReturnMethodNotCallable, "The iterator's 'return' method is not callable") \
468 : T(SharedArrayBufferTooShort, \
469 : "Derived SharedArrayBuffer constructor created a buffer which was too " \
470 : "small") \
471 : T(SharedArrayBufferSpeciesThis, \
472 : "SharedArrayBuffer subclass returned this from species constructor") \
473 : T(StaticPrototype, "Classes may not have static property named prototype") \
474 : T(StrictCannotAssign, "Cannot assign to read only '%' in strict mode") \
475 : T(StrictDeleteProperty, "Cannot delete property '%' of %") \
476 : T(StrictPoisonPill, \
477 : "'caller', 'callee', and 'arguments' properties may not be accessed on " \
478 : "strict mode functions or the arguments objects for calls to them") \
479 : T(StrictReadOnlyProperty, \
480 : "Cannot assign to read only property '%' of % '%'") \
481 : T(StrictCannotCreateProperty, "Cannot create property '%' on % '%'") \
482 : T(SymbolIteratorInvalid, \
483 : "Result of the Symbol.iterator method is not an object") \
484 : T(SymbolAsyncIteratorInvalid, \
485 : "Result of the Symbol.asyncIterator method is not an object") \
486 : T(SymbolKeyFor, "% is not a symbol") \
487 : T(SymbolToNumber, "Cannot convert a Symbol value to a number") \
488 : T(SymbolToString, "Cannot convert a Symbol value to a string") \
489 : T(ThrowMethodMissing, "The iterator does not provide a 'throw' method.") \
490 : T(UndefinedOrNullToObject, "Cannot convert undefined or null to object") \
491 : T(ValueAndAccessor, \
492 : "Invalid property descriptor. Cannot both specify accessors and a value " \
493 : "or writable attribute, %") \
494 : T(VarRedeclaration, "Identifier '%' has already been declared") \
495 : T(WrongArgs, "%: Arguments list has wrong type") \
496 : /* ReferenceError */ \
497 : T(NotDefined, "% is not defined") \
498 : T(SuperAlreadyCalled, "Super constructor may only be called once") \
499 : T(UnsupportedSuper, "Unsupported reference to 'super'") \
500 : /* RangeError */ \
501 : T(DateRange, "Provided date is not in valid range.") \
502 : T(ExpectedTimezoneID, \
503 : "Expected Area/Location(/Location)* for time zone, got %") \
504 : T(ExpectedLocation, \
505 : "Expected letters optionally connected with underscores or hyphens for " \
506 : "a location, got %") \
507 : T(InvalidArrayBufferLength, "Invalid array buffer length") \
508 : T(ArrayBufferAllocationFailed, "Array buffer allocation failed") \
509 : T(InvalidArrayLength, "Invalid array length") \
510 : T(InvalidAtomicAccessIndex, "Invalid atomic access index") \
511 : T(InvalidCodePoint, "Invalid code point %") \
512 : T(InvalidCountValue, "Invalid count value") \
513 : T(InvalidCurrencyCode, "Invalid currency code: %") \
514 : T(InvalidDataViewAccessorOffset, \
515 : "Offset is outside the bounds of the DataView") \
516 : T(InvalidDataViewLength, "Invalid DataView length %") \
517 : T(InvalidOffset, "Start offset % is outside the bounds of the buffer") \
518 : T(InvalidHint, "Invalid hint: %") \
519 : T(InvalidLanguageTag, "Invalid language tag: %") \
520 : T(InvalidWeakMapKey, "Invalid value used as weak map key") \
521 : T(InvalidWeakSetValue, "Invalid value used in weak set") \
522 : T(InvalidStringLength, "Invalid string length") \
523 : T(InvalidTimeValue, "Invalid time value") \
524 : T(InvalidTypedArrayAlignment, "% of % should be a multiple of %") \
525 : T(InvalidTypedArrayIndex, "Invalid typed array index") \
526 : T(InvalidTypedArrayLength, "Invalid typed array length: %") \
527 : T(LetInLexicalBinding, "let is disallowed as a lexically bound name") \
528 : T(LocaleMatcher, "Illegal value for localeMatcher:%") \
529 : T(NormalizationForm, "The normalization form should be one of %.") \
530 : T(NumberFormatRange, "% argument must be between 0 and 20") \
531 : T(PropertyValueOutOfRange, "% value is out of range.") \
532 : T(StackOverflow, "Maximum call stack size exceeded") \
533 : T(ToPrecisionFormatRange, "toPrecision() argument must be between 1 and 21") \
534 : T(ToRadixFormatRange, "toString() radix argument must be between 2 and 36") \
535 : T(TypedArraySetNegativeOffset, "Start offset is negative") \
536 : T(TypedArraySetSourceTooLarge, "Source is too large") \
537 : T(UnsupportedTimeZone, "Unsupported time zone specified %") \
538 : T(ValueOutOfRange, "Value % out of range for % options property %") \
539 : /* SyntaxError */ \
540 : T(AmbiguousExport, \
541 : "The requested module contains conflicting star exports for name '%'") \
542 : T(BadGetterArity, "Getter must not have any formal parameters.") \
543 : T(BadSetterArity, "Setter must have exactly one formal parameter.") \
544 : T(ConstructorIsAccessor, "Class constructor may not be an accessor") \
545 : T(ConstructorIsGenerator, "Class constructor may not be a generator") \
546 : T(ConstructorIsAsync, "Class constructor may not be an async method") \
547 : T(ClassConstructorReturnedNonObject, \
548 : "Class constructors may only return object or undefined") \
549 : T(DerivedConstructorReturnedNonObject, \
550 : "Derived constructors may only return object or undefined") \
551 : T(DuplicateConstructor, "A class may only have one constructor") \
552 : T(DuplicateExport, "Duplicate export of '%'") \
553 : T(DuplicateProto, \
554 : "Duplicate __proto__ fields are not allowed in object literals") \
555 : T(ForInOfLoopInitializer, \
556 : "% loop variable declaration may not have an initializer.") \
557 : T(ForInOfLoopMultiBindings, \
558 : "Invalid left-hand side in % loop: Must have a single binding.") \
559 : T(GeneratorInLegacyContext, \
560 : "Generator declarations are not allowed in legacy contexts.") \
561 : T(IllegalBreak, "Illegal break statement") \
562 : T(NoIterationStatement, \
563 : "Illegal continue statement: no surrounding iteration statement") \
564 : T(IllegalContinue, \
565 : "Illegal continue statement: '%' does not denote an iteration statement") \
566 : T(IllegalLanguageModeDirective, \
567 : "Illegal '%' directive in function with non-simple parameter list") \
568 : T(IllegalReturn, "Illegal return statement") \
569 : T(InvalidEscapedReservedWord, "Keyword must not contain escaped characters") \
570 : T(InvalidEscapedMetaProperty, "'%' must not contain escaped characters") \
571 : T(InvalidLhsInAssignment, "Invalid left-hand side in assignment") \
572 : T(InvalidCoverInitializedName, "Invalid shorthand property initializer") \
573 : T(InvalidDestructuringTarget, "Invalid destructuring assignment target") \
574 : T(InvalidLhsInFor, "Invalid left-hand side in for-loop") \
575 : T(InvalidLhsInPostfixOp, \
576 : "Invalid left-hand side expression in postfix operation") \
577 : T(InvalidLhsInPrefixOp, \
578 : "Invalid left-hand side expression in prefix operation") \
579 : T(InvalidRegExpFlags, "Invalid flags supplied to RegExp constructor '%'") \
580 : T(InvalidOrUnexpectedToken, "Invalid or unexpected token") \
581 : T(JsonParseUnexpectedEOS, "Unexpected end of JSON input") \
582 : T(JsonParseUnexpectedToken, "Unexpected token % in JSON at position %") \
583 : T(JsonParseUnexpectedTokenNumber, "Unexpected number in JSON at position %") \
584 : T(JsonParseUnexpectedTokenString, "Unexpected string in JSON at position %") \
585 : T(LabelRedeclaration, "Label '%' has already been declared") \
586 : T(LabelledFunctionDeclaration, \
587 : "Labelled function declaration not allowed as the body of a control flow " \
588 : "structure") \
589 : T(MalformedArrowFunParamList, "Malformed arrow function parameter list") \
590 : T(MalformedRegExp, "Invalid regular expression: /%/: %") \
591 : T(MalformedRegExpFlags, "Invalid regular expression flags") \
592 : T(ModuleExportUndefined, "Export '%' is not defined in module") \
593 : T(MultipleDefaultsInSwitch, \
594 : "More than one default clause in switch statement") \
595 : T(NewlineAfterThrow, "Illegal newline after throw") \
596 : T(NoCatchOrFinally, "Missing catch or finally after try") \
597 : T(NotIsvar, "builtin %%IS_VAR: not a variable") \
598 : T(ParamAfterRest, "Rest parameter must be last formal parameter") \
599 : T(PushPastSafeLength, \
600 : "Pushing % elements on an array-like of length % " \
601 : "is disallowed, as the total surpasses 2**53-1") \
602 : T(ElementAfterRest, "Rest element must be last element") \
603 : T(BadSetterRestParameter, \
604 : "Setter function argument must not be a rest parameter") \
605 : T(ParamDupe, "Duplicate parameter name not allowed in this context") \
606 : T(ParenthesisInArgString, "Function arg string contains parenthesis") \
607 : T(ArgStringTerminatesParametersEarly, \
608 : "Arg string terminates parameters early") \
609 : T(UnexpectedEndOfArgString, "Unexpected end of arg string") \
610 : T(RuntimeWrongNumArgs, "Runtime function given wrong number of arguments") \
611 : T(SuperNotCalled, \
612 : "Must call super constructor in derived class before accessing 'this' or " \
613 : "returning from derived constructor") \
614 : T(SingleFunctionLiteral, "Single function literal required") \
615 : T(SloppyFunction, \
616 : "In non-strict mode code, functions can only be declared at top level, " \
617 : "inside a block, or as the body of an if statement.") \
618 : T(SpeciesNotConstructor, \
619 : "object.constructor[Symbol.species] is not a constructor") \
620 : T(StrictDelete, "Delete of an unqualified identifier in strict mode.") \
621 : T(StrictEvalArguments, "Unexpected eval or arguments in strict mode") \
622 : T(StrictFunction, \
623 : "In strict mode code, functions can only be declared at top level or " \
624 : "inside a block.") \
625 : T(StrictOctalLiteral, "Octal literals are not allowed in strict mode.") \
626 : T(StrictDecimalWithLeadingZero, \
627 : "Decimals with leading zeros are not allowed in strict mode.") \
628 : T(StrictOctalEscape, \
629 : "Octal escape sequences are not allowed in strict mode.") \
630 : T(StrictWith, "Strict mode code may not include a with statement") \
631 : T(TemplateOctalLiteral, \
632 : "Octal escape sequences are not allowed in template strings.") \
633 : T(ThisFormalParameter, "'this' is not a valid formal parameter name") \
634 : T(AwaitBindingIdentifier, \
635 : "'await' is not a valid identifier name in an async function") \
636 : T(AwaitExpressionFormalParameter, \
637 : "Illegal await-expression in formal parameters of async function") \
638 : T(TooManyArguments, \
639 : "Too many arguments in function call (only 65535 allowed)") \
640 : T(TooManyParameters, \
641 : "Too many parameters in function definition (only 65535 allowed)") \
642 : T(TooManySpreads, \
643 : "Literal containing too many nested spreads (up to 65534 allowed)") \
644 : T(TooManyVariables, "Too many variables declared (only 4194303 allowed)") \
645 : T(TypedArrayTooShort, \
646 : "Derived TypedArray constructor created an array which was too small") \
647 : T(UnexpectedEOS, "Unexpected end of input") \
648 : T(UnexpectedFunctionSent, \
649 : "function.sent expression is not allowed outside a generator") \
650 : T(UnexpectedReserved, "Unexpected reserved word") \
651 : T(UnexpectedStrictReserved, "Unexpected strict mode reserved word") \
652 : T(UnexpectedSuper, "'super' keyword unexpected here") \
653 : T(UnexpectedNewTarget, "new.target expression is not allowed here") \
654 : T(UnexpectedTemplateString, "Unexpected template string") \
655 : T(UnexpectedToken, "Unexpected token %") \
656 : T(UnexpectedTokenIdentifier, "Unexpected identifier") \
657 : T(UnexpectedTokenNumber, "Unexpected number") \
658 : T(UnexpectedTokenString, "Unexpected string") \
659 : T(UnexpectedTokenRegExp, "Unexpected regular expression") \
660 : T(UnexpectedLexicalDeclaration, \
661 : "Lexical declaration cannot appear in a single-statement context") \
662 : T(UnknownLabel, "Undefined label '%'") \
663 : T(UnresolvableExport, \
664 : "The requested module does not provide an export named '%'") \
665 : T(UnterminatedArgList, "missing ) after argument list") \
666 : T(UnterminatedRegExp, "Invalid regular expression: missing /") \
667 : T(UnterminatedTemplate, "Unterminated template literal") \
668 : T(UnterminatedTemplateExpr, "Missing } in template expression") \
669 : T(FoundNonCallableHasInstance, "Found non-callable @@hasInstance") \
670 : T(InvalidHexEscapeSequence, "Invalid hexadecimal escape sequence") \
671 : T(InvalidUnicodeEscapeSequence, "Invalid Unicode escape sequence") \
672 : T(UndefinedUnicodeCodePoint, "Undefined Unicode code-point") \
673 : T(YieldInParameter, "Yield expression not allowed in formal parameter") \
674 : /* EvalError */ \
675 : T(CodeGenFromStrings, "%") \
676 : T(NoSideEffectDebugEvaluate, "Possible side-effect in debug-evaluate") \
677 : /* URIError */ \
678 : T(URIMalformed, "URI malformed") \
679 : /* Wasm errors (currently Error) */ \
680 : T(WasmTrapUnreachable, "unreachable") \
681 : T(WasmTrapMemOutOfBounds, "memory access out of bounds") \
682 : T(WasmTrapDivByZero, "divide by zero") \
683 : T(WasmTrapDivUnrepresentable, "divide result unrepresentable") \
684 : T(WasmTrapRemByZero, "remainder by zero") \
685 : T(WasmTrapFloatUnrepresentable, "integer result unrepresentable") \
686 : T(WasmTrapFuncInvalid, "invalid function") \
687 : T(WasmTrapFuncSigMismatch, "function signature mismatch") \
688 : T(WasmTrapInvalidIndex, "invalid index into function table") \
689 : T(WasmTrapTypeError, "invalid type") \
690 : /* Asm.js validation related */ \
691 : T(AsmJsInvalid, "Invalid asm.js: %") \
692 : T(AsmJsCompiled, "Converted asm.js to WebAssembly: %") \
693 : T(AsmJsInstantiated, "Instantiated asm.js: %") \
694 : /* DataCloneError messages */ \
695 : T(DataCloneError, "% could not be cloned.") \
696 : T(DataCloneErrorOutOfMemory, "Data cannot be cloned, out of memory.") \
697 : T(DataCloneErrorNeuteredArrayBuffer, \
698 : "An ArrayBuffer is neutered and could not be cloned.") \
699 : T(DataCloneErrorSharedArrayBufferTransferred, \
700 : "A SharedArrayBuffer could not be cloned. SharedArrayBuffer must not be " \
701 : "transferred.") \
702 : T(DataCloneDeserializationError, "Unable to deserialize cloned data.") \
703 : T(DataCloneDeserializationVersionError, \
704 : "Unable to deserialize cloned data due to invalid or unsupported " \
705 : "version.")
706 :
707 : class MessageTemplate {
708 : public:
709 : enum Template {
710 : #define TEMPLATE(NAME, STRING) k##NAME,
711 : MESSAGE_TEMPLATES(TEMPLATE)
712 : #undef TEMPLATE
713 : kLastMessage
714 : };
715 :
716 : static const char* TemplateString(int template_index);
717 :
718 : static MaybeHandle<String> FormatMessage(int template_index,
719 : Handle<String> arg0,
720 : Handle<String> arg1,
721 : Handle<String> arg2);
722 :
723 : static Handle<String> FormatMessage(Isolate* isolate, int template_index,
724 : Handle<Object> arg);
725 : };
726 :
727 :
728 : // A message handler is a convenience interface for accessing the list
729 : // of message listeners registered in an environment
730 : class MessageHandler {
731 : public:
732 : // Returns a message object for the API to use.
733 : static Handle<JSMessageObject> MakeMessageObject(
734 : Isolate* isolate, MessageTemplate::Template type,
735 : const MessageLocation* location, Handle<Object> argument,
736 : Handle<FixedArray> stack_frames);
737 :
738 : // Report a formatted message (needs JS allocation).
739 : static void ReportMessage(Isolate* isolate, const MessageLocation* loc,
740 : Handle<JSMessageObject> message);
741 :
742 : static void DefaultMessageReport(Isolate* isolate, const MessageLocation* loc,
743 : Handle<Object> message_obj);
744 : static Handle<String> GetMessage(Isolate* isolate, Handle<Object> data);
745 : static std::unique_ptr<char[]> GetLocalizedMessage(Isolate* isolate,
746 : Handle<Object> data);
747 :
748 : private:
749 : static void ReportMessageNoExceptions(Isolate* isolate,
750 : const MessageLocation* loc,
751 : Handle<Object> message_obj,
752 : v8::Local<v8::Value> api_exception_obj);
753 : };
754 :
755 :
756 : } // namespace internal
757 : } // namespace v8
758 :
759 : #endif // V8_MESSAGES_H_
|