1/*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003-2019 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#pragma once
24
25#include "ErrorInstance.h"
26#include "ErrorType.h"
27#include "Exception.h"
28#include "InternalFunction.h"
29#include "JSObject.h"
30#include "ThrowScope.h"
31#include <stdint.h>
32
33
34namespace JSC {
35
36class CallFrame;
37class VM;
38class JSGlobalObject;
39class JSObject;
40class SourceCode;
41class Structure;
42
43JSObject* createError(JSGlobalObject*, const String&, ErrorInstance::SourceAppender);
44JSObject* createEvalError(JSGlobalObject*, const String&, ErrorInstance::SourceAppender);
45JSObject* createRangeError(JSGlobalObject*, const String&, ErrorInstance::SourceAppender);
46JSObject* createReferenceError(JSGlobalObject*, const String&, ErrorInstance::SourceAppender);
47JSObject* createSyntaxError(JSGlobalObject*, const String&, ErrorInstance::SourceAppender);
48JSObject* createTypeError(JSGlobalObject*, const String&, ErrorInstance::SourceAppender, RuntimeType);
49JSObject* createNotEnoughArgumentsError(JSGlobalObject*, ErrorInstance::SourceAppender);
50JSObject* createURIError(JSGlobalObject*, const String&, ErrorInstance::SourceAppender);
51
52
53JS_EXPORT_PRIVATE JSObject* createError(JSGlobalObject*, const String&);
54JS_EXPORT_PRIVATE JSObject* createEvalError(JSGlobalObject*, const String&);
55JS_EXPORT_PRIVATE JSObject* createRangeError(JSGlobalObject*, const String&);
56JS_EXPORT_PRIVATE JSObject* createReferenceError(JSGlobalObject*, const String&);
57JS_EXPORT_PRIVATE JSObject* createSyntaxError(JSGlobalObject*, const String&);
58JS_EXPORT_PRIVATE JSObject* createTypeError(JSGlobalObject*);
59JS_EXPORT_PRIVATE JSObject* createTypeError(JSGlobalObject*, const String&);
60JS_EXPORT_PRIVATE JSObject* createNotEnoughArgumentsError(JSGlobalObject*);
61JS_EXPORT_PRIVATE JSObject* createURIError(JSGlobalObject*, const String&);
62JS_EXPORT_PRIVATE JSObject* createOutOfMemoryError(JSGlobalObject*);
63JS_EXPORT_PRIVATE JSObject* createOutOfMemoryError(JSGlobalObject*, const String&);
64
65JS_EXPORT_PRIVATE JSObject* createError(JSGlobalObject*, ErrorType, const String&);
66
67JSObject* createGetterTypeError(JSGlobalObject*, const String&);
68
69std::unique_ptr<Vector<StackFrame>> getStackTrace(JSGlobalObject*, VM&, JSObject*, bool useCurrentFrame);
70void getBytecodeIndex(VM&, CallFrame*, Vector<StackFrame>*, CallFrame*&, BytecodeIndex&);
71bool getLineColumnAndSource(Vector<StackFrame>* stackTrace, unsigned& line, unsigned& column, String& sourceURL);
72bool addErrorInfo(VM&, Vector<StackFrame>*, JSObject*);
73JS_EXPORT_PRIVATE void addErrorInfo(JSGlobalObject*, JSObject*, bool);
74JSObject* addErrorInfo(VM&, JSObject* error, int line, const SourceCode&);
75
76// Methods to throw Errors.
77
78// Convenience wrappers, create an throw an exception with a default message.
79JS_EXPORT_PRIVATE Exception* throwConstructorCannotBeCalledAsFunctionTypeError(JSGlobalObject*, ThrowScope&, const char* constructorName);
80JS_EXPORT_PRIVATE Exception* throwTypeError(JSGlobalObject*, ThrowScope&);
81JS_EXPORT_PRIVATE Exception* throwTypeError(JSGlobalObject*, ThrowScope&, ASCIILiteral errorMessage);
82JS_EXPORT_PRIVATE Exception* throwTypeError(JSGlobalObject*, ThrowScope&, const String& errorMessage);
83JS_EXPORT_PRIVATE Exception* throwSyntaxError(JSGlobalObject*, ThrowScope&);
84JS_EXPORT_PRIVATE Exception* throwSyntaxError(JSGlobalObject*, ThrowScope&, const String& errorMessage);
85inline Exception* throwRangeError(JSGlobalObject* globalObject, ThrowScope& scope, const String& errorMessage) { return throwException(globalObject, scope, createRangeError(globalObject, errorMessage)); }
86
87JS_EXPORT_PRIVATE Exception* throwGetterTypeError(JSGlobalObject*, ThrowScope&, const String& errorMessage);
88JS_EXPORT_PRIVATE JSValue throwDOMAttributeGetterTypeError(JSGlobalObject*, ThrowScope&, const ClassInfo*, PropertyName);
89
90// Convenience wrappers, wrap result as an EncodedJSValue.
91inline void throwVMError(JSGlobalObject* globalObject, ThrowScope& scope, Exception* exception) { throwException(globalObject, scope, exception); }
92inline EncodedJSValue throwVMError(JSGlobalObject* globalObject, ThrowScope& scope, JSValue error) { return JSValue::encode(throwException(globalObject, scope, error)); }
93inline EncodedJSValue throwVMError(JSGlobalObject* globalObject, ThrowScope& scope, const char* errorMessage) { return JSValue::encode(throwException(globalObject, scope, createError(globalObject, errorMessage))); }
94inline EncodedJSValue throwVMTypeError(JSGlobalObject* globalObject, ThrowScope& scope) { return JSValue::encode(throwTypeError(globalObject, scope)); }
95inline EncodedJSValue throwVMTypeError(JSGlobalObject* globalObject, ThrowScope& scope, ASCIILiteral errorMessage) { return JSValue::encode(throwTypeError(globalObject, scope, errorMessage)); }
96inline EncodedJSValue throwVMTypeError(JSGlobalObject* globalObject, ThrowScope& scope, const String& errorMessage) { return JSValue::encode(throwTypeError(globalObject, scope, errorMessage)); }
97inline EncodedJSValue throwVMRangeError(JSGlobalObject* globalObject, ThrowScope& scope, const String& errorMessage) { return JSValue::encode(throwRangeError(globalObject, scope, errorMessage)); }
98inline EncodedJSValue throwVMGetterTypeError(JSGlobalObject* globalObject, ThrowScope& scope, const String& errorMessage) { return JSValue::encode(throwGetterTypeError(globalObject, scope, errorMessage)); }
99inline EncodedJSValue throwVMDOMAttributeGetterTypeError(JSGlobalObject* globalObject, ThrowScope& scope, const ClassInfo* classInfo, PropertyName propertyName) { return JSValue::encode(throwDOMAttributeGetterTypeError(globalObject, scope, classInfo, propertyName)); }
100
101} // namespace JSC
102