]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/ErrorConstructor.cpp
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / runtime / ErrorConstructor.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 "ErrorConstructor.h"
23
24#include "ErrorPrototype.h"
81345200 25#include "Interpreter.h"
9dae56ea
A
26#include "JSGlobalObject.h"
27#include "JSString.h"
81345200 28#include "JSCInlines.h"
9dae56ea
A
29
30namespace JSC {
31
81345200 32STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(ErrorConstructor);
9dae56ea 33
ed1e77d3 34const ClassInfo ErrorConstructor::s_info = { "Function", &Base::s_info, 0, CREATE_METHOD_TABLE(ErrorConstructor) };
6fe7ccc8 35
81345200
A
36ErrorConstructor::ErrorConstructor(VM& vm, Structure* structure)
37 : InternalFunction(vm, structure)
6fe7ccc8
A
38{
39}
40
81345200 41void ErrorConstructor::finishCreation(VM& vm, ErrorPrototype* errorPrototype)
9dae56ea 42{
81345200 43 Base::finishCreation(vm, errorPrototype->classInfo()->className);
9dae56ea 44 // ECMA 15.11.3.1 Error.prototype
81345200
A
45 putDirectWithoutTransition(vm, vm.propertyNames->prototype, errorPrototype, DontEnum | DontDelete | ReadOnly);
46 putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), DontDelete | ReadOnly | DontEnum);
9dae56ea
A
47}
48
49// ECMA 15.9.3
9dae56ea 50
81345200 51EncodedJSValue JSC_HOST_CALL Interpreter::constructWithErrorConstructor(ExecState* exec)
9dae56ea 52{
14957cd0
A
53 JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined();
54 Structure* errorStructure = asInternalFunction(exec->callee())->globalObject()->errorStructure();
ed1e77d3 55 return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, nullptr, TypeNothing, false));
9dae56ea
A
56}
57
6fe7ccc8 58ConstructType ErrorConstructor::getConstructData(JSCell*, ConstructData& constructData)
9dae56ea 59{
81345200 60 constructData.native.function = Interpreter::constructWithErrorConstructor;
9dae56ea
A
61 return ConstructTypeHost;
62}
63
81345200 64EncodedJSValue JSC_HOST_CALL Interpreter::callErrorConstructor(ExecState* exec)
9dae56ea 65{
14957cd0
A
66 JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined();
67 Structure* errorStructure = asInternalFunction(exec->callee())->globalObject()->errorStructure();
ed1e77d3 68 return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, nullptr, TypeNothing, false));
9dae56ea
A
69}
70
6fe7ccc8 71CallType ErrorConstructor::getCallData(JSCell*, CallData& callData)
9dae56ea 72{
81345200 73 callData.native.function = Interpreter::callErrorConstructor;
9dae56ea
A
74 return CallTypeHost;
75}
76
77} // namespace JSC