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)
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.
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.
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.
27 #include "ConstructData.h"
28 #include "ErrorConstructor.h"
29 #include "JSFunction.h"
30 #include "JSGlobalObject.h"
33 #include "NativeErrorConstructor.h"
37 const char* expressionBeginOffsetPropertyName
= "expressionBeginOffset";
38 const char* expressionCaretOffsetPropertyName
= "expressionCaretOffset";
39 const char* expressionEndOffsetPropertyName
= "expressionEndOffset";
41 JSObject
* Error::create(ExecState
* exec
, ErrorType type
, const UString
& message
, int lineNumber
, intptr_t sourceID
, const UString
& sourceURL
)
43 JSObject
* constructor
;
47 constructor
= exec
->lexicalGlobalObject()->evalErrorConstructor();
48 name
= "Evaluation error";
51 constructor
= exec
->lexicalGlobalObject()->rangeErrorConstructor();
55 constructor
= exec
->lexicalGlobalObject()->referenceErrorConstructor();
56 name
= "Reference error";
59 constructor
= exec
->lexicalGlobalObject()->syntaxErrorConstructor();
60 name
= "Syntax error";
63 constructor
= exec
->lexicalGlobalObject()->typeErrorConstructor();
67 constructor
= exec
->lexicalGlobalObject()->URIErrorConstructor();
71 constructor
= exec
->lexicalGlobalObject()->errorConstructor();
76 MarkedArgumentBuffer args
;
77 if (message
.isEmpty())
78 args
.append(jsString(exec
, name
));
80 args
.append(jsString(exec
, message
));
81 ConstructData constructData
;
82 ConstructType constructType
= constructor
->getConstructData(constructData
);
83 JSObject
* error
= construct(exec
, constructor
, constructType
, constructData
, args
);
86 error
->putWithAttributes(exec
, Identifier(exec
, "line"), jsNumber(exec
, lineNumber
), ReadOnly
| DontDelete
);
88 error
->putWithAttributes(exec
, Identifier(exec
, "sourceId"), jsNumber(exec
, sourceID
), ReadOnly
| DontDelete
);
89 if (!sourceURL
.isNull())
90 error
->putWithAttributes(exec
, Identifier(exec
, "sourceURL"), jsString(exec
, sourceURL
), ReadOnly
| DontDelete
);
95 JSObject
* Error::create(ExecState
* exec
, ErrorType type
, const char* message
)
97 return create(exec
, type
, message
, -1, -1, NULL
);
100 JSObject
* throwError(ExecState
* exec
, ErrorType type
)
102 JSObject
* error
= Error::create(exec
, type
, UString(), -1, -1, NULL
);
103 exec
->setException(error
);
107 JSObject
* throwError(ExecState
* exec
, ErrorType type
, const UString
& message
)
109 JSObject
* error
= Error::create(exec
, type
, message
, -1, -1, NULL
);
110 exec
->setException(error
);
114 JSObject
* throwError(ExecState
* exec
, ErrorType type
, const char* message
)
116 JSObject
* error
= Error::create(exec
, type
, message
, -1, -1, NULL
);
117 exec
->setException(error
);
121 JSObject
* throwError(ExecState
* exec
, ErrorType type
, const UString
& message
, int line
, intptr_t sourceID
, const UString
& sourceURL
)
123 JSObject
* error
= Error::create(exec
, type
, message
, line
, sourceID
, sourceURL
);
124 exec
->setException(error
);