blob: 26bb89ffee9bb1cece59ac50096bba50d0be8885 [file] [log] [blame]
weinig@apple.comf157abf2008-07-05 05:35:09 +00001/*
2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
mark.lam@apple.com60c090d2019-03-07 10:16:58 +00004 * Copyright (C) 2003-2019 Apple Inc. All rights reserved.
weinig@apple.comf157abf2008-07-05 05:35:09 +00005 *
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
ryanhaddad@apple.com22104f52016-09-28 17:08:17 +000023#pragma once
weinig@apple.comf157abf2008-07-05 05:35:09 +000024
mmirman@apple.comc35dac92015-04-07 21:34:05 +000025#include "ErrorInstance.h"
ysuzuki@apple.comf4986c82019-01-26 09:07:25 +000026#include "ErrorType.h"
mark.lam@apple.com60c090d2019-03-07 10:16:58 +000027#include "Exception.h"
mhahnenberg@apple.com6fb47cf2011-10-10 22:32:00 +000028#include "InternalFunction.h"
barraclough@apple.com9c099f92010-06-06 23:34:36 +000029#include "JSObject.h"
mark.lam@apple.com284f4562016-08-30 20:54:54 +000030#include "ThrowScope.h"
ggaren@apple.com306b0d52008-10-02 07:04:10 +000031#include <stdint.h>
32
mmirman@apple.comc35dac92015-04-07 21:34:05 +000033
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000034namespace JSC {
weinig@apple.comf157abf2008-07-05 05:35:09 +000035
ysuzuki@apple.com622e8692019-10-07 23:13:45 +000036class CallFrame;
mark.lam@apple.com188640e2014-09-04 19:10:36 +000037class VM;
38class JSGlobalObject;
39class JSObject;
40class SourceCode;
41class Structure;
weinig@apple.comf157abf2008-07-05 05:35:09 +000042
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000043JSObject* 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);
mmirman@apple.comc35dac92015-04-07 21:34:05 +000051
52
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000053JS_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&);
weinig@apple.com0e2d66e2008-07-06 05:26:58 +000064
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000065JS_EXPORT_PRIVATE JSObject* createError(JSGlobalObject*, ErrorType, const String&);
utatane.tea@gmail.com0eb0f832016-10-06 07:44:23 +000066
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000067JSObject* createGetterTypeError(JSGlobalObject*, const String&);
drousso@apple.comaad56082019-04-16 00:02:32 +000068
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000069std::unique_ptr<Vector<StackFrame>> getStackTrace(JSGlobalObject*, VM&, JSObject*, bool useCurrentFrame);
keith_miller@apple.com0f985ec2019-10-23 00:55:38 +000070void getBytecodeIndex(VM&, CallFrame*, Vector<StackFrame>*, CallFrame*&, BytecodeIndex&);
fpizlo@apple.coma06a0d22017-09-10 19:00:03 +000071bool getLineColumnAndSource(Vector<StackFrame>* stackTrace, unsigned& line, unsigned& column, String& sourceURL);
72bool addErrorInfo(VM&, Vector<StackFrame>*, JSObject*);
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000073JS_EXPORT_PRIVATE void addErrorInfo(JSGlobalObject*, JSObject*, bool);
74JSObject* addErrorInfo(VM&, JSObject* error, int line, const SourceCode&);
barraclough@apple.com9c099f92010-06-06 23:34:36 +000075
mark.lam@apple.com188640e2014-09-04 19:10:36 +000076// Methods to throw Errors.
weinig@apple.comf157abf2008-07-05 05:35:09 +000077
mark.lam@apple.com188640e2014-09-04 19:10:36 +000078// Convenience wrappers, create an throw an exception with a default message.
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000079JS_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)); }
drousso@apple.comaad56082019-04-16 00:02:32 +000086
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000087JS_EXPORT_PRIVATE Exception* throwGetterTypeError(JSGlobalObject*, ThrowScope&, const String& errorMessage);
88JS_EXPORT_PRIVATE JSValue throwDOMAttributeGetterTypeError(JSGlobalObject*, ThrowScope&, const ClassInfo*, PropertyName);
barraclough@apple.com9c099f92010-06-06 23:34:36 +000089
mark.lam@apple.com188640e2014-09-04 19:10:36 +000090// Convenience wrappers, wrap result as an EncodedJSValue.
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000091inline 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)); }
mhahnenberg@apple.com6fb47cf2011-10-10 22:32:00 +0000100
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +0000101} // namespace JSC