]> git.saurik.com Git - apple/javascriptcore.git/blob - runtime/NativeErrorConstructor.cpp
JavaScriptCore-7600.1.4.16.1.tar.gz
[apple/javascriptcore.git] / runtime / NativeErrorConstructor.cpp
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 #include "JSCInlines.h"
29
30 namespace JSC {
31
32 STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(NativeErrorConstructor);
33
34 const ClassInfo NativeErrorConstructor::s_info = { "Function", &InternalFunction::s_info, 0, 0, CREATE_METHOD_TABLE(NativeErrorConstructor) };
35
36 NativeErrorConstructor::NativeErrorConstructor(VM& vm, Structure* structure)
37 : InternalFunction(vm, structure)
38 {
39 }
40
41 void NativeErrorConstructor::finishCreation(VM& vm, JSGlobalObject* globalObject, Structure* prototypeStructure, const String& name)
42 {
43 Base::finishCreation(vm, name);
44 ASSERT(inherits(info()));
45
46 NativeErrorPrototype* prototype = NativeErrorPrototype::create(vm, globalObject, prototypeStructure, name, this);
47
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());
53 }
54
55 void NativeErrorConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
56 {
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());
61
62 InternalFunction::visitChildren(thisObject, visitor);
63 visitor.append(&thisObject->m_errorStructure);
64 }
65
66 EncodedJSValue JSC_HOST_CALL Interpreter::constructWithNativeErrorConstructor(ExecState* exec)
67 {
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());
73 stackTrace.remove(0);
74 return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, stackTrace));
75 }
76
77 ConstructType NativeErrorConstructor::getConstructData(JSCell*, ConstructData& constructData)
78 {
79 constructData.native.function = Interpreter::constructWithNativeErrorConstructor;
80 return ConstructTypeHost;
81 }
82
83 EncodedJSValue JSC_HOST_CALL Interpreter::callNativeErrorConstructor(ExecState* exec)
84 {
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());
89 stackTrace.remove(0);
90 return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, stackTrace));
91 }
92
93 CallType NativeErrorConstructor::getCallData(JSCell*, CallData& callData)
94 {
95 callData.native.function = Interpreter::callNativeErrorConstructor;
96 return CallTypeHost;
97 }
98
99 } // namespace JSC