blob: d2792f8691b34668bc5e7bb391305373b8f761a8 [file] [log] [blame]
ggaren08d9eec2006-07-02 04:06:07 +00001/*
darin@apple.com1edff432008-06-24 05:23:17 +00002 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
ggaren08d9eec2006-07-02 04:06:07 +00003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
mjs@apple.com92047332014-03-15 04:08:27 +000013 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
ggaren08d9eec2006-07-02 04:06:07 +000014 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
mjs@apple.com92047332014-03-15 04:08:27 +000016 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
ggaren08d9eec2006-07-02 04:06:07 +000017 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef JSCallbackConstructor_h
27#define JSCallbackConstructor_h
28
29#include "JSObjectRef.h"
mhahnenberg@apple.com30738a72012-10-03 17:51:28 +000030#include "runtime/JSDestructibleObject.h"
ggaren08d9eec2006-07-02 04:06:07 +000031
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000032namespace JSC {
ggaren55ae6eb2006-07-17 08:20:28 +000033
mhahnenberg@apple.com30738a72012-10-03 17:51:28 +000034class JSCallbackConstructor : public JSDestructibleObject {
oliver@apple.comfcacd3c2011-07-18 17:47:13 +000035public:
mhahnenberg@apple.com30738a72012-10-03 17:51:28 +000036 typedef JSDestructibleObject Base;
commit-queue@webkit.org6c25c522011-08-09 20:46:17 +000037
oliver@apple.comfcacd3c2011-07-18 17:47:13 +000038 static JSCallbackConstructor* create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, JSClassRef classRef, JSObjectCallAsConstructorCallback callback)
39 {
ggaren@apple.com215589e2011-12-19 17:45:13 +000040 JSCallbackConstructor* constructor = new (NotNull, allocateCell<JSCallbackConstructor>(*exec->heap())) JSCallbackConstructor(globalObject, structure, classRef, callback);
mhahnenberg@apple.com7317a7f2011-09-09 21:43:14 +000041 constructor->finishCreation(globalObject, classRef);
42 return constructor;
oliver@apple.comfcacd3c2011-07-18 17:47:13 +000043 }
44
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +000045 ~JSCallbackConstructor();
46 static void destroy(JSCell*);
darin@apple.com1edff432008-06-24 05:23:17 +000047 JSClassRef classRef() const { return m_class; }
48 JSObjectCallAsConstructorCallback callback() const { return m_callback; }
fpizlo@apple.com10ae2d02013-08-14 02:41:47 +000049 DECLARE_INFO;
barraclough@apple.coma5540da2011-02-19 21:55:44 +000050
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +000051 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto)
barraclough@apple.coma5540da2011-02-19 21:55:44 +000052 {
fpizlo@apple.com10ae2d02013-08-14 02:41:47 +000053 return Structure::create(vm, globalObject, proto, TypeInfo(ObjectType, StructureFlags), info());
mjs@apple.com221b4752008-09-22 15:03:52 +000054 }
55
oliver@apple.come9eda782009-10-17 01:06:40 +000056protected:
commit-queue@webkit.org6c25c522011-08-09 20:46:17 +000057 JSCallbackConstructor(JSGlobalObject*, Structure*, JSClassRef, JSObjectCallAsConstructorCallback);
commit-queue@webkit.org6e5671b2011-09-01 23:49:23 +000058 void finishCreation(JSGlobalObject*, JSClassRef);
oliver@apple.come9eda782009-10-17 01:06:40 +000059 static const unsigned StructureFlags = ImplementsHasInstance | JSObject::StructureFlags;
60
ggaren08d9eec2006-07-02 04:06:07 +000061private:
mhahnenberg@apple.com2ac93f32013-10-10 18:20:13 +000062 friend struct APICallbackFunction;
63
mhahnenberg@apple.com79c8e6e2011-10-08 23:26:41 +000064 static ConstructType getConstructData(JSCell*, ConstructData&);
ggaren0503a4b2006-07-18 04:33:46 +000065
mhahnenberg@apple.com2ac93f32013-10-10 18:20:13 +000066 JSObjectCallAsConstructorCallback constructCallback() { return m_callback; }
67
ggaren0503a4b2006-07-18 04:33:46 +000068 JSClassRef m_class;
ggarene66ccee2006-07-12 08:12:08 +000069 JSObjectCallAsConstructorCallback m_callback;
ggaren08d9eec2006-07-02 04:06:07 +000070};
71
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000072} // namespace JSC
ggaren08d9eec2006-07-02 04:06:07 +000073
74#endif // JSCallbackConstructor_h