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 "InternalFunction.h"
27 #include "Interpreter.h"
40 // Methods to create a range of internal errors.
41 JSObject
* createError(JSGlobalObject
*, const String
&);
42 JSObject
* createEvalError(JSGlobalObject
*, const String
&);
43 JSObject
* createRangeError(JSGlobalObject
*, const String
&);
44 JSObject
* createReferenceError(JSGlobalObject
*, const String
&);
45 JSObject
* createSyntaxError(JSGlobalObject
*, const String
&);
46 JSObject
* createTypeError(JSGlobalObject
*, const String
&);
47 JSObject
* createNotEnoughArgumentsError(JSGlobalObject
*);
48 JSObject
* createURIError(JSGlobalObject
*, const String
&);
49 // ExecState wrappers.
50 JS_EXPORT_PRIVATE JSObject
* createError(ExecState
*, const String
&);
51 JSObject
* createEvalError(ExecState
*, const String
&);
52 JS_EXPORT_PRIVATE JSObject
* createRangeError(ExecState
*, const String
&);
53 JS_EXPORT_PRIVATE JSObject
* createReferenceError(ExecState
*, const String
&);
54 JS_EXPORT_PRIVATE JSObject
* createSyntaxError(ExecState
*, const String
&);
55 JS_EXPORT_PRIVATE JSObject
* createTypeError(ExecState
*, const String
&);
56 JS_EXPORT_PRIVATE JSObject
* createNotEnoughArgumentsError(ExecState
*);
57 JSObject
* createURIError(ExecState
*, const String
&);
60 bool hasErrorInfo(ExecState
*, JSObject
* error
);
61 // ExecState wrappers.
62 JSObject
* addErrorInfo(ExecState
*, JSObject
* error
, int line
, const SourceCode
&);
64 // Methods to throw Errors.
66 // Convenience wrappers, create an throw an exception with a default message.
67 JS_EXPORT_PRIVATE JSObject
* throwTypeError(ExecState
*);
68 JS_EXPORT_PRIVATE JSObject
* throwSyntaxError(ExecState
*);
70 // Convenience wrappers, wrap result as an EncodedJSValue.
71 inline EncodedJSValue
throwVMError(ExecState
* exec
, JSValue error
) { return JSValue::encode(exec
->vm().throwException(exec
, error
)); }
72 inline EncodedJSValue
throwVMTypeError(ExecState
* exec
) { return JSValue::encode(throwTypeError(exec
)); }
73 inline EncodedJSValue
throwVMTypeError(ExecState
* exec
, const String
& errorMessage
) { return JSValue::encode(throwTypeError(exec
, errorMessage
)); }
75 class StrictModeTypeErrorFunction
: public InternalFunction
{
77 StrictModeTypeErrorFunction(VM
& vm
, Structure
* structure
, const String
& message
)
78 : InternalFunction(vm
, structure
)
83 static void destroy(JSCell
*);
86 typedef InternalFunction Base
;
88 static StrictModeTypeErrorFunction
* create(VM
& vm
, Structure
* structure
, const String
& message
)
90 StrictModeTypeErrorFunction
* function
= new (NotNull
, allocateCell
<StrictModeTypeErrorFunction
>(vm
.heap
)) StrictModeTypeErrorFunction(vm
, structure
, message
);
91 function
->finishCreation(vm
, String());
95 static EncodedJSValue JSC_HOST_CALL
constructThrowTypeError(ExecState
* exec
)
97 throwTypeError(exec
, static_cast<StrictModeTypeErrorFunction
*>(exec
->callee())->m_message
);
98 return JSValue::encode(jsNull());
101 static ConstructType
getConstructData(JSCell
*, ConstructData
& constructData
)
103 constructData
.native
.function
= constructThrowTypeError
;
104 return ConstructTypeHost
;
107 static EncodedJSValue JSC_HOST_CALL
callThrowTypeError(ExecState
* exec
)
109 throwTypeError(exec
, static_cast<StrictModeTypeErrorFunction
*>(exec
->callee())->m_message
);
110 return JSValue::encode(jsNull());
113 static CallType
getCallData(JSCell
*, CallData
& callData
)
115 callData
.native
.function
= callThrowTypeError
;
121 static Structure
* createStructure(VM
& vm
, JSGlobalObject
* globalObject
, JSValue prototype
)
123 return Structure::create(vm
, globalObject
, prototype
, TypeInfo(ObjectType
, StructureFlags
), info());