blob: a0874d4a7220361c91b54dbfc8eb8e31246a1546 [file] [log] [blame]
weinig@apple.comfee62a72008-06-29 22:14:57 +00001/*
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
weinig@apple.comfee62a72008-06-29 22:14:57 +000024#include "ErrorPrototype.h"
weinig@apple.comfee62a72008-06-29 22:14:57 +000025#include "JSGlobalObject.h"
26#include "JSString.h"
27
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000028namespace JSC {
weinig@apple.comfee62a72008-06-29 22:14:57 +000029
ggaren@apple.comfea43532008-08-17 20:23:49 +000030ASSERT_CLASS_FITS_IN_CELL(ErrorConstructor);
31
oliver@apple.com5dea6152010-05-21 18:19:42 +000032ErrorConstructor::ErrorConstructor(ExecState* exec, JSGlobalObject* globalObject, NonNullPassRefPtr<Structure> structure, ErrorPrototype* errorPrototype)
33 : InternalFunction(&exec->globalData(), globalObject, structure, Identifier(exec, errorPrototype->classInfo()->className))
weinig@apple.comfee62a72008-06-29 22:14:57 +000034{
35 // ECMA 15.11.3.1 Error.prototype
weinig@apple.com5677e042008-10-20 21:27:44 +000036 putDirectWithoutTransition(exec->propertyNames().prototype, errorPrototype, DontEnum | DontDelete | ReadOnly);
37 putDirectWithoutTransition(exec->propertyNames().length, jsNumber(exec, 1), DontDelete | ReadOnly | DontEnum);
weinig@apple.comfee62a72008-06-29 22:14:57 +000038}
39
40// ECMA 15.9.3
weinig@apple.comfee62a72008-06-29 22:14:57 +000041
barraclough@apple.com11d351a2010-06-04 21:38:38 +000042static EncodedJSValue JSC_HOST_CALL constructWithErrorConstructor(ExecState* exec)
weinig@apple.comfee62a72008-06-29 22:14:57 +000043{
barraclough@apple.com9c099f92010-06-06 23:34:36 +000044 JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined();
45 Structure* errorStructure = exec->lexicalGlobalObject()->errorStructure();
46 return JSValue::encode(ErrorInstance::create(exec, errorStructure, message));
weinig@apple.comfee62a72008-06-29 22:14:57 +000047}
48
49ConstructType ErrorConstructor::getConstructData(ConstructData& constructData)
50{
51 constructData.native.function = constructWithErrorConstructor;
ggaren@apple.com9a0472b2008-07-28 20:04:48 +000052 return ConstructTypeHost;
weinig@apple.comfee62a72008-06-29 22:14:57 +000053}
54
barraclough@apple.com99ff3432010-06-03 20:00:18 +000055static EncodedJSValue JSC_HOST_CALL callErrorConstructor(ExecState* exec)
weinig@apple.comfee62a72008-06-29 22:14:57 +000056{
barraclough@apple.com9c099f92010-06-06 23:34:36 +000057 JSValue message = exec->argumentCount() ? exec->argument(0) : jsUndefined();
58 Structure* errorStructure = exec->lexicalGlobalObject()->errorStructure();
59 return JSValue::encode(ErrorInstance::create(exec, errorStructure, message));
weinig@apple.comfee62a72008-06-29 22:14:57 +000060}
61
62CallType ErrorConstructor::getCallData(CallData& callData)
63{
64 callData.native.function = callErrorConstructor;
ggaren@apple.com1914ee92008-07-18 22:18:21 +000065 return CallTypeHost;
weinig@apple.comfee62a72008-06-29 22:14:57 +000066}
67
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000068} // namespace JSC