1 | /* |
2 | * Copyright (C) 2014 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 | #pragma once |
27 | |
28 | #include "JSGlobalObject.h" |
29 | #include "JSObject.h" |
30 | #include "JSScope.h" |
31 | |
32 | namespace JSC { |
33 | |
34 | class JSGlobalObject; |
35 | class ; |
36 | |
37 | |
38 | class JSCallee : public JSNonFinalObject { |
39 | friend class JIT; |
40 | #if ENABLE(DFG_JIT) |
41 | friend class DFG::SpeculativeJIT; |
42 | friend class DFG::JITCompiler; |
43 | #endif |
44 | friend class VM; |
45 | |
46 | public: |
47 | typedef JSNonFinalObject Base; |
48 | const static unsigned StructureFlags = Base::StructureFlags | ImplementsHasInstance | ImplementsDefaultHasInstance; |
49 | |
50 | static JSCallee* create(VM& vm, JSGlobalObject* globalObject, JSScope* scope) |
51 | { |
52 | JSCallee* callee = new (NotNull, allocateCell<JSCallee>(vm.heap)) JSCallee(vm, scope, globalObject->calleeStructure()); |
53 | callee->finishCreation(vm); |
54 | return callee; |
55 | } |
56 | |
57 | JSScope* scope() |
58 | { |
59 | return m_scope.get(); |
60 | } |
61 | |
62 | // This method may be called for host functions, in which case it |
63 | // will return an arbitrary value. This should only be used for |
64 | // optimized paths in which the return value does not matter for |
65 | // host functions, and checking whether the function is a host |
66 | // function is deemed too expensive. |
67 | JSScope* scopeUnchecked() |
68 | { |
69 | return m_scope.get(); |
70 | } |
71 | |
72 | void setScope(VM& vm, JSScope* scope) |
73 | { |
74 | m_scope.set(vm, this, scope); |
75 | } |
76 | |
77 | DECLARE_EXPORT_INFO; |
78 | |
79 | static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) |
80 | { |
81 | ASSERT(globalObject); |
82 | return Structure::create(vm, globalObject, prototype, TypeInfo(JSCalleeType, StructureFlags), info()); |
83 | } |
84 | |
85 | static inline ptrdiff_t offsetOfScopeChain() |
86 | { |
87 | return OBJECT_OFFSETOF(JSCallee, m_scope); |
88 | } |
89 | |
90 | protected: |
91 | JS_EXPORT_PRIVATE JSCallee(VM&, JSGlobalObject*, Structure*); |
92 | JSCallee(VM&, JSScope*, Structure*); |
93 | |
94 | void finishCreation(VM&); |
95 | using Base::finishCreation; |
96 | |
97 | static void visitChildren(JSCell*, SlotVisitor&); |
98 | |
99 | private: |
100 | friend class LLIntOffsetsExtractor; |
101 | |
102 | WriteBarrier<JSScope> m_scope; |
103 | }; |
104 | |
105 | } // namespace JSC |
106 | |