blob: fedbc133ef63d7167c7fd0763aea34c9dddc7887 [file] [log] [blame]
oliver@apple.com37172f82013-07-25 04:01:17 +00001/*
mark.lam@apple.coma925f8a2018-03-12 21:06:42 +00002 * Copyright (C) 2013-2018 Apple Inc. All rights reserved.
oliver@apple.com37172f82013-07-25 04:01:17 +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 *
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
ryanhaddad@apple.com22104f52016-09-28 17:08:17 +000026#pragma once
oliver@apple.com37172f82013-07-25 04:01:17 +000027
ggaren@apple.comc9a6ef42016-10-28 20:04:56 +000028#include "FunctionExecutable.h"
oliver@apple.com37172f82013-07-25 04:01:17 +000029#include "JSFunction.h"
ggaren@apple.comc9a6ef42016-10-28 20:04:56 +000030#include "NativeExecutable.h"
oliver@apple.com37172f82013-07-25 04:01:17 +000031
32namespace JSC {
33
fpizlo@apple.com3a2fa4c2015-04-13 22:13:12 +000034inline JSFunction* JSFunction::createWithInvalidatedReallocationWatchpoint(
35 VM& vm, FunctionExecutable* executable, JSScope* scope)
36{
37 ASSERT(executable->singletonFunction()->hasBeenInvalidated());
sbarati@apple.com916649b2017-12-14 04:10:02 +000038 return createImpl(vm, executable, scope, selectStructureForNewFuncExp(scope->globalObject(vm), executable));
fpizlo@apple.com3a2fa4c2015-04-13 22:13:12 +000039}
40
commit-queue@webkit.orga4201b02015-08-17 22:24:20 +000041inline 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{
sbarati@apple.com5ddf6402018-05-17 01:49:24 +000046 assertTypeInfoFlagInvariants();
commit-queue@webkit.orga4201b02015-08-17 22:24:20 +000047}
oliver@apple.com37172f82013-07-25 04:01:17 +000048
49inline FunctionExecutable* JSFunction::jsExecutable() const
50{
51 ASSERT(!isHostFunctionNonInline());
52 return static_cast<FunctionExecutable*>(m_executable.get());
53}
54
55inline bool JSFunction::isHostFunction() const
56{
57 ASSERT(m_executable);
58 return m_executable->isHostFunction();
59}
60
keith_miller@apple.com59bba5d2015-10-16 22:18:42 +000061inline Intrinsic JSFunction::intrinsic() const
62{
63 return executable()->intrinsic();
64}
65
mhahnenberg@apple.comff62ccb2014-06-09 18:53:32 +000066inline bool JSFunction::isBuiltinFunction() const
67{
68 return !isHostFunction() && jsExecutable()->isBuiltinFunction();
69}
70
71inline bool JSFunction::isHostOrBuiltinFunction() const
72{
73 return isHostFunction() || isBuiltinFunction();
74}
75
joepeck@webkit.org31c46502015-03-27 01:42:37 +000076inline bool JSFunction::isClassConstructorFunction() const
77{
78 return !isHostFunction() && jsExecutable()->isClassConstructorFunction();
79}
80
mark.lam@apple.coma925f8a2018-03-12 21:06:42 +000081inline TaggedNativeFunction JSFunction::nativeFunction()
oliver@apple.com37172f82013-07-25 04:01:17 +000082{
oliver@apple.comba848d12014-02-12 17:14:23 +000083 ASSERT(isHostFunctionNonInline());
oliver@apple.com37172f82013-07-25 04:01:17 +000084 return static_cast<NativeExecutable*>(m_executable.get())->function();
85}
86
mark.lam@apple.coma925f8a2018-03-12 21:06:42 +000087inline TaggedNativeFunction JSFunction::nativeConstructor()
oliver@apple.com37172f82013-07-25 04:01:17 +000088{
oliver@apple.comba848d12014-02-12 17:14:23 +000089 ASSERT(isHostFunctionNonInline());
oliver@apple.com37172f82013-07-25 04:01:17 +000090 return static_cast<NativeExecutable*>(m_executable.get())->constructor();
91}
92
mark.lam@apple.coma925f8a2018-03-12 21:06:42 +000093inline bool isHostFunction(JSValue value, TaggedNativeFunction nativeFunction)
oliver@apple.comba848d12014-02-12 17:14:23 +000094{
95 JSFunction* function = jsCast<JSFunction*>(getJSFunction(value));
96 if (!function || !function->isHostFunction())
97 return false;
98 return function->nativeFunction() == nativeFunction;
99}
100
mark.lam@apple.com9efa2932016-02-26 22:29:59 +0000101inline bool JSFunction::hasReifiedLength() const
102{
103 return m_rareData ? m_rareData->hasReifiedLength() : false;
104}
105
106inline bool JSFunction::hasReifiedName() const
107{
108 return m_rareData ? m_rareData->hasReifiedName() : false;
109}
110
sbarati@apple.com12c3af22018-02-20 03:45:03 +0000111inline bool JSFunction::canUseAllocationProfile()
112{
113 if (isHostFunction())
114 return false;
115
116 // If we don't have a prototype property, we're not guaranteed it's
117 // non-configurable. For example, user code can define the prototype
118 // as a getter. JS semantics require that the getter is called every
119 // time |construct| occurs with this function as new.target.
120 return jsExecutable()->hasPrototypeProperty();
121}
122
123inline FunctionRareData* JSFunction::ensureRareDataAndAllocationProfile(ExecState* exec, unsigned inlineCapacity)
124{
125 ASSERT(canUseAllocationProfile());
126 if (UNLIKELY(!m_rareData))
127 return allocateAndInitializeRareData(exec, inlineCapacity);
128 if (UNLIKELY(!m_rareData->isObjectAllocationProfileInitialized()))
129 return initializeRareData(exec, inlineCapacity);
130 return m_rareData.get();
131}
132
oliver@apple.com37172f82013-07-25 04:01:17 +0000133} // namespace JSC