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
22 #include "NativeErrorConstructor.h"
24 #include "ErrorInstance.h"
25 #include "JSFunction.h"
27 #include "NativeErrorPrototype.h"
28 #include "JSCInlines.h"
32 STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(NativeErrorConstructor
);
34 const ClassInfo
NativeErrorConstructor::s_info
= { "Function", &InternalFunction::s_info
, 0, 0, CREATE_METHOD_TABLE(NativeErrorConstructor
) };
36 NativeErrorConstructor::NativeErrorConstructor(VM
& vm
, Structure
* structure
)
37 : InternalFunction(vm
, structure
)
41 void NativeErrorConstructor::finishCreation(VM
& vm
, JSGlobalObject
* globalObject
, Structure
* prototypeStructure
, const String
& name
)
43 Base::finishCreation(vm
, name
);
44 ASSERT(inherits(info()));
46 NativeErrorPrototype
* prototype
= NativeErrorPrototype::create(vm
, globalObject
, prototypeStructure
, name
, this);
48 putDirect(vm
, vm
.propertyNames
->length
, jsNumber(1), DontDelete
| ReadOnly
| DontEnum
); // ECMA 15.11.7.5
49 putDirect(vm
, vm
.propertyNames
->prototype
, prototype
, DontDelete
| ReadOnly
| DontEnum
);
50 m_errorStructure
.set(vm
, this, ErrorInstance::createStructure(vm
, globalObject
, prototype
));
51 ASSERT(m_errorStructure
);
52 ASSERT(m_errorStructure
->isObject());
55 void NativeErrorConstructor::visitChildren(JSCell
* cell
, SlotVisitor
& visitor
)
57 NativeErrorConstructor
* thisObject
= jsCast
<NativeErrorConstructor
*>(cell
);
58 ASSERT_GC_OBJECT_INHERITS(thisObject
, info());
59 COMPILE_ASSERT(StructureFlags
& OverridesVisitChildren
, OverridesVisitChildrenWithoutSettingFlag
);
60 ASSERT(thisObject
->structure()->typeInfo().overridesVisitChildren());
62 InternalFunction::visitChildren(thisObject
, visitor
);
63 visitor
.append(&thisObject
->m_errorStructure
);
66 EncodedJSValue JSC_HOST_CALL
Interpreter::constructWithNativeErrorConstructor(ExecState
* exec
)
68 JSValue message
= exec
->argument(0);
69 Structure
* errorStructure
= static_cast<NativeErrorConstructor
*>(exec
->callee())->errorStructure();
70 ASSERT(errorStructure
);
71 Vector
<StackFrame
> stackTrace
;
72 exec
->vm().interpreter
->getStackTrace(stackTrace
, std::numeric_limits
<size_t>::max());
74 return JSValue::encode(ErrorInstance::create(exec
, errorStructure
, message
, stackTrace
));
77 ConstructType
NativeErrorConstructor::getConstructData(JSCell
*, ConstructData
& constructData
)
79 constructData
.native
.function
= Interpreter::constructWithNativeErrorConstructor
;
80 return ConstructTypeHost
;
83 EncodedJSValue JSC_HOST_CALL
Interpreter::callNativeErrorConstructor(ExecState
* exec
)
85 JSValue message
= exec
->argument(0);
86 Structure
* errorStructure
= static_cast<NativeErrorConstructor
*>(exec
->callee())->errorStructure();
87 Vector
<StackFrame
> stackTrace
;
88 exec
->vm().interpreter
->getStackTrace(stackTrace
, std::numeric_limits
<size_t>::max());
90 return JSValue::encode(ErrorInstance::create(exec
, errorStructure
, message
, stackTrace
));
93 CallType
NativeErrorConstructor::getCallData(JSCell
*, CallData
& callData
)
95 callData
.native
.function
= Interpreter::callNativeErrorConstructor
;