kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 1 | /* |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 2 | * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) |
fpizlo@apple.com | c5108b0 | 2015-02-23 18:13:41 +0000 | [diff] [blame] | 3 | * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2015 Apple Inc. All rights reserved. |
ggaren | 6c0384f | 2007-10-29 05:32:23 +0000 | [diff] [blame] | 4 | * Copyright (C) 2007 Cameron Zwarich (cwzwarich@uwaterloo.ca) |
| 5 | * Copyright (C) 2007 Maks Orlovich |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Library General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Library General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Library General Public License |
| 18 | * along with this library; see the file COPYING.LIB. If not, write to |
mjs | cdff33b | 2006-01-23 21:41:36 +0000 | [diff] [blame] | 19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
ggaren | 07d4ce6 | 2005-07-14 18:27:04 +0000 | [diff] [blame] | 20 | * Boston, MA 02110-1301, USA. |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 21 | * |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 22 | */ |
| 23 | |
darin@apple.com | 5c0863d | 2008-06-16 04:17:44 +0000 | [diff] [blame] | 24 | #ifndef JSFunction_h |
| 25 | #define JSFunction_h |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 26 | |
commit-queue@webkit.org | cc894b0 | 2015-04-16 19:15:09 +0000 | [diff] [blame] | 27 | #include "FunctionRareData.h" |
barraclough@apple.com | 484a9d3 | 2012-03-22 18:54:50 +0000 | [diff] [blame] | 28 | #include "InternalFunction.h" |
msaboff@apple.com | 42142a1 | 2014-09-11 21:52:33 +0000 | [diff] [blame] | 29 | #include "JSCallee.h" |
ggaren@apple.com | b11e787 | 2012-08-30 22:50:00 +0000 | [diff] [blame] | 30 | #include "JSScope.h" |
fpizlo@apple.com | f5db15e | 2012-11-14 07:22:57 +0000 | [diff] [blame] | 31 | #include "Watchpoint.h" |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 32 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 33 | namespace JSC { |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 34 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 35 | class ExecutableBase; |
| 36 | class FunctionExecutable; |
| 37 | class FunctionPrototype; |
oliver@apple.com | a7dfb4d | 2014-09-11 18:18:14 +0000 | [diff] [blame] | 38 | class JSLexicalEnvironment; |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 39 | class JSGlobalObject; |
| 40 | class LLIntOffsetsExtractor; |
| 41 | class NativeExecutable; |
| 42 | class SourceCode; |
commit-queue@webkit.org | fa19663 | 2015-08-28 21:07:22 +0000 | [diff] [blame] | 43 | class WebAssemblyExecutable; |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 44 | namespace DFG { |
| 45 | class SpeculativeJIT; |
| 46 | class JITCompiler; |
| 47 | } |
| 48 | |
| 49 | JS_EXPORT_PRIVATE EncodedJSValue JSC_HOST_CALL callHostFunctionAsConstructor(ExecState*); |
| 50 | |
| 51 | JS_EXPORT_PRIVATE String getCalculatedDisplayName(CallFrame*, JSObject*); |
commit-queue@webkit.org | cc894b0 | 2015-04-16 19:15:09 +0000 | [diff] [blame] | 52 | |
msaboff@apple.com | 42142a1 | 2014-09-11 21:52:33 +0000 | [diff] [blame] | 53 | class JSFunction : public JSCallee { |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 54 | friend class JIT; |
| 55 | friend class DFG::SpeculativeJIT; |
| 56 | friend class DFG::JITCompiler; |
| 57 | friend class VM; |
| 58 | |
| 59 | public: |
msaboff@apple.com | 42142a1 | 2014-09-11 21:52:33 +0000 | [diff] [blame] | 60 | typedef JSCallee Base; |
akling@apple.com | 4b9e000 | 2015-04-13 19:12:48 +0000 | [diff] [blame] | 61 | const static unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | OverridesGetPropertyNames; |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 62 | |
commit-queue@webkit.org | 14aa054 | 2015-04-17 00:44:58 +0000 | [diff] [blame] | 63 | static size_t allocationSize(size_t inlineCapacity) |
| 64 | { |
| 65 | ASSERT_UNUSED(inlineCapacity, !inlineCapacity); |
| 66 | return sizeof(JSFunction); |
| 67 | } |
| 68 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 69 | JS_EXPORT_PRIVATE static JSFunction* create(VM&, JSGlobalObject*, int length, const String& name, NativeFunction, Intrinsic = NoIntrinsic, NativeFunction nativeConstructor = callHostFunctionAsConstructor); |
fpizlo@apple.com | 3a2fa4c | 2015-04-13 22:13:12 +0000 | [diff] [blame] | 70 | |
| 71 | static JSFunction* createWithInvalidatedReallocationWatchpoint(VM&, FunctionExecutable*, JSScope*); |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 72 | |
fpizlo@apple.com | 3a2fa4c | 2015-04-13 22:13:12 +0000 | [diff] [blame] | 73 | static JSFunction* create(VM&, FunctionExecutable*, JSScope*); |
commit-queue@webkit.org | fa19663 | 2015-08-28 21:07:22 +0000 | [diff] [blame] | 74 | #if ENABLE(WEBASSEMBLY) |
| 75 | static JSFunction* create(VM&, WebAssemblyExecutable*, JSScope*); |
| 76 | #endif |
bdash | 53ebcaf | 2007-05-30 12:19:36 +0000 | [diff] [blame] | 77 | |
youenn.fablet@crf.canon.fr | fafcd04 | 2015-09-24 09:18:15 +0000 | [diff] [blame] | 78 | JS_EXPORT_PRIVATE static JSFunction* createBuiltinFunction(VM&, FunctionExecutable*, JSGlobalObject*); |
utatane.tea@gmail.com | de247cf | 2015-06-16 02:11:41 +0000 | [diff] [blame] | 79 | static JSFunction* createBuiltinFunction(VM&, FunctionExecutable*, JSGlobalObject*, const String& name); |
barraclough@apple.com | fd8c28a | 2010-05-25 03:04:43 +0000 | [diff] [blame] | 80 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 81 | JS_EXPORT_PRIVATE String name(ExecState*); |
| 82 | JS_EXPORT_PRIVATE String displayName(ExecState*); |
| 83 | const String calculatedDisplayName(ExecState*); |
commit-queue@webkit.org | 6c25c52 | 2011-08-09 20:46:17 +0000 | [diff] [blame] | 84 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 85 | ExecutableBase* executable() const { return m_executable.get(); } |
barraclough@apple.com | 4be541c | 2010-05-20 02:38:01 +0000 | [diff] [blame] | 86 | |
keith_miller@apple.com | 59bba5d | 2015-10-16 22:18:42 +0000 | [diff] [blame^] | 87 | // To call any of these methods include JSFunctionInlines.h |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 88 | bool isHostFunction() const; |
| 89 | FunctionExecutable* jsExecutable() const; |
keith_miller@apple.com | 59bba5d | 2015-10-16 22:18:42 +0000 | [diff] [blame^] | 90 | Intrinsic intrinsic() const; |
mjs | a84805f | 2006-03-15 10:21:48 +0000 | [diff] [blame] | 91 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 92 | JS_EXPORT_PRIVATE const SourceCode* sourceCode() const; |
barraclough@apple.com | 12710b6 | 2009-08-21 21:54:20 +0000 | [diff] [blame] | 93 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 94 | DECLARE_EXPORT_INFO; |
weinig@apple.com | 0b4376b | 2008-11-28 02:24:20 +0000 | [diff] [blame] | 95 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 96 | static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) |
| 97 | { |
| 98 | ASSERT(globalObject); |
| 99 | return Structure::create(vm, globalObject, prototype, TypeInfo(JSFunctionType, StructureFlags), info()); |
| 100 | } |
yurys@chromium.org | 0114f05 | 2011-11-14 09:27:25 +0000 | [diff] [blame] | 101 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 102 | NativeFunction nativeFunction(); |
| 103 | NativeFunction nativeConstructor(); |
mjs | 308be5a | 2006-08-14 03:06:14 +0000 | [diff] [blame] | 104 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 105 | static ConstructType getConstructData(JSCell*, ConstructData&); |
| 106 | static CallType getCallData(JSCell*, CallData&); |
darin@apple.com | 74e6ed6 | 2008-10-23 00:11:11 +0000 | [diff] [blame] | 107 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 108 | static inline ptrdiff_t offsetOfExecutable() |
| 109 | { |
| 110 | return OBJECT_OFFSETOF(JSFunction, m_executable); |
| 111 | } |
mjs | 308be5a | 2006-08-14 03:06:14 +0000 | [diff] [blame] | 112 | |
commit-queue@webkit.org | cc894b0 | 2015-04-16 19:15:09 +0000 | [diff] [blame] | 113 | static inline ptrdiff_t offsetOfRareData() |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 114 | { |
commit-queue@webkit.org | cc894b0 | 2015-04-16 19:15:09 +0000 | [diff] [blame] | 115 | return OBJECT_OFFSETOF(JSFunction, m_rareData); |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 116 | } |
oliver@apple.com | e843bc0 | 2011-08-05 20:03:19 +0000 | [diff] [blame] | 117 | |
commit-queue@webkit.org | cc894b0 | 2015-04-16 19:15:09 +0000 | [diff] [blame] | 118 | FunctionRareData* rareData(ExecState* exec, unsigned inlineCapacity) |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 119 | { |
commit-queue@webkit.org | cc894b0 | 2015-04-16 19:15:09 +0000 | [diff] [blame] | 120 | if (UNLIKELY(!m_rareData)) |
commit-queue@webkit.org | a89ef27 | 2015-04-22 17:39:44 +0000 | [diff] [blame] | 121 | return allocateAndInitializeRareData(exec, inlineCapacity); |
| 122 | if (UNLIKELY(!m_rareData->isInitialized())) |
| 123 | return initializeRareData(exec, inlineCapacity); |
commit-queue@webkit.org | cc894b0 | 2015-04-16 19:15:09 +0000 | [diff] [blame] | 124 | return m_rareData.get(); |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 125 | } |
oliver@apple.com | e843bc0 | 2011-08-05 20:03:19 +0000 | [diff] [blame] | 126 | |
commit-queue@webkit.org | 311b1e1 | 2015-04-23 21:56:23 +0000 | [diff] [blame] | 127 | FunctionRareData* rareData() |
commit-queue@webkit.org | cc894b0 | 2015-04-16 19:15:09 +0000 | [diff] [blame] | 128 | { |
commit-queue@webkit.org | 311b1e1 | 2015-04-23 21:56:23 +0000 | [diff] [blame] | 129 | FunctionRareData* rareData = m_rareData.get(); |
commit-queue@webkit.org | a60da23 | 2015-04-21 18:50:16 +0000 | [diff] [blame] | 130 | |
commit-queue@webkit.org | 311b1e1 | 2015-04-23 21:56:23 +0000 | [diff] [blame] | 131 | // The JS thread may be concurrently creating the rare data |
| 132 | // If we see it, we want to ensure it has been properly created |
| 133 | WTF::loadLoadFence(); |
| 134 | |
| 135 | return rareData; |
commit-queue@webkit.org | cc894b0 | 2015-04-16 19:15:09 +0000 | [diff] [blame] | 136 | } |
barraclough@apple.com | cef11dc | 2012-05-10 18:40:29 +0000 | [diff] [blame] | 137 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 138 | bool isHostOrBuiltinFunction() const; |
| 139 | bool isBuiltinFunction() const; |
| 140 | JS_EXPORT_PRIVATE bool isHostFunctionNonInline() const; |
joepeck@webkit.org | 31c4650 | 2015-03-27 01:42:37 +0000 | [diff] [blame] | 141 | bool isClassConstructorFunction() const; |
barraclough@apple.com | cef11dc | 2012-05-10 18:40:29 +0000 | [diff] [blame] | 142 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 143 | protected: |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 144 | JS_EXPORT_PRIVATE JSFunction(VM&, JSGlobalObject*, Structure*); |
| 145 | JSFunction(VM&, FunctionExecutable*, JSScope*); |
commit-queue@webkit.org | a4201b0 | 2015-08-17 22:24:20 +0000 | [diff] [blame] | 146 | JSFunction(VM&, FunctionExecutable*, JSScope*, Structure*); |
oliver@apple.com | e9eda78 | 2009-10-17 01:06:40 +0000 | [diff] [blame] | 147 | |
commit-queue@webkit.org | fa19663 | 2015-08-28 21:07:22 +0000 | [diff] [blame] | 148 | #if ENABLE(WEBASSEMBLY) |
| 149 | JSFunction(VM&, WebAssemblyExecutable*, JSScope*); |
| 150 | #endif |
| 151 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 152 | void finishCreation(VM&, NativeExecutable*, int length, const String& name); |
| 153 | using Base::finishCreation; |
commit-queue@webkit.org | 53aecd2 | 2011-08-19 00:58:34 +0000 | [diff] [blame] | 154 | |
commit-queue@webkit.org | a89ef27 | 2015-04-22 17:39:44 +0000 | [diff] [blame] | 155 | FunctionRareData* allocateAndInitializeRareData(ExecState*, size_t inlineCapacity); |
| 156 | FunctionRareData* initializeRareData(ExecState*, size_t inlineCapacity); |
barraclough@apple.com | cef11dc | 2012-05-10 18:40:29 +0000 | [diff] [blame] | 157 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 158 | static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&); |
utatane.tea@gmail.com | 69af196 | 2015-04-02 18:53:32 +0000 | [diff] [blame] | 159 | static void getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode = EnumerationMode()); |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 160 | static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow); |
barraclough@apple.com | 2221566 | 2011-09-22 21:22:17 +0000 | [diff] [blame] | 161 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 162 | static void put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&); |
mhahnenberg@apple.com | 61a1171 | 2011-10-22 00:48:40 +0000 | [diff] [blame] | 163 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 164 | static bool deleteProperty(JSCell*, ExecState*, PropertyName); |
mhahnenberg@apple.com | c751c3e | 2011-10-24 00:21:52 +0000 | [diff] [blame] | 165 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 166 | static void visitChildren(JSCell*, SlotVisitor&); |
barraclough@apple.com | 2221566 | 2011-09-22 21:22:17 +0000 | [diff] [blame] | 167 | |
utatane.tea@gmail.com | 4218f53 | 2015-08-28 21:35:39 +0000 | [diff] [blame] | 168 | |
| 169 | static NativeExecutable* lookUpOrCreateNativeExecutable(VM&, NativeFunction, Intrinsic, NativeFunction nativeConstructor); |
| 170 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 171 | private: |
fpizlo@apple.com | 3a2fa4c | 2015-04-13 22:13:12 +0000 | [diff] [blame] | 172 | static JSFunction* createImpl(VM& vm, FunctionExecutable* executable, JSScope* scope) |
| 173 | { |
| 174 | JSFunction* function = new (NotNull, allocateCell<JSFunction>(vm.heap)) JSFunction(vm, executable, scope); |
| 175 | ASSERT(function->structure()->globalObject()); |
| 176 | function->finishCreation(vm); |
| 177 | return function; |
| 178 | } |
| 179 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 180 | friend class LLIntOffsetsExtractor; |
weinig@apple.com | 0e2d66e | 2008-07-06 05:26:58 +0000 | [diff] [blame] | 181 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 182 | static EncodedJSValue argumentsGetter(ExecState*, JSObject*, EncodedJSValue, PropertyName); |
| 183 | static EncodedJSValue callerGetter(ExecState*, JSObject*, EncodedJSValue, PropertyName); |
| 184 | static EncodedJSValue lengthGetter(ExecState*, JSObject*, EncodedJSValue, PropertyName); |
| 185 | static EncodedJSValue nameGetter(ExecState*, JSObject*, EncodedJSValue, PropertyName); |
| 186 | |
| 187 | WriteBarrier<ExecutableBase> m_executable; |
commit-queue@webkit.org | cc894b0 | 2015-04-16 19:15:09 +0000 | [diff] [blame] | 188 | WriteBarrier<FunctionRareData> m_rareData; |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 189 | }; |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 190 | |
ddkilzer@apple.com | f9f6bbd | 2009-01-02 20:59:17 +0000 | [diff] [blame] | 191 | } // namespace JSC |
mjs | 70d7421 | 2005-08-07 06:17:49 +0000 | [diff] [blame] | 192 | |
weinig@apple.com | 7dab465 | 2008-07-05 23:19:36 +0000 | [diff] [blame] | 193 | #endif // JSFunction_h |