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