]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/NativeErrorConstructor.cpp
JavaScriptCore-1097.13.tar.gz
[apple/javascriptcore.git] / runtime / NativeErrorConstructor.cpp
CommitLineData
9dae56ea
A
1/*
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2008 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21#include "config.h"
22#include "NativeErrorConstructor.h"
23
24#include "ErrorInstance.h"
25#include "JSFunction.h"
26#include "JSString.h"
27#include "NativeErrorPrototype.h"
28
29namespace JSC {
30
31ASSERT_CLASS_FITS_IN_CELL(NativeErrorConstructor);
6fe7ccc8 32ASSERT_HAS_TRIVIAL_DESTRUCTOR(NativeErrorConstructor);
9dae56ea 33
6fe7ccc8 34const ClassInfo NativeErrorConstructor::s_info = { "Function", &InternalFunction::s_info, 0, 0, CREATE_METHOD_TABLE(NativeErrorConstructor) };
9dae56ea 35
6fe7ccc8
A
36NativeErrorConstructor::NativeErrorConstructor(JSGlobalObject* globalObject, Structure* structure)
37 : InternalFunction(globalObject, structure)
9dae56ea 38{
14957cd0 39}
4e4e5a6f 40
6fe7ccc8 41void NativeErrorConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
9dae56ea 42{
6fe7ccc8
A
43 NativeErrorConstructor* thisObject = jsCast<NativeErrorConstructor*>(cell);
44 ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
14957cd0 45 COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
6fe7ccc8
A
46 ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
47 InternalFunction::visitChildren(thisObject, visitor);
48 if (thisObject->m_errorStructure)
49 visitor.append(&thisObject->m_errorStructure);
9dae56ea
A
50}
51
14957cd0 52static EncodedJSValue JSC_HOST_CALL constructWithNativeErrorConstructor(ExecState* exec)
9dae56ea 53{
14957cd0
A
54 JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined();
55 Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure();
56 ASSERT(errorStructure);
57 return JSValue::encode(ErrorInstance::create(exec, errorStructure, message));
9dae56ea
A
58}
59
6fe7ccc8 60ConstructType NativeErrorConstructor::getConstructData(JSCell*, ConstructData& constructData)
9dae56ea
A
61{
62 constructData.native.function = constructWithNativeErrorConstructor;
63 return ConstructTypeHost;
64}
ba379fdc 65
14957cd0 66static EncodedJSValue JSC_HOST_CALL callNativeErrorConstructor(ExecState* exec)
9dae56ea 67{
14957cd0
A
68 JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined();
69 Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure();
70 return JSValue::encode(ErrorInstance::create(exec, errorStructure, message));
9dae56ea
A
71}
72
6fe7ccc8 73CallType NativeErrorConstructor::getCallData(JSCell*, CallData& callData)
9dae56ea
A
74{
75 callData.native.function = callNativeErrorConstructor;
76 return CallTypeHost;
77}
78
79} // namespace JSC