blob: 1ef60665f5242cb0ac0662bfe950393b2aa6f971 [file] [log] [blame]
ggaren08d9eec2006-07-02 04:06:07 +00001/*
mark.lam@apple.comaaf30212021-11-12 18:15:56 +00002 * Copyright (C) 2006-2021 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
darin@apple.com7f984872007-11-12 23:04:41 +000026#include "config.h"
ggaren08d9eec2006-07-02 04:06:07 +000027#include "JSCallbackFunction.h"
weinigab5f09e2006-07-29 23:15:25 +000028
oliver@apple.com5109edb2013-07-25 04:03:12 +000029#include "APICallbackFunction.h"
ross.kirsling@sony.come257a3b2020-05-19 23:56:00 +000030#include "JSCInlines.h"
ggaren08d9eec2006-07-02 04:06:07 +000031
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000032namespace JSC {
ggaren08d9eec2006-07-02 04:06:07 +000033
andersca@apple.com7de5aae2013-09-05 20:12:23 +000034STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSCallbackFunction);
ggaren@apple.comfea43532008-08-17 20:23:49 +000035
cdumez@apple.com1392b8b2022-03-24 01:40:35 +000036const ClassInfo JSCallbackFunction::s_info = { "CallbackFunction"_s, &InternalFunction::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCallbackFunction) };
ggaren08d9eec2006-07-02 04:06:07 +000037
ysuzuki@apple.com5299a3a2020-09-25 21:32:22 +000038static JSC_DECLARE_HOST_FUNCTION(callJSCallbackFunction);
39
40JSC_DEFINE_HOST_FUNCTION(callJSCallbackFunction, (JSGlobalObject* globalObject, CallFrame* callFrame))
ysuzuki@apple.com316018b2020-09-24 05:59:46 +000041{
42 return APICallbackFunction::callImpl<JSCallbackFunction>(globalObject, callFrame);
43}
44
akling@apple.com59875522013-09-30 03:45:30 +000045JSCallbackFunction::JSCallbackFunction(VM& vm, Structure* structure, JSObjectCallAsFunctionCallback callback)
ysuzuki@apple.com316018b2020-09-24 05:59:46 +000046 : InternalFunction(vm, structure, callJSCallbackFunction, nullptr)
ggaren08d9eec2006-07-02 04:06:07 +000047 , m_callback(callback)
48{
mhahnenberg@apple.com7317a7f2011-09-09 21:43:14 +000049}
50
ggaren@apple.com9a9a4b52013-04-18 19:32:17 +000051void JSCallbackFunction::finishCreation(VM& vm, const String& name)
mhahnenberg@apple.com7317a7f2011-09-09 21:43:14 +000052{
keith_miller@apple.com10a495f2020-09-21 20:41:07 +000053 Base::finishCreation(vm, 0, name);
ysuzuki@apple.com984775d2022-04-16 00:00:35 +000054 ASSERT(inherits(info()));
ggaren08d9eec2006-07-02 04:06:07 +000055}
56
akling@apple.com59875522013-09-30 03:45:30 +000057JSCallbackFunction* JSCallbackFunction::create(VM& vm, JSGlobalObject* globalObject, JSObjectCallAsFunctionCallback callback, const String& name)
mhahnenberg@apple.com9c4b2102013-03-14 21:14:01 +000058{
fpizlo@apple.comcff2d0c2016-05-04 21:21:36 +000059 Structure* structure = globalObject->callbackFunctionStructure();
mark.lam@apple.comaaf30212021-11-12 18:15:56 +000060 JSCallbackFunction* function = new (NotNull, allocateCell<JSCallbackFunction>(vm)) JSCallbackFunction(vm, structure, callback);
akling@apple.com59875522013-09-30 03:45:30 +000061 function->finishCreation(vm, name);
mhahnenberg@apple.com9c4b2102013-03-14 21:14:01 +000062 return function;
63}
64
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000065} // namespace JSC