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 "JSGlobalObject.h"
32 #include "NativeErrorConstructor.h"
36 const char* expressionBeginOffsetPropertyName
= "expressionBeginOffset";
37 const char* expressionCaretOffsetPropertyName
= "expressionCaretOffset";
38 const char* expressionEndOffsetPropertyName
= "expressionEndOffset";
40 JSObject
* Error::create(ExecState
* exec
, ErrorType type
, const UString
& message
, int lineNumber
, intptr_t sourceID
, const UString
& sourceURL
)
42 JSObject
* constructor
;
46 constructor
= exec
->lexicalGlobalObject()->evalErrorConstructor();
47 name
= "Evaluation error";
50 constructor
= exec
->lexicalGlobalObject()->rangeErrorConstructor();
54 constructor
= exec
->lexicalGlobalObject()->referenceErrorConstructor();
55 name
= "Reference error";
58 constructor
= exec
->lexicalGlobalObject()->syntaxErrorConstructor();
59 name
= "Syntax error";
62 constructor
= exec
->lexicalGlobalObject()->typeErrorConstructor();
66 constructor
= exec
->lexicalGlobalObject()->URIErrorConstructor();
70 constructor
= exec
->lexicalGlobalObject()->errorConstructor();
76 if (message
.isEmpty())
77 args
.append(jsString(exec
, name
));
79 args
.append(jsString(exec
, message
));
80 ConstructData constructData
;
81 ConstructType constructType
= constructor
->getConstructData(constructData
);
82 JSObject
* error
= construct(exec
, constructor
, constructType
, constructData
, args
);
85 error
->putWithAttributes(exec
, Identifier(exec
, "line"), jsNumber(exec
, lineNumber
), ReadOnly
| DontDelete
);
87 error
->putWithAttributes(exec
, Identifier(exec
, "sourceId"), jsNumber(exec
, sourceID
), ReadOnly
| DontDelete
);
88 if (!sourceURL
.isNull())
89 error
->putWithAttributes(exec
, Identifier(exec
, "sourceURL"), jsString(exec
, sourceURL
), ReadOnly
| DontDelete
);
94 JSObject
* Error::create(ExecState
* exec
, ErrorType type
, const char* message
)
96 return create(exec
, type
, message
, -1, -1, NULL
);
99 JSObject
* throwError(ExecState
* exec
, ErrorType type
)
101 JSObject
* error
= Error::create(exec
, type
, UString(), -1, -1, NULL
);
102 exec
->setException(error
);
106 JSObject
* throwError(ExecState
* exec
, ErrorType type
, const UString
& message
)
108 JSObject
* error
= Error::create(exec
, type
, message
, -1, -1, NULL
);
109 exec
->setException(error
);
113 JSObject
* throwError(ExecState
* exec
, ErrorType type
, const char* message
)
115 JSObject
* error
= Error::create(exec
, type
, message
, -1, -1, NULL
);
116 exec
->setException(error
);
120 JSObject
* throwError(ExecState
* exec
, ErrorType type
, const UString
& message
, int line
, intptr_t sourceID
, const UString
& sourceURL
)
122 JSObject
* error
= Error::create(exec
, type
, message
, line
, sourceID
, sourceURL
);
123 exec
->setException(error
);