weinig@apple.com | f0ea355 | 2008-07-01 01:11:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) |
mark.lam@apple.com | 7725e2a | 2019-02-27 05:43:34 +0000 | [diff] [blame] | 3 | * Copyright (C) 2003-2019 Apple Inc. All rights reserved. |
weinig@apple.com | f0ea355 | 2008-07-01 01:11:22 +0000 | [diff] [blame] | 4 | * Copyright (C) 2007 Cameron Zwarich (cwzwarich@uwaterloo.ca) |
| 5 | * Copyright (C) 2007 Maks Orlovich |
| 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 |
| 19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 | * Boston, MA 02110-1301, USA. |
| 21 | * |
| 22 | */ |
| 23 | |
ryanhaddad@apple.com | 22104f5 | 2016-09-28 17:08:17 +0000 | [diff] [blame] | 24 | #pragma once |
weinig@apple.com | f0ea355 | 2008-07-01 01:11:22 +0000 | [diff] [blame] | 25 | |
utatane.tea@gmail.com | 7ab015d | 2017-11-06 14:40:08 +0000 | [diff] [blame] | 26 | #include "CodeSpecializationKind.h" |
mhahnenberg@apple.com | 30738a7 | 2012-10-03 17:51:28 +0000 | [diff] [blame] | 27 | #include "JSDestructibleObject.h" |
weinig@apple.com | f0ea355 | 2008-07-01 01:11:22 +0000 | [diff] [blame] | 28 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 29 | namespace JSC { |
weinig@apple.com | f0ea355 | 2008-07-01 01:11:22 +0000 | [diff] [blame] | 30 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 31 | class FunctionPrototype; |
weinig@apple.com | f0ea355 | 2008-07-01 01:11:22 +0000 | [diff] [blame] | 32 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 33 | class InternalFunction : public JSDestructibleObject { |
utatane.tea@gmail.com | 7ab015d | 2017-11-06 14:40:08 +0000 | [diff] [blame] | 34 | friend class JIT; |
| 35 | friend class LLIntOffsetsExtractor; |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 36 | public: |
| 37 | typedef JSDestructibleObject Base; |
mark.lam@apple.com | d27553f | 2019-09-18 00:36:19 +0000 | [diff] [blame] | 38 | static constexpr unsigned StructureFlags = Base::StructureFlags | ImplementsHasInstance | ImplementsDefaultHasInstance | OverridesGetCallData; |
commit-queue@webkit.org | 6c25c52 | 2011-08-09 20:46:17 +0000 | [diff] [blame] | 39 | |
ysuzuki@apple.com | 64b74db | 2019-02-05 06:32:08 +0000 | [diff] [blame] | 40 | template<typename CellType, SubspaceAccess> |
fpizlo@apple.com | dcb592d | 2018-04-19 19:33:03 +0000 | [diff] [blame] | 41 | static IsoSubspace* subspaceFor(VM& vm) |
| 42 | { |
| 43 | static_assert(sizeof(CellType) == sizeof(InternalFunction), "InternalFunction subclasses that add fields need to override subspaceFor<>()"); |
| 44 | return &vm.internalFunctionSpace; |
| 45 | } |
| 46 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 47 | DECLARE_EXPORT_INFO; |
mrowe@apple.com | db57abe | 2008-09-30 19:38:36 +0000 | [diff] [blame] | 48 | |
mark.lam@apple.com | ac502b3 | 2016-03-09 00:01:09 +0000 | [diff] [blame] | 49 | JS_EXPORT_PRIVATE static void visitChildren(JSCell*, SlotVisitor&); |
| 50 | |
fpizlo@apple.com | cff2d0c | 2016-05-04 21:21:36 +0000 | [diff] [blame] | 51 | JS_EXPORT_PRIVATE const String& name(); |
mark.lam@apple.com | d14283b | 2016-06-07 19:51:41 +0000 | [diff] [blame] | 52 | const String displayName(VM&); |
| 53 | const String calculatedDisplayName(VM&); |
weinig@apple.com | f0ea355 | 2008-07-01 01:11:22 +0000 | [diff] [blame] | 54 | |
keith_miller@apple.com | 6bd2435 | 2016-01-11 22:40:00 +0000 | [diff] [blame] | 55 | static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto) |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 56 | { |
utatane.tea@gmail.com | 7ab015d | 2017-11-06 14:40:08 +0000 | [diff] [blame] | 57 | return Structure::create(vm, globalObject, proto, TypeInfo(InternalFunctionType, StructureFlags), info()); |
darin@apple.com | 5a49442 | 2008-10-18 23:08:12 +0000 | [diff] [blame] | 58 | } |
| 59 | |
utatane.tea@gmail.com | 62a4685 | 2017-05-27 23:21:53 +0000 | [diff] [blame] | 60 | static Structure* createSubclassStructure(ExecState*, JSValue newTarget, Structure*); |
ysuzuki@apple.com | 48d4e53 | 2019-09-05 01:23:46 +0000 | [diff] [blame] | 61 | static Structure* createSubclassStructure(ExecState*, JSObject* baseCallee, JSValue newTarget, Structure*); |
keith_miller@apple.com | 3793b13 | 2016-01-11 21:31:04 +0000 | [diff] [blame] | 62 | |
mark.lam@apple.com | a925f8a | 2018-03-12 21:06:42 +0000 | [diff] [blame] | 63 | TaggedNativeFunction nativeFunctionFor(CodeSpecializationKind kind) |
utatane.tea@gmail.com | 7ab015d | 2017-11-06 14:40:08 +0000 | [diff] [blame] | 64 | { |
| 65 | if (kind == CodeForCall) |
mark.lam@apple.com | 7725e2a | 2019-02-27 05:43:34 +0000 | [diff] [blame] | 66 | return m_functionForCall; |
utatane.tea@gmail.com | 7ab015d | 2017-11-06 14:40:08 +0000 | [diff] [blame] | 67 | ASSERT(kind == CodeForConstruct); |
mark.lam@apple.com | 7725e2a | 2019-02-27 05:43:34 +0000 | [diff] [blame] | 68 | return m_functionForConstruct; |
utatane.tea@gmail.com | 7ab015d | 2017-11-06 14:40:08 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static ptrdiff_t offsetOfNativeFunctionFor(CodeSpecializationKind kind) |
| 72 | { |
| 73 | if (kind == CodeForCall) |
| 74 | return OBJECT_OFFSETOF(InternalFunction, m_functionForCall); |
| 75 | ASSERT(kind == CodeForConstruct); |
| 76 | return OBJECT_OFFSETOF(InternalFunction, m_functionForConstruct); |
| 77 | } |
| 78 | |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 79 | protected: |
utatane.tea@gmail.com | 7ab015d | 2017-11-06 14:40:08 +0000 | [diff] [blame] | 80 | JS_EXPORT_PRIVATE InternalFunction(VM&, Structure*, NativeFunction functionForCall, NativeFunction functionForConstruct); |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 81 | |
utatane.tea@gmail.com | 1fd8292 | 2017-09-01 06:40:55 +0000 | [diff] [blame] | 82 | enum class NameVisibility { Visible, Anonymous }; |
ysuzuki@apple.com | 5f05b1e | 2019-03-08 19:33:51 +0000 | [diff] [blame] | 83 | enum class NameAdditionMode { WithStructureTransition, WithoutStructureTransition }; |
| 84 | JS_EXPORT_PRIVATE void finishCreation(VM&, const String& name, NameVisibility = NameVisibility::Visible, NameAdditionMode = NameAdditionMode::WithStructureTransition); |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 85 | |
utatane.tea@gmail.com | 62a4685 | 2017-05-27 23:21:53 +0000 | [diff] [blame] | 86 | JS_EXPORT_PRIVATE static Structure* createSubclassStructureSlow(ExecState*, JSValue newTarget, Structure*); |
| 87 | |
utatane.tea@gmail.com | 7ab015d | 2017-11-06 14:40:08 +0000 | [diff] [blame] | 88 | JS_EXPORT_PRIVATE static ConstructType getConstructData(JSCell*, ConstructData&); |
| 89 | JS_EXPORT_PRIVATE static CallType getCallData(JSCell*, CallData&); |
| 90 | |
mark.lam@apple.com | 7725e2a | 2019-02-27 05:43:34 +0000 | [diff] [blame] | 91 | TaggedNativeFunction m_functionForCall; |
| 92 | TaggedNativeFunction m_functionForConstruct; |
mark.lam@apple.com | ac502b3 | 2016-03-09 00:01:09 +0000 | [diff] [blame] | 93 | WriteBarrier<JSString> m_originalName; |
mark.lam@apple.com | 188640e | 2014-09-04 19:10:36 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
utatane.tea@gmail.com | 62a4685 | 2017-05-27 23:21:53 +0000 | [diff] [blame] | 96 | ALWAYS_INLINE Structure* InternalFunction::createSubclassStructure(ExecState* exec, JSValue newTarget, Structure* baseClass) |
| 97 | { |
ysuzuki@apple.com | 48d4e53 | 2019-09-05 01:23:46 +0000 | [diff] [blame] | 98 | return createSubclassStructure(exec, exec->jsCallee(), newTarget, baseClass); |
| 99 | } |
| 100 | |
| 101 | ALWAYS_INLINE Structure* InternalFunction::createSubclassStructure(ExecState* exec, JSObject* baseCallee, JSValue newTarget, Structure* baseClass) |
| 102 | { |
utatane.tea@gmail.com | 62a4685 | 2017-05-27 23:21:53 +0000 | [diff] [blame] | 103 | // We allow newTarget == JSValue() because the API needs to be able to create classes without having a real JS frame. |
| 104 | // Since we don't allow subclassing in the API we just treat newTarget == JSValue() as newTarget == exec->jsCallee() |
ysuzuki@apple.com | 48d4e53 | 2019-09-05 01:23:46 +0000 | [diff] [blame] | 105 | if (newTarget && newTarget != baseCallee) |
utatane.tea@gmail.com | 62a4685 | 2017-05-27 23:21:53 +0000 | [diff] [blame] | 106 | return createSubclassStructureSlow(exec, newTarget, baseClass); |
| 107 | return baseClass; |
| 108 | } |
| 109 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 110 | } // namespace JSC |