Rubber-stamped by Brady Eidson.
[webbrowser.git] / JavaScriptCore / runtime / NativeErrorConstructor.cpp
blob403fc7ecca463e62c6b18491868bae817007d54a
1 /*
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2003, 2008 Apple Inc. All rights reserved.
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.
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.
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
21 #include "config.h"
22 #include "NativeErrorConstructor.h"
24 #include "ErrorInstance.h"
25 #include "JSFunction.h"
26 #include "JSString.h"
27 #include "NativeErrorPrototype.h"
29 namespace JSC {
31 ASSERT_CLASS_FITS_IN_CELL(NativeErrorConstructor);
33 const ClassInfo NativeErrorConstructor::info = { "Function", &InternalFunction::info, 0, 0 };
35 NativeErrorConstructor::NativeErrorConstructor(ExecState* exec, NonNullPassRefPtr<Structure> structure, NativeErrorPrototype* nativeErrorPrototype)
36 : InternalFunction(&exec->globalData(), structure, Identifier(exec, nativeErrorPrototype->getDirect(exec->propertyNames().name).getString(exec)))
37 , m_errorStructure(ErrorInstance::createStructure(nativeErrorPrototype))
39 putDirect(exec->propertyNames().length, jsNumber(exec, 1), DontDelete | ReadOnly | DontEnum); // ECMA 15.11.7.5
40 putDirect(exec->propertyNames().prototype, nativeErrorPrototype, DontDelete | ReadOnly | DontEnum);
43 ErrorInstance* NativeErrorConstructor::construct(ExecState* exec, const ArgList& args)
45 ErrorInstance* object = new (exec) ErrorInstance(m_errorStructure);
46 if (!args.at(0).isUndefined())
47 object->putDirect(exec->propertyNames().message, jsString(exec, args.at(0).toString(exec)));
48 return object;
51 static JSObject* constructWithNativeErrorConstructor(ExecState* exec, JSObject* constructor, const ArgList& args)
53 return static_cast<NativeErrorConstructor*>(constructor)->construct(exec, args);
56 ConstructType NativeErrorConstructor::getConstructData(ConstructData& constructData)
58 constructData.native.function = constructWithNativeErrorConstructor;
59 return ConstructTypeHost;
62 static JSValue JSC_HOST_CALL callNativeErrorConstructor(ExecState* exec, JSObject* constructor, JSValue, const ArgList& args)
64 return static_cast<NativeErrorConstructor*>(constructor)->construct(exec, args);
67 CallType NativeErrorConstructor::getCallData(CallData& callData)
69 callData.native.function = callNativeErrorConstructor;
70 return CallTypeHost;
73 } // namespace JSC