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, 2007, 2008 Apple Inc. All rights reserved.
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.
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.
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.
26 #include "ErrorInstance.h"
27 #include "InternalFunction.h"
28 #include "Interpreter.h"
42 // ExecState wrappers.
43 JSObject
* createError(ExecState
*, const String
&, ErrorInstance::SourceAppender
);
44 JSObject
* createEvalError(ExecState
*, const String
&, ErrorInstance::SourceAppender
);
45 JSObject
* createRangeError(ExecState
*, const String
&, ErrorInstance::SourceAppender
);
46 JSObject
* createReferenceError(ExecState
*, const String
&, ErrorInstance::SourceAppender
);
47 JSObject
* createSyntaxError(ExecState
*, const String
&, ErrorInstance::SourceAppender
);
48 JSObject
* createTypeError(ExecState
*, const String
&, ErrorInstance::SourceAppender
, RuntimeType
);
49 JSObject
* createNotEnoughArgumentsError(ExecState
*, ErrorInstance::SourceAppender
);
50 JSObject
* createURIError(ExecState
*, const String
&, ErrorInstance::SourceAppender
);
51 JSObject
* createOutOfMemoryError(ExecState
*, ErrorInstance::SourceAppender
);
54 JS_EXPORT_PRIVATE JSObject
* createError(ExecState
*, const String
&);
55 JS_EXPORT_PRIVATE JSObject
* createEvalError(ExecState
*, const String
&);
56 JS_EXPORT_PRIVATE JSObject
* createRangeError(ExecState
*, const String
&);
57 JS_EXPORT_PRIVATE JSObject
* createReferenceError(ExecState
*, const String
&);
58 JS_EXPORT_PRIVATE JSObject
* createSyntaxError(ExecState
*, const String
&);
59 JS_EXPORT_PRIVATE JSObject
* createTypeError(ExecState
*);
60 JS_EXPORT_PRIVATE JSObject
* createTypeError(ExecState
*, const String
&);
61 JS_EXPORT_PRIVATE JSObject
* createNotEnoughArgumentsError(ExecState
*);
62 JS_EXPORT_PRIVATE JSObject
* createURIError(ExecState
*, const String
&);
63 JS_EXPORT_PRIVATE JSObject
* createOutOfMemoryError(ExecState
*);
66 bool addErrorInfoAndGetBytecodeOffset(ExecState
*, VM
&, JSObject
*, bool, CallFrame
*&, unsigned&);
68 bool hasErrorInfo(ExecState
*, JSObject
* error
);
69 JS_EXPORT_PRIVATE
void addErrorInfo(ExecState
*, JSObject
*, bool);
70 JSObject
* addErrorInfo(ExecState
*, JSObject
* error
, int line
, const SourceCode
&);
72 // Methods to throw Errors.
74 // Convenience wrappers, create an throw an exception with a default message.
75 JS_EXPORT_PRIVATE JSObject
* throwTypeError(ExecState
*);
76 JS_EXPORT_PRIVATE JSObject
* throwSyntaxError(ExecState
*);
77 inline JSObject
* throwRangeError(ExecState
* state
, const String
& errorMessage
) { return state
->vm().throwException(state
, createRangeError(state
, errorMessage
)); }
79 // Convenience wrappers, wrap result as an EncodedJSValue.
80 inline void throwVMError(ExecState
* exec
, Exception
* exception
) { exec
->vm().throwException(exec
, exception
); }
81 inline EncodedJSValue
throwVMError(ExecState
* exec
, JSValue error
) { return JSValue::encode(exec
->vm().throwException(exec
, error
)); }
82 inline EncodedJSValue
throwVMTypeError(ExecState
* exec
) { return JSValue::encode(throwTypeError(exec
)); }
83 inline EncodedJSValue
throwVMTypeError(ExecState
* exec
, const String
& errorMessage
) { return JSValue::encode(throwTypeError(exec
, errorMessage
)); }
84 inline EncodedJSValue
throwVMRangeError(ExecState
* state
, const String
& errorMessage
) { return JSValue::encode(throwRangeError(state
, errorMessage
)); }
86 class StrictModeTypeErrorFunction
: public InternalFunction
{
88 StrictModeTypeErrorFunction(VM
& vm
, Structure
* structure
, const String
& message
)
89 : InternalFunction(vm
, structure
)
94 static void destroy(JSCell
*);
97 typedef InternalFunction Base
;
99 static StrictModeTypeErrorFunction
* create(VM
& vm
, Structure
* structure
, const String
& message
)
101 StrictModeTypeErrorFunction
* function
= new (NotNull
, allocateCell
<StrictModeTypeErrorFunction
>(vm
.heap
)) StrictModeTypeErrorFunction(vm
, structure
, message
);
102 function
->finishCreation(vm
, String());
106 static EncodedJSValue JSC_HOST_CALL
constructThrowTypeError(ExecState
* exec
)
108 throwTypeError(exec
, static_cast<StrictModeTypeErrorFunction
*>(exec
->callee())->m_message
);
109 return JSValue::encode(jsNull());
112 static ConstructType
getConstructData(JSCell
*, ConstructData
& constructData
)
114 constructData
.native
.function
= constructThrowTypeError
;
115 return ConstructTypeHost
;
118 static EncodedJSValue JSC_HOST_CALL
callThrowTypeError(ExecState
* exec
)
120 throwTypeError(exec
, static_cast<StrictModeTypeErrorFunction
*>(exec
->callee())->m_message
);
121 return JSValue::encode(jsNull());
124 static CallType
getCallData(JSCell
*, CallData
& callData
)
126 callData
.native
.function
= callThrowTypeError
;
132 static Structure
* createStructure(VM
& vm
, JSGlobalObject
* globalObject
, JSValue prototype
)
134 return Structure::create(vm
, globalObject
, prototype
, TypeInfo(ObjectType
, StructureFlags
), info());