]>
Commit | Line | Data |
---|---|---|
9dae56ea A |
1 | /* |
2 | * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) | |
3 | * Copyright (C) 2001 Peter Kelly (pmk@post.com) | |
4 | * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. | |
5 | * Copyright (C) 2007 Eric Seidel (eric@webkit.org) | |
6 | * | |
7 | * This library is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU Library General Public | |
9 | * License as published by the Free Software Foundation; either | |
10 | * version 2 of the License, or (at your option) any later version. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Library General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Library General Public License | |
18 | * along with this library; see the file COPYING.LIB. If not, write to | |
19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
20 | * Boston, MA 02110-1301, USA. | |
21 | * | |
22 | */ | |
23 | ||
24 | #include "config.h" | |
25 | #include "Error.h" | |
26 | ||
27 | #include "ConstructData.h" | |
28 | #include "ErrorConstructor.h" | |
6fe7ccc8 A |
29 | #include "ExceptionHelpers.h" |
30 | #include "FunctionPrototype.h" | |
31 | #include "JSArray.h" | |
ba379fdc | 32 | #include "JSFunction.h" |
9dae56ea A |
33 | #include "JSGlobalObject.h" |
34 | #include "JSObject.h" | |
35 | #include "JSString.h" | |
36 | #include "NativeErrorConstructor.h" | |
81345200 | 37 | #include "JSCInlines.h" |
14957cd0 | 38 | #include "SourceCode.h" |
9dae56ea | 39 | |
6fe7ccc8 A |
40 | #include <wtf/text/StringBuilder.h> |
41 | ||
9dae56ea A |
42 | namespace JSC { |
43 | ||
14957cd0 | 44 | static const char* linePropertyName = "line"; |
14957cd0 A |
45 | static const char* sourceURLPropertyName = "sourceURL"; |
46 | ||
93a37866 | 47 | JSObject* createError(JSGlobalObject* globalObject, const String& message) |
14957cd0 A |
48 | { |
49 | ASSERT(!message.isEmpty()); | |
93a37866 | 50 | return ErrorInstance::create(globalObject->vm(), globalObject->errorStructure(), message); |
14957cd0 A |
51 | } |
52 | ||
93a37866 | 53 | JSObject* createEvalError(JSGlobalObject* globalObject, const String& message) |
14957cd0 A |
54 | { |
55 | ASSERT(!message.isEmpty()); | |
93a37866 | 56 | return ErrorInstance::create(globalObject->vm(), globalObject->evalErrorConstructor()->errorStructure(), message); |
14957cd0 A |
57 | } |
58 | ||
93a37866 | 59 | JSObject* createRangeError(JSGlobalObject* globalObject, const String& message) |
14957cd0 A |
60 | { |
61 | ASSERT(!message.isEmpty()); | |
93a37866 | 62 | return ErrorInstance::create(globalObject->vm(), globalObject->rangeErrorConstructor()->errorStructure(), message); |
14957cd0 A |
63 | } |
64 | ||
93a37866 | 65 | JSObject* createReferenceError(JSGlobalObject* globalObject, const String& message) |
14957cd0 A |
66 | { |
67 | ASSERT(!message.isEmpty()); | |
93a37866 | 68 | return ErrorInstance::create(globalObject->vm(), globalObject->referenceErrorConstructor()->errorStructure(), message); |
14957cd0 A |
69 | } |
70 | ||
93a37866 | 71 | JSObject* createSyntaxError(JSGlobalObject* globalObject, const String& message) |
14957cd0 A |
72 | { |
73 | ASSERT(!message.isEmpty()); | |
93a37866 | 74 | return ErrorInstance::create(globalObject->vm(), globalObject->syntaxErrorConstructor()->errorStructure(), message); |
14957cd0 A |
75 | } |
76 | ||
93a37866 | 77 | JSObject* createTypeError(JSGlobalObject* globalObject, const String& message) |
14957cd0 A |
78 | { |
79 | ASSERT(!message.isEmpty()); | |
93a37866 | 80 | return ErrorInstance::create(globalObject->vm(), globalObject->typeErrorConstructor()->errorStructure(), message); |
6fe7ccc8 A |
81 | } |
82 | ||
83 | JSObject* createNotEnoughArgumentsError(JSGlobalObject* globalObject) | |
84 | { | |
93a37866 | 85 | return createTypeError(globalObject, ASCIILiteral("Not enough arguments")); |
14957cd0 A |
86 | } |
87 | ||
93a37866 | 88 | JSObject* createURIError(JSGlobalObject* globalObject, const String& message) |
14957cd0 A |
89 | { |
90 | ASSERT(!message.isEmpty()); | |
93a37866 | 91 | return ErrorInstance::create(globalObject->vm(), globalObject->URIErrorConstructor()->errorStructure(), message); |
14957cd0 A |
92 | } |
93 | ||
93a37866 | 94 | JSObject* createError(ExecState* exec, const String& message) |
14957cd0 A |
95 | { |
96 | return createError(exec->lexicalGlobalObject(), message); | |
97 | } | |
98 | ||
93a37866 | 99 | JSObject* createEvalError(ExecState* exec, const String& message) |
14957cd0 A |
100 | { |
101 | return createEvalError(exec->lexicalGlobalObject(), message); | |
102 | } | |
103 | ||
93a37866 | 104 | JSObject* createRangeError(ExecState* exec, const String& message) |
14957cd0 A |
105 | { |
106 | return createRangeError(exec->lexicalGlobalObject(), message); | |
107 | } | |
9dae56ea | 108 | |
93a37866 | 109 | JSObject* createReferenceError(ExecState* exec, const String& message) |
14957cd0 A |
110 | { |
111 | return createReferenceError(exec->lexicalGlobalObject(), message); | |
112 | } | |
113 | ||
93a37866 | 114 | JSObject* createSyntaxError(ExecState* exec, const String& message) |
14957cd0 A |
115 | { |
116 | return createSyntaxError(exec->lexicalGlobalObject(), message); | |
117 | } | |
118 | ||
93a37866 | 119 | JSObject* createTypeError(ExecState* exec, const String& message) |
14957cd0 A |
120 | { |
121 | return createTypeError(exec->lexicalGlobalObject(), message); | |
122 | } | |
123 | ||
6fe7ccc8 A |
124 | JSObject* createNotEnoughArgumentsError(ExecState* exec) |
125 | { | |
126 | return createNotEnoughArgumentsError(exec->lexicalGlobalObject()); | |
127 | } | |
128 | ||
93a37866 | 129 | JSObject* createURIError(ExecState* exec, const String& message) |
14957cd0 A |
130 | { |
131 | return createURIError(exec->lexicalGlobalObject(), message); | |
132 | } | |
133 | ||
6fe7ccc8 | 134 | JSObject* addErrorInfo(CallFrame* callFrame, JSObject* error, int line, const SourceCode& source) |
14957cd0 | 135 | { |
93a37866 A |
136 | VM* vm = &callFrame->vm(); |
137 | const String& sourceURL = source.provider()->url(); | |
14957cd0 A |
138 | |
139 | if (line != -1) | |
93a37866 | 140 | error->putDirect(*vm, Identifier(vm, linePropertyName), jsNumber(line), ReadOnly | DontDelete); |
9dae56ea | 141 | if (!sourceURL.isNull()) |
93a37866 | 142 | error->putDirect(*vm, Identifier(vm, sourceURLPropertyName), jsString(vm, sourceURL), ReadOnly | DontDelete); |
9dae56ea A |
143 | return error; |
144 | } | |
145 | ||
9dae56ea | 146 | |
14957cd0 | 147 | bool hasErrorInfo(ExecState* exec, JSObject* error) |
f9bf01c6 | 148 | { |
14957cd0 | 149 | return error->hasProperty(exec, Identifier(exec, linePropertyName)) |
14957cd0 | 150 | || error->hasProperty(exec, Identifier(exec, sourceURLPropertyName)); |
f9bf01c6 A |
151 | } |
152 | ||
14957cd0 | 153 | JSObject* throwTypeError(ExecState* exec) |
9dae56ea | 154 | { |
81345200 | 155 | return exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("Type error"))); |
9dae56ea A |
156 | } |
157 | ||
14957cd0 | 158 | JSObject* throwSyntaxError(ExecState* exec) |
9dae56ea | 159 | { |
81345200 | 160 | return exec->vm().throwException(exec, createSyntaxError(exec, ASCIILiteral("Syntax error"))); |
14957cd0 A |
161 | } |
162 | ||
6fe7ccc8 A |
163 | const ClassInfo StrictModeTypeErrorFunction::s_info = { "Function", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(StrictModeTypeErrorFunction) }; |
164 | ||
165 | void StrictModeTypeErrorFunction::destroy(JSCell* cell) | |
14957cd0 | 166 | { |
93a37866 | 167 | static_cast<StrictModeTypeErrorFunction*>(cell)->StrictModeTypeErrorFunction::~StrictModeTypeErrorFunction(); |
9dae56ea A |
168 | } |
169 | ||
170 | } // namespace JSC |