This repository was archived by the owner on Jul 11, 2025. It is now read-only.
forked from phoboslab/JavaScriptCore-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathError.cpp
More file actions
189 lines (154 loc) · 6.14 KB
/
Error.cpp
File metadata and controls
189 lines (154 loc) · 6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
* Copyright (C) 1999-2001 Harri Porten ([email protected])
* Copyright (C) 2001 Peter Kelly ([email protected])
* Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2007 Eric Seidel ([email protected])
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "config.h"
#include "Error.h"
#include "ConstructData.h"
#include "ErrorConstructor.h"
#include "ExceptionHelpers.h"
#include "FunctionPrototype.h"
#include "JSArray.h"
#include "JSFunction.h"
#include "JSGlobalObject.h"
#include "JSObject.h"
#include "JSString.h"
#include "NativeErrorConstructor.h"
#include "SourceCode.h"
#include <wtf/text/StringBuilder.h>
namespace JSC {
static const char* linePropertyName = "line";
static const char* sourceURLPropertyName = "sourceURL";
JSObject* createError(JSGlobalObject* globalObject, const UString& message)
{
ASSERT(!message.isEmpty());
return ErrorInstance::create(globalObject->globalData(), globalObject->errorStructure(), message);
}
JSObject* createEvalError(JSGlobalObject* globalObject, const UString& message)
{
ASSERT(!message.isEmpty());
return ErrorInstance::create(globalObject->globalData(), globalObject->evalErrorConstructor()->errorStructure(), message);
}
JSObject* createRangeError(JSGlobalObject* globalObject, const UString& message)
{
ASSERT(!message.isEmpty());
return ErrorInstance::create(globalObject->globalData(), globalObject->rangeErrorConstructor()->errorStructure(), message);
}
JSObject* createReferenceError(JSGlobalObject* globalObject, const UString& message)
{
ASSERT(!message.isEmpty());
return ErrorInstance::create(globalObject->globalData(), globalObject->referenceErrorConstructor()->errorStructure(), message);
}
JSObject* createSyntaxError(JSGlobalObject* globalObject, const UString& message)
{
ASSERT(!message.isEmpty());
return ErrorInstance::create(globalObject->globalData(), globalObject->syntaxErrorConstructor()->errorStructure(), message);
}
JSObject* createTypeError(JSGlobalObject* globalObject, const UString& message)
{
ASSERT(!message.isEmpty());
return ErrorInstance::create(globalObject->globalData(), globalObject->typeErrorConstructor()->errorStructure(), message);
}
JSObject* createNotEnoughArgumentsError(JSGlobalObject* globalObject)
{
return createTypeError(globalObject, "Not enough arguments");
}
JSObject* createURIError(JSGlobalObject* globalObject, const UString& message)
{
ASSERT(!message.isEmpty());
return ErrorInstance::create(globalObject->globalData(), globalObject->URIErrorConstructor()->errorStructure(), message);
}
JSObject* createError(ExecState* exec, const UString& message)
{
return createError(exec->lexicalGlobalObject(), message);
}
JSObject* createEvalError(ExecState* exec, const UString& message)
{
return createEvalError(exec->lexicalGlobalObject(), message);
}
JSObject* createRangeError(ExecState* exec, const UString& message)
{
return createRangeError(exec->lexicalGlobalObject(), message);
}
JSObject* createReferenceError(ExecState* exec, const UString& message)
{
return createReferenceError(exec->lexicalGlobalObject(), message);
}
JSObject* createSyntaxError(ExecState* exec, const UString& message)
{
return createSyntaxError(exec->lexicalGlobalObject(), message);
}
JSObject* createTypeError(ExecState* exec, const UString& message)
{
return createTypeError(exec->lexicalGlobalObject(), message);
}
JSObject* createNotEnoughArgumentsError(ExecState* exec)
{
return createNotEnoughArgumentsError(exec->lexicalGlobalObject());
}
JSObject* createURIError(ExecState* exec, const UString& message)
{
return createURIError(exec->lexicalGlobalObject(), message);
}
JSObject* addErrorInfo(CallFrame* callFrame, JSObject* error, int line, const SourceCode& source)
{
JSGlobalData* globalData = &callFrame->globalData();
const UString& sourceURL = source.provider()->url();
if (line != -1)
error->putDirect(*globalData, Identifier(globalData, linePropertyName), jsNumber(line), ReadOnly | DontDelete);
if (!sourceURL.isNull())
error->putDirect(*globalData, Identifier(globalData, sourceURLPropertyName), jsString(globalData, sourceURL), ReadOnly | DontDelete);
globalData->interpreter->addStackTraceIfNecessary(callFrame, error);
return error;
}
bool hasErrorInfo(ExecState* exec, JSObject* error)
{
return error->hasProperty(exec, Identifier(exec, linePropertyName))
|| error->hasProperty(exec, Identifier(exec, sourceURLPropertyName));
}
JSValue throwError(ExecState* exec, JSValue error)
{
if (error.isObject())
return throwError(exec, asObject(error));
exec->globalData().exception = error;
return error;
}
JSObject* throwError(ExecState* exec, JSObject* error)
{
Interpreter::addStackTraceIfNecessary(exec, error);
exec->globalData().exception = error;
return error;
}
JSObject* throwTypeError(ExecState* exec)
{
return throwError(exec, createTypeError(exec, "Type error"));
}
JSObject* throwSyntaxError(ExecState* exec)
{
return throwError(exec, createSyntaxError(exec, "Syntax error"));
}
ASSERT_CLASS_FITS_IN_CELL(StrictModeTypeErrorFunction);
const ClassInfo StrictModeTypeErrorFunction::s_info = { "Function", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(StrictModeTypeErrorFunction) };
void StrictModeTypeErrorFunction::destroy(JSCell* cell)
{
jsCast<StrictModeTypeErrorFunction*>(cell)->StrictModeTypeErrorFunction::~StrictModeTypeErrorFunction();
}
} // namespace JSC