ggaren | 08d9eec | 2006-07-02 04:06:07 +0000 | [diff] [blame] | 1 | /* |
mark.lam@apple.com | aaf3021 | 2021-11-12 18:15:56 +0000 | [diff] [blame] | 2 | * Copyright (C) 2006-2021 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 | |
darin@apple.com | 7f98487 | 2007-11-12 23:04:41 +0000 | [diff] [blame] | 26 | #include "config.h" |
ggaren | 08d9eec | 2006-07-02 04:06:07 +0000 | [diff] [blame] | 27 | #include "JSCallbackFunction.h" |
weinig | ab5f09e | 2006-07-29 23:15:25 +0000 | [diff] [blame] | 28 | |
oliver@apple.com | 5109edb | 2013-07-25 04:03:12 +0000 | [diff] [blame] | 29 | #include "APICallbackFunction.h" |
ross.kirsling@sony.com | e257a3b | 2020-05-19 23:56:00 +0000 | [diff] [blame] | 30 | #include "JSCInlines.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 | 08d9eec | 2006-07-02 04:06:07 +0000 | [diff] [blame] | 33 | |
andersca@apple.com | 7de5aae | 2013-09-05 20:12:23 +0000 | [diff] [blame] | 34 | STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSCallbackFunction); |
ggaren@apple.com | fea4353 | 2008-08-17 20:23:49 +0000 | [diff] [blame] | 35 | |
cdumez@apple.com | 1392b8b | 2022-03-24 01:40:35 +0000 | [diff] [blame] | 36 | const ClassInfo JSCallbackFunction::s_info = { "CallbackFunction"_s, &InternalFunction::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCallbackFunction) }; |
ggaren | 08d9eec | 2006-07-02 04:06:07 +0000 | [diff] [blame] | 37 | |
ysuzuki@apple.com | 5299a3a | 2020-09-25 21:32:22 +0000 | [diff] [blame] | 38 | static JSC_DECLARE_HOST_FUNCTION(callJSCallbackFunction); |
| 39 | |
| 40 | JSC_DEFINE_HOST_FUNCTION(callJSCallbackFunction, (JSGlobalObject* globalObject, CallFrame* callFrame)) |
ysuzuki@apple.com | 316018b | 2020-09-24 05:59:46 +0000 | [diff] [blame] | 41 | { |
| 42 | return APICallbackFunction::callImpl<JSCallbackFunction>(globalObject, callFrame); |
| 43 | } |
| 44 | |
akling@apple.com | 5987552 | 2013-09-30 03:45:30 +0000 | [diff] [blame] | 45 | JSCallbackFunction::JSCallbackFunction(VM& vm, Structure* structure, JSObjectCallAsFunctionCallback callback) |
ysuzuki@apple.com | 316018b | 2020-09-24 05:59:46 +0000 | [diff] [blame] | 46 | : InternalFunction(vm, structure, callJSCallbackFunction, nullptr) |
ggaren | 08d9eec | 2006-07-02 04:06:07 +0000 | [diff] [blame] | 47 | , m_callback(callback) |
| 48 | { |
mhahnenberg@apple.com | 7317a7f | 2011-09-09 21:43:14 +0000 | [diff] [blame] | 49 | } |
| 50 | |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 51 | void JSCallbackFunction::finishCreation(VM& vm, const String& name) |
mhahnenberg@apple.com | 7317a7f | 2011-09-09 21:43:14 +0000 | [diff] [blame] | 52 | { |
keith_miller@apple.com | 10a495f | 2020-09-21 20:41:07 +0000 | [diff] [blame] | 53 | Base::finishCreation(vm, 0, name); |
ysuzuki@apple.com | 984775d | 2022-04-16 00:00:35 +0000 | [diff] [blame] | 54 | ASSERT(inherits(info())); |
ggaren | 08d9eec | 2006-07-02 04:06:07 +0000 | [diff] [blame] | 55 | } |
| 56 | |
akling@apple.com | 5987552 | 2013-09-30 03:45:30 +0000 | [diff] [blame] | 57 | JSCallbackFunction* JSCallbackFunction::create(VM& vm, JSGlobalObject* globalObject, JSObjectCallAsFunctionCallback callback, const String& name) |
mhahnenberg@apple.com | 9c4b210 | 2013-03-14 21:14:01 +0000 | [diff] [blame] | 58 | { |
fpizlo@apple.com | cff2d0c | 2016-05-04 21:21:36 +0000 | [diff] [blame] | 59 | Structure* structure = globalObject->callbackFunctionStructure(); |
mark.lam@apple.com | aaf3021 | 2021-11-12 18:15:56 +0000 | [diff] [blame] | 60 | JSCallbackFunction* function = new (NotNull, allocateCell<JSCallbackFunction>(vm)) JSCallbackFunction(vm, structure, callback); |
akling@apple.com | 5987552 | 2013-09-30 03:45:30 +0000 | [diff] [blame] | 61 | function->finishCreation(vm, name); |
mhahnenberg@apple.com | 9c4b210 | 2013-03-14 21:14:01 +0000 | [diff] [blame] | 62 | return function; |
| 63 | } |
| 64 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 65 | } // namespace JSC |