ggaren | 08d9eec | 2006-07-02 04:06:07 +0000 | [diff] [blame] | 1 | /* |
darin@apple.com | 1edff43 | 2008-06-24 05:23:17 +0000 | [diff] [blame] | 2 | * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. |
ggaren | 08d9eec | 2006-07-02 04:06:07 +0000 | [diff] [blame] | 3 | * |
| 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.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
ggaren | 08d9eec | 2006-07-02 04:06:07 +0000 | [diff] [blame] | 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
ggaren | 08d9eec | 2006-07-02 04:06:07 +0000 | [diff] [blame] | 17 | * 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.com | 30738a7 | 2012-10-03 17:51:28 +0000 | [diff] [blame] | 30 | #include "runtime/JSDestructibleObject.h" |
ggaren | 08d9eec | 2006-07-02 04:06:07 +0000 | [diff] [blame] | 31 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 32 | namespace JSC { |
ggaren | 55ae6eb | 2006-07-17 08:20:28 +0000 | [diff] [blame] | 33 | |
mhahnenberg@apple.com | 30738a7 | 2012-10-03 17:51:28 +0000 | [diff] [blame] | 34 | class JSCallbackConstructor : public JSDestructibleObject { |
oliver@apple.com | fcacd3c | 2011-07-18 17:47:13 +0000 | [diff] [blame] | 35 | public: |
mhahnenberg@apple.com | 30738a7 | 2012-10-03 17:51:28 +0000 | [diff] [blame] | 36 | typedef JSDestructibleObject Base; |
commit-queue@webkit.org | 6c25c52 | 2011-08-09 20:46:17 +0000 | [diff] [blame] | 37 | |
oliver@apple.com | fcacd3c | 2011-07-18 17:47:13 +0000 | [diff] [blame] | 38 | static JSCallbackConstructor* create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, JSClassRef classRef, JSObjectCallAsConstructorCallback callback) |
| 39 | { |
ggaren@apple.com | 215589e | 2011-12-19 17:45:13 +0000 | [diff] [blame] | 40 | JSCallbackConstructor* constructor = new (NotNull, allocateCell<JSCallbackConstructor>(*exec->heap())) JSCallbackConstructor(globalObject, structure, classRef, callback); |
mhahnenberg@apple.com | 7317a7f | 2011-09-09 21:43:14 +0000 | [diff] [blame] | 41 | constructor->finishCreation(globalObject, classRef); |
| 42 | return constructor; |
oliver@apple.com | fcacd3c | 2011-07-18 17:47:13 +0000 | [diff] [blame] | 43 | } |
| 44 | |
mhahnenberg@apple.com | c58d54d | 2011-12-16 19:06:44 +0000 | [diff] [blame] | 45 | ~JSCallbackConstructor(); |
| 46 | static void destroy(JSCell*); |
darin@apple.com | 1edff43 | 2008-06-24 05:23:17 +0000 | [diff] [blame] | 47 | JSClassRef classRef() const { return m_class; } |
| 48 | JSObjectCallAsConstructorCallback callback() const { return m_callback; } |
fpizlo@apple.com | 10ae2d0 | 2013-08-14 02:41:47 +0000 | [diff] [blame] | 49 | DECLARE_INFO; |
barraclough@apple.com | a5540da | 2011-02-19 21:55:44 +0000 | [diff] [blame] | 50 | |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 51 | static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto) |
barraclough@apple.com | a5540da | 2011-02-19 21:55:44 +0000 | [diff] [blame] | 52 | { |
fpizlo@apple.com | 10ae2d0 | 2013-08-14 02:41:47 +0000 | [diff] [blame] | 53 | return Structure::create(vm, globalObject, proto, TypeInfo(ObjectType, StructureFlags), info()); |
mjs@apple.com | 221b475 | 2008-09-22 15:03:52 +0000 | [diff] [blame] | 54 | } |
| 55 | |
oliver@apple.com | e9eda78 | 2009-10-17 01:06:40 +0000 | [diff] [blame] | 56 | protected: |
commit-queue@webkit.org | 6c25c52 | 2011-08-09 20:46:17 +0000 | [diff] [blame] | 57 | JSCallbackConstructor(JSGlobalObject*, Structure*, JSClassRef, JSObjectCallAsConstructorCallback); |
commit-queue@webkit.org | 6e5671b | 2011-09-01 23:49:23 +0000 | [diff] [blame] | 58 | void finishCreation(JSGlobalObject*, JSClassRef); |
oliver@apple.com | e9eda78 | 2009-10-17 01:06:40 +0000 | [diff] [blame] | 59 | static const unsigned StructureFlags = ImplementsHasInstance | JSObject::StructureFlags; |
| 60 | |
ggaren | 08d9eec | 2006-07-02 04:06:07 +0000 | [diff] [blame] | 61 | private: |
mhahnenberg@apple.com | 2ac93f3 | 2013-10-10 18:20:13 +0000 | [diff] [blame] | 62 | friend struct APICallbackFunction; |
| 63 | |
mhahnenberg@apple.com | 79c8e6e | 2011-10-08 23:26:41 +0000 | [diff] [blame] | 64 | static ConstructType getConstructData(JSCell*, ConstructData&); |
ggaren | 0503a4b | 2006-07-18 04:33:46 +0000 | [diff] [blame] | 65 | |
mhahnenberg@apple.com | 2ac93f3 | 2013-10-10 18:20:13 +0000 | [diff] [blame] | 66 | JSObjectCallAsConstructorCallback constructCallback() { return m_callback; } |
| 67 | |
ggaren | 0503a4b | 2006-07-18 04:33:46 +0000 | [diff] [blame] | 68 | JSClassRef m_class; |
ggaren | e66ccee | 2006-07-12 08:12:08 +0000 | [diff] [blame] | 69 | JSObjectCallAsConstructorCallback m_callback; |
ggaren | 08d9eec | 2006-07-02 04:06:07 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 72 | } // namespace JSC |
ggaren | 08d9eec | 2006-07-02 04:06:07 +0000 | [diff] [blame] | 73 | |
| 74 | #endif // JSCallbackConstructor_h |