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);
32
33const ClassInfo NativeErrorConstructor::info = { .className: "Function", .parentClass: &InternalFunction::info, .staticPropHashTable: 0, .classPropHashTableGetterFunction: 0 };
34
35NativeErrorConstructor::NativeErrorConstructor(ExecState* exec, NonNullPassRefPtr<Structure> structure, NativeErrorPrototype* nativeErrorPrototype)
36 : InternalFunction(&exec->globalData(), structure, Identifier(exec, nativeErrorPrototype->getDirect(propertyName: exec->propertyNames().name).getString(exec)))
37 , m_errorStructure(ErrorInstance::createStructure(prototype: nativeErrorPrototype))
38{
39 putDirect(propertyName: exec->propertyNames().length, value: jsNumber(exec, i: 1), attributes: DontDelete | ReadOnly | DontEnum); // ECMA 15.11.7.5
40 putDirect(propertyName: exec->propertyNames().prototype, value: nativeErrorPrototype, attributes: DontDelete | ReadOnly | DontEnum);
41}
42
43ErrorInstance* NativeErrorConstructor::construct(ExecState* exec, const ArgList& args)
44{
45 ErrorInstance* object = new (exec) ErrorInstance(m_errorStructure);
46 if (!args.at(idx: 0).isUndefined())
47 object->putDirect(propertyName: exec->propertyNames().message, value: jsString(exec, s: args.at(idx: 0).toString(exec)));
48 return object;
49}
50
51static JSObject* constructWithNativeErrorConstructor(ExecState* exec, JSObject* constructor, const ArgList& args)
52{
53 return static_cast<NativeErrorConstructor*>(constructor)->construct(exec, args);
54}
55
56ConstructType NativeErrorConstructor::getConstructData(ConstructData& constructData)
57{
58 constructData.native.function = constructWithNativeErrorConstructor;
59 return ConstructTypeHost;
60}
61
62static JSValue JSC_HOST_CALL callNativeErrorConstructor(ExecState* exec, JSObject* constructor, JSValue, const ArgList& args)
63{
64 return static_cast<NativeErrorConstructor*>(constructor)->construct(exec, args);
65}
66
67CallType NativeErrorConstructor::getCallData(CallData& callData)
68{
69 callData.native.function = callNativeErrorConstructor;
70 return CallTypeHost;
71}
72
73} // namespace JSC
74

source code of qtscript/src/3rdparty/javascriptcore/JavaScriptCore/runtime/NativeErrorConstructor.cpp