weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 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 | |
weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 24 | #include "ErrorPrototype.h" |
weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 25 | #include "JSGlobalObject.h" |
| 26 | #include "JSString.h" |
| 27 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 28 | namespace JSC { |
weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 29 | |
ggaren@apple.com | fea4353 | 2008-08-17 20:23:49 +0000 | [diff] [blame] | 30 | ASSERT_CLASS_FITS_IN_CELL(ErrorConstructor); |
| 31 | |
oliver@apple.com | 5dea615 | 2010-05-21 18:19:42 +0000 | [diff] [blame] | 32 | ErrorConstructor::ErrorConstructor(ExecState* exec, JSGlobalObject* globalObject, NonNullPassRefPtr<Structure> structure, ErrorPrototype* errorPrototype) |
| 33 | : InternalFunction(&exec->globalData(), globalObject, structure, Identifier(exec, errorPrototype->classInfo()->className)) |
weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 34 | { |
| 35 | // ECMA 15.11.3.1 Error.prototype |
weinig@apple.com | 5677e04 | 2008-10-20 21:27:44 +0000 | [diff] [blame] | 36 | putDirectWithoutTransition(exec->propertyNames().prototype, errorPrototype, DontEnum | DontDelete | ReadOnly); |
| 37 | putDirectWithoutTransition(exec->propertyNames().length, jsNumber(exec, 1), DontDelete | ReadOnly | DontEnum); |
weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | // ECMA 15.9.3 |
weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 41 | |
barraclough@apple.com | 11d351a | 2010-06-04 21:38:38 +0000 | [diff] [blame] | 42 | static EncodedJSValue JSC_HOST_CALL constructWithErrorConstructor(ExecState* exec) |
weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 43 | { |
barraclough@apple.com | 9c099f9 | 2010-06-06 23:34:36 +0000 | [diff] [blame] | 44 | 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.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | ConstructType ErrorConstructor::getConstructData(ConstructData& constructData) |
| 50 | { |
| 51 | constructData.native.function = constructWithErrorConstructor; |
ggaren@apple.com | 9a0472b | 2008-07-28 20:04:48 +0000 | [diff] [blame] | 52 | return ConstructTypeHost; |
weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 53 | } |
| 54 | |
barraclough@apple.com | 99ff343 | 2010-06-03 20:00:18 +0000 | [diff] [blame] | 55 | static EncodedJSValue JSC_HOST_CALL callErrorConstructor(ExecState* exec) |
weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 56 | { |
barraclough@apple.com | 9c099f9 | 2010-06-06 23:34:36 +0000 | [diff] [blame] | 57 | 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.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | CallType ErrorConstructor::getCallData(CallData& callData) |
| 63 | { |
| 64 | callData.native.function = callErrorConstructor; |
ggaren@apple.com | 1914ee9 | 2008-07-18 22:18:21 +0000 | [diff] [blame] | 65 | return CallTypeHost; |
weinig@apple.com | fee62a7 | 2008-06-29 22:14:57 +0000 | [diff] [blame] | 66 | } |
| 67 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 68 | } // namespace JSC |