]>
Commit | Line | Data |
---|---|---|
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, 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 | Base::visitChildren(thisObject, visitor); | |
60 | visitor.append(&thisObject->m_errorStructure); | |
61 | } | |
62 | ||
63 | EncodedJSValue JSC_HOST_CALL Interpreter::constructWithNativeErrorConstructor(ExecState* exec) | |
64 | { | |
65 | JSValue message = exec->argument(0); | |
66 | Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure(); | |
67 | ASSERT(errorStructure); | |
68 | return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, nullptr, TypeNothing, false)); | |
69 | } | |
70 | ||
71 | ConstructType NativeErrorConstructor::getConstructData(JSCell*, ConstructData& constructData) | |
72 | { | |
73 | constructData.native.function = Interpreter::constructWithNativeErrorConstructor; | |
74 | return ConstructTypeHost; | |
75 | } | |
76 | ||
77 | EncodedJSValue JSC_HOST_CALL Interpreter::callNativeErrorConstructor(ExecState* exec) | |
78 | { | |
79 | JSValue message = exec->argument(0); | |
80 | Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure(); | |
81 | return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, nullptr, TypeNothing, false)); | |
82 | } | |
83 | ||
84 | CallType NativeErrorConstructor::getCallData(JSCell*, CallData& callData) | |
85 | { | |
86 | callData.native.function = Interpreter::callNativeErrorConstructor; | |
87 | return CallTypeHost; | |
88 | } | |
89 | ||
90 | } // namespace JSC |