]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/NativeErrorConstructor.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / runtime / NativeErrorConstructor.cpp
CommitLineData
9dae56ea
A
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"
81345200 28#include "JSCInlines.h"
9dae56ea
A
29
30namespace JSC {
31
81345200 32STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(NativeErrorConstructor);
9dae56ea 33
ed1e77d3 34const ClassInfo NativeErrorConstructor::s_info = { "Function", &InternalFunction::s_info, 0, CREATE_METHOD_TABLE(NativeErrorConstructor) };
9dae56ea 35
81345200
A
36NativeErrorConstructor::NativeErrorConstructor(VM& vm, Structure* structure)
37 : InternalFunction(vm, structure)
9dae56ea 38{
14957cd0 39}
4e4e5a6f 40
81345200
A
41void 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
6fe7ccc8 55void NativeErrorConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
9dae56ea 56{
6fe7ccc8 57 NativeErrorConstructor* thisObject = jsCast<NativeErrorConstructor*>(cell);
81345200 58 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
ed1e77d3 59 Base::visitChildren(thisObject, visitor);
93a37866 60 visitor.append(&thisObject->m_errorStructure);
9dae56ea
A
61}
62
81345200 63EncodedJSValue JSC_HOST_CALL Interpreter::constructWithNativeErrorConstructor(ExecState* exec)
9dae56ea 64{
81345200 65 JSValue message = exec->argument(0);
14957cd0
A
66 Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure();
67 ASSERT(errorStructure);
ed1e77d3 68 return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, nullptr, TypeNothing, false));
9dae56ea
A
69}
70
6fe7ccc8 71ConstructType NativeErrorConstructor::getConstructData(JSCell*, ConstructData& constructData)
9dae56ea 72{
81345200 73 constructData.native.function = Interpreter::constructWithNativeErrorConstructor;
9dae56ea
A
74 return ConstructTypeHost;
75}
ba379fdc 76
81345200 77EncodedJSValue JSC_HOST_CALL Interpreter::callNativeErrorConstructor(ExecState* exec)
9dae56ea 78{
81345200 79 JSValue message = exec->argument(0);
14957cd0 80 Structure* errorStructure = static_cast<NativeErrorConstructor*>(exec->callee())->errorStructure();
ed1e77d3 81 return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, nullptr, TypeNothing, false));
9dae56ea
A
82}
83
6fe7ccc8 84CallType NativeErrorConstructor::getCallData(JSCell*, CallData& callData)
9dae56ea 85{
81345200 86 callData.native.function = Interpreter::callNativeErrorConstructor;
9dae56ea
A
87 return CallTypeHost;
88}
89
90} // namespace JSC