oliver@apple.com | 37172f8 | 2013-07-25 04:01:17 +0000 | [diff] [blame] | 1 | /* |
mark.lam@apple.com | a925f8a | 2018-03-12 21:06:42 +0000 | [diff] [blame] | 2 | * Copyright (C) 2013-2018 Apple Inc. All rights reserved. |
oliver@apple.com | 37172f8 | 2013-07-25 04:01:17 +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 | * |
| 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.com | 22104f5 | 2016-09-28 17:08:17 +0000 | [diff] [blame] | 26 | #pragma once |
oliver@apple.com | 37172f8 | 2013-07-25 04:01:17 +0000 | [diff] [blame] | 27 | |
ggaren@apple.com | c9a6ef4 | 2016-10-28 20:04:56 +0000 | [diff] [blame] | 28 | #include "FunctionExecutable.h" |
oliver@apple.com | 37172f8 | 2013-07-25 04:01:17 +0000 | [diff] [blame] | 29 | #include "JSFunction.h" |
ggaren@apple.com | c9a6ef4 | 2016-10-28 20:04:56 +0000 | [diff] [blame] | 30 | #include "NativeExecutable.h" |
oliver@apple.com | 37172f8 | 2013-07-25 04:01:17 +0000 | [diff] [blame] | 31 | |
| 32 | namespace JSC { |
| 33 | |
fpizlo@apple.com | 3a2fa4c | 2015-04-13 22:13:12 +0000 | [diff] [blame] | 34 | inline JSFunction* JSFunction::createWithInvalidatedReallocationWatchpoint( |
| 35 | VM& vm, FunctionExecutable* executable, JSScope* scope) |
| 36 | { |
| 37 | ASSERT(executable->singletonFunction()->hasBeenInvalidated()); |
sbarati@apple.com | 916649b | 2017-12-14 04:10:02 +0000 | [diff] [blame] | 38 | return createImpl(vm, executable, scope, selectStructureForNewFuncExp(scope->globalObject(vm), executable)); |
fpizlo@apple.com | 3a2fa4c | 2015-04-13 22:13:12 +0000 | [diff] [blame] | 39 | } |
| 40 | |
commit-queue@webkit.org | a4201b0 | 2015-08-17 22:24:20 +0000 | [diff] [blame] | 41 | inline 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.com | 5ddf640 | 2018-05-17 01:49:24 +0000 | [diff] [blame] | 46 | assertTypeInfoFlagInvariants(); |
commit-queue@webkit.org | a4201b0 | 2015-08-17 22:24:20 +0000 | [diff] [blame] | 47 | } |
oliver@apple.com | 37172f8 | 2013-07-25 04:01:17 +0000 | [diff] [blame] | 48 | |
| 49 | inline FunctionExecutable* JSFunction::jsExecutable() const |
| 50 | { |
| 51 | ASSERT(!isHostFunctionNonInline()); |
| 52 | return static_cast<FunctionExecutable*>(m_executable.get()); |
| 53 | } |
| 54 | |
| 55 | inline bool JSFunction::isHostFunction() const |
| 56 | { |
| 57 | ASSERT(m_executable); |
| 58 | return m_executable->isHostFunction(); |
| 59 | } |
| 60 | |
keith_miller@apple.com | 59bba5d | 2015-10-16 22:18:42 +0000 | [diff] [blame] | 61 | inline Intrinsic JSFunction::intrinsic() const |
| 62 | { |
| 63 | return executable()->intrinsic(); |
| 64 | } |
| 65 | |
mhahnenberg@apple.com | ff62ccb | 2014-06-09 18:53:32 +0000 | [diff] [blame] | 66 | inline bool JSFunction::isBuiltinFunction() const |
| 67 | { |
| 68 | return !isHostFunction() && jsExecutable()->isBuiltinFunction(); |
| 69 | } |
| 70 | |
| 71 | inline bool JSFunction::isHostOrBuiltinFunction() const |
| 72 | { |
| 73 | return isHostFunction() || isBuiltinFunction(); |
| 74 | } |
| 75 | |
joepeck@webkit.org | 31c4650 | 2015-03-27 01:42:37 +0000 | [diff] [blame] | 76 | inline bool JSFunction::isClassConstructorFunction() const |
| 77 | { |
| 78 | return !isHostFunction() && jsExecutable()->isClassConstructorFunction(); |
| 79 | } |
| 80 | |
mark.lam@apple.com | a925f8a | 2018-03-12 21:06:42 +0000 | [diff] [blame] | 81 | inline TaggedNativeFunction JSFunction::nativeFunction() |
oliver@apple.com | 37172f8 | 2013-07-25 04:01:17 +0000 | [diff] [blame] | 82 | { |
oliver@apple.com | ba848d1 | 2014-02-12 17:14:23 +0000 | [diff] [blame] | 83 | ASSERT(isHostFunctionNonInline()); |
oliver@apple.com | 37172f8 | 2013-07-25 04:01:17 +0000 | [diff] [blame] | 84 | return static_cast<NativeExecutable*>(m_executable.get())->function(); |
| 85 | } |
| 86 | |
mark.lam@apple.com | a925f8a | 2018-03-12 21:06:42 +0000 | [diff] [blame] | 87 | inline TaggedNativeFunction JSFunction::nativeConstructor() |
oliver@apple.com | 37172f8 | 2013-07-25 04:01:17 +0000 | [diff] [blame] | 88 | { |
oliver@apple.com | ba848d1 | 2014-02-12 17:14:23 +0000 | [diff] [blame] | 89 | ASSERT(isHostFunctionNonInline()); |
oliver@apple.com | 37172f8 | 2013-07-25 04:01:17 +0000 | [diff] [blame] | 90 | return static_cast<NativeExecutable*>(m_executable.get())->constructor(); |
| 91 | } |
| 92 | |
mark.lam@apple.com | a925f8a | 2018-03-12 21:06:42 +0000 | [diff] [blame] | 93 | inline bool isHostFunction(JSValue value, TaggedNativeFunction nativeFunction) |
oliver@apple.com | ba848d1 | 2014-02-12 17:14:23 +0000 | [diff] [blame] | 94 | { |
| 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.com | 9efa293 | 2016-02-26 22:29:59 +0000 | [diff] [blame] | 101 | inline bool JSFunction::hasReifiedLength() const |
| 102 | { |
| 103 | return m_rareData ? m_rareData->hasReifiedLength() : false; |
| 104 | } |
| 105 | |
| 106 | inline bool JSFunction::hasReifiedName() const |
| 107 | { |
| 108 | return m_rareData ? m_rareData->hasReifiedName() : false; |
| 109 | } |
| 110 | |
sbarati@apple.com | 12c3af2 | 2018-02-20 03:45:03 +0000 | [diff] [blame] | 111 | inline 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 | |
| 123 | inline 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.com | 37172f8 | 2013-07-25 04:01:17 +0000 | [diff] [blame] | 133 | } // namespace JSC |