1/*
2 * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
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 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
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 JSFunctionInlines_h
27#define JSFunctionInlines_h
28
29#include "Executable.h"
30#include "JSFunction.h"
31
32namespace JSC {
33
34inline JSFunction* JSFunction::createWithInvalidatedReallocationWatchpoint(
35 VM& vm, FunctionExecutable* executable, JSScope* scope)
36{
37 ASSERT(executable->singletonFunction()->hasBeenInvalidated());
38 return createImpl(vm, executable, scope, scope->globalObject()->functionStructure());
39}
40
41inline JSFunction::JSFunction(VM& vm, FunctionExecutable* executable, JSScope* scope, Structure* structure)
42 : Base(vm, scope, structure)
43 , m_executable(vm, this, executable)
44 , m_rareData()
45{
46}
47
48#if ENABLE(WEBASSEMBLY)
49inline JSFunction::JSFunction(VM& vm, WebAssemblyExecutable* executable, JSScope* scope)
50 : Base(vm, scope, scope->globalObject()->functionStructure())
51 , m_executable(vm, this, executable)
52 , m_rareData()
53{
54}
55#endif
56
57inline FunctionExecutable* JSFunction::jsExecutable() const
58{
59 ASSERT(!isHostFunctionNonInline());
60 return static_cast<FunctionExecutable*>(m_executable.get());
61}
62
63inline bool JSFunction::isHostFunction() const
64{
65 ASSERT(m_executable);
66 return m_executable->isHostFunction();
67}
68
69inline Intrinsic JSFunction::intrinsic() const
70{
71 return executable()->intrinsic();
72}
73
74inline bool JSFunction::isBuiltinFunction() const
75{
76#if ENABLE(WEBASSEMBLY)
77 if (m_executable->isWebAssemblyExecutable())
78 return false;
79#endif
80 return !isHostFunction() && jsExecutable()->isBuiltinFunction();
81}
82
83inline bool JSFunction::isHostOrBuiltinFunction() const
84{
85 return isHostFunction() || isBuiltinFunction();
86}
87
88inline bool JSFunction::isClassConstructorFunction() const
89{
90 return !isHostFunction() && jsExecutable()->isClassConstructorFunction();
91}
92
93inline NativeFunction JSFunction::nativeFunction()
94{
95 ASSERT(isHostFunctionNonInline());
96 return static_cast<NativeExecutable*>(m_executable.get())->function();
97}
98
99inline NativeFunction JSFunction::nativeConstructor()
100{
101 ASSERT(isHostFunctionNonInline());
102 return static_cast<NativeExecutable*>(m_executable.get())->constructor();
103}
104
105inline bool isHostFunction(JSValue value, NativeFunction nativeFunction)
106{
107 JSFunction* function = jsCast<JSFunction*>(getJSFunction(value));
108 if (!function || !function->isHostFunction())
109 return false;
110 return function->nativeFunction() == nativeFunction;
111}
112
113} // namespace JSC
114
115#endif // JSFunctionInlines_h
116
117