1/*
2 * Copyright (C) 2014, 2016 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#include "config.h"
27#include "JSJavaScriptCallFramePrototype.h"
28
29#include "Error.h"
30#include "Identifier.h"
31#include "JSCInlines.h"
32#include "JSFunction.h"
33#include "JSJavaScriptCallFrame.h"
34
35using namespace JSC;
36
37namespace Inspector {
38
39// Functions.
40static EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFramePrototypeFunctionEvaluateWithScopeExtension(JSGlobalObject*, CallFrame*);
41static EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFramePrototypeFunctionScopeDescriptions(JSGlobalObject*, CallFrame*);
42
43// Attributes.
44static EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameAttributeCaller(JSGlobalObject*, CallFrame*);
45static EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameAttributeSourceID(JSGlobalObject*, CallFrame*);
46static EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameAttributeLine(JSGlobalObject*, CallFrame*);
47static EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameAttributeColumn(JSGlobalObject*, CallFrame*);
48static EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameAttributeFunctionName(JSGlobalObject*, CallFrame*);
49static EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameAttributeScopeChain(JSGlobalObject*, CallFrame*);
50static EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameAttributeThisObject(JSGlobalObject*, CallFrame*);
51static EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameAttributeType(JSGlobalObject*, CallFrame*);
52static EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameIsTailDeleted(JSGlobalObject*, CallFrame*);
53
54const ClassInfo JSJavaScriptCallFramePrototype::s_info = { "JavaScriptCallFrame", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSJavaScriptCallFramePrototype) };
55
56void JSJavaScriptCallFramePrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
57{
58 Base::finishCreation(vm);
59 ASSERT(inherits(vm, info()));
60
61 JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("evaluateWithScopeExtension", jsJavaScriptCallFramePrototypeFunctionEvaluateWithScopeExtension, static_cast<unsigned>(PropertyAttribute::DontEnum), 1);
62 JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("scopeDescriptions", jsJavaScriptCallFramePrototypeFunctionScopeDescriptions, static_cast<unsigned>(PropertyAttribute::DontEnum), 0);
63
64 JSC_NATIVE_GETTER_WITHOUT_TRANSITION("caller", jsJavaScriptCallFrameAttributeCaller, PropertyAttribute::DontEnum | PropertyAttribute::Accessor);
65 JSC_NATIVE_GETTER_WITHOUT_TRANSITION("sourceID", jsJavaScriptCallFrameAttributeSourceID, PropertyAttribute::DontEnum | PropertyAttribute::Accessor);
66 JSC_NATIVE_GETTER_WITHOUT_TRANSITION("line", jsJavaScriptCallFrameAttributeLine, PropertyAttribute::DontEnum | PropertyAttribute::Accessor);
67 JSC_NATIVE_GETTER_WITHOUT_TRANSITION("column", jsJavaScriptCallFrameAttributeColumn, PropertyAttribute::DontEnum | PropertyAttribute::Accessor);
68 JSC_NATIVE_GETTER_WITHOUT_TRANSITION("functionName", jsJavaScriptCallFrameAttributeFunctionName, PropertyAttribute::DontEnum | PropertyAttribute::Accessor);
69 JSC_NATIVE_GETTER_WITHOUT_TRANSITION("scopeChain", jsJavaScriptCallFrameAttributeScopeChain, PropertyAttribute::DontEnum | PropertyAttribute::Accessor);
70 JSC_NATIVE_GETTER_WITHOUT_TRANSITION("thisObject", jsJavaScriptCallFrameAttributeThisObject, PropertyAttribute::DontEnum | PropertyAttribute::Accessor);
71 JSC_NATIVE_GETTER_WITHOUT_TRANSITION("type", jsJavaScriptCallFrameAttributeType, PropertyAttribute::DontEnum | PropertyAttribute::Accessor);
72 JSC_NATIVE_GETTER_WITHOUT_TRANSITION("isTailDeleted", jsJavaScriptCallFrameIsTailDeleted, PropertyAttribute::DontEnum | PropertyAttribute::Accessor);
73}
74
75EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFramePrototypeFunctionEvaluateWithScopeExtension(JSGlobalObject* globalObject, CallFrame* callFrame)
76{
77 VM& vm = globalObject->vm();
78 auto scope = DECLARE_THROW_SCOPE(vm);
79
80 JSValue thisValue = callFrame->thisValue();
81 JSJavaScriptCallFrame* castedThis = jsDynamicCast<JSJavaScriptCallFrame*>(vm, thisValue);
82 if (!castedThis)
83 return throwVMTypeError(globalObject, scope);
84
85 return JSValue::encode(castedThis->evaluateWithScopeExtension(globalObject, callFrame));
86}
87
88EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFramePrototypeFunctionScopeDescriptions(JSGlobalObject* globalObject, CallFrame* callFrame)
89{
90 VM& vm = globalObject->vm();
91 auto scope = DECLARE_THROW_SCOPE(vm);
92
93 JSValue thisValue = callFrame->thisValue();
94 JSJavaScriptCallFrame* castedThis = jsDynamicCast<JSJavaScriptCallFrame*>(vm, thisValue);
95 if (!castedThis)
96 return throwVMTypeError(globalObject, scope);
97
98 return JSValue::encode(castedThis->scopeDescriptions(globalObject));
99}
100
101EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameAttributeCaller(JSGlobalObject* globalObject, CallFrame* callFrame)
102{
103 VM& vm = globalObject->vm();
104 auto scope = DECLARE_THROW_SCOPE(vm);
105
106 JSValue thisValue = callFrame->thisValue();
107 JSJavaScriptCallFrame* castedThis = jsDynamicCast<JSJavaScriptCallFrame*>(vm, thisValue);
108 if (!castedThis)
109 return throwVMTypeError(globalObject, scope);
110
111 return JSValue::encode(castedThis->caller(globalObject));
112}
113
114EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameAttributeSourceID(JSGlobalObject* globalObject, CallFrame* callFrame)
115{
116 VM& vm = globalObject->vm();
117 auto scope = DECLARE_THROW_SCOPE(vm);
118
119 JSValue thisValue = callFrame->thisValue();
120 JSJavaScriptCallFrame* castedThis = jsDynamicCast<JSJavaScriptCallFrame*>(vm, thisValue);
121 if (!castedThis)
122 return throwVMTypeError(globalObject, scope);
123
124 return JSValue::encode(castedThis->sourceID(globalObject));
125}
126
127EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameAttributeLine(JSGlobalObject* globalObject, CallFrame* callFrame)
128{
129 VM& vm = globalObject->vm();
130 auto scope = DECLARE_THROW_SCOPE(vm);
131
132 JSValue thisValue = callFrame->thisValue();
133 JSJavaScriptCallFrame* castedThis = jsDynamicCast<JSJavaScriptCallFrame*>(vm, thisValue);
134 if (!castedThis)
135 return throwVMTypeError(globalObject, scope);
136
137 return JSValue::encode(castedThis->line(globalObject));
138}
139
140EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameAttributeColumn(JSGlobalObject* globalObject, CallFrame* callFrame)
141{
142 VM& vm = globalObject->vm();
143 auto scope = DECLARE_THROW_SCOPE(vm);
144
145 JSValue thisValue = callFrame->thisValue();
146 JSJavaScriptCallFrame* castedThis = jsDynamicCast<JSJavaScriptCallFrame*>(vm, thisValue);
147 if (!castedThis)
148 return throwVMTypeError(globalObject, scope);
149
150 return JSValue::encode(castedThis->column(globalObject));
151}
152
153EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameAttributeFunctionName(JSGlobalObject* globalObject, CallFrame* callFrame)
154{
155 VM& vm = globalObject->vm();
156 auto scope = DECLARE_THROW_SCOPE(vm);
157
158 JSValue thisValue = callFrame->thisValue();
159 JSJavaScriptCallFrame* castedThis = jsDynamicCast<JSJavaScriptCallFrame*>(vm, thisValue);
160 if (!castedThis)
161 return throwVMTypeError(globalObject, scope);
162
163 return JSValue::encode(castedThis->functionName(globalObject));
164}
165
166EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameAttributeScopeChain(JSGlobalObject* globalObject, CallFrame* callFrame)
167{
168 VM& vm = globalObject->vm();
169 auto scope = DECLARE_THROW_SCOPE(vm);
170
171 JSValue thisValue = callFrame->thisValue();
172 JSJavaScriptCallFrame* castedThis = jsDynamicCast<JSJavaScriptCallFrame*>(vm, thisValue);
173 if (!castedThis)
174 return throwVMTypeError(globalObject, scope);
175
176 return JSValue::encode(castedThis->scopeChain(globalObject));
177}
178
179EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameAttributeThisObject(JSGlobalObject* globalObject, CallFrame* callFrame)
180{
181 VM& vm = globalObject->vm();
182 auto scope = DECLARE_THROW_SCOPE(vm);
183
184 JSValue thisValue = callFrame->thisValue();
185 JSJavaScriptCallFrame* castedThis = jsDynamicCast<JSJavaScriptCallFrame*>(vm, thisValue);
186 if (!castedThis)
187 return throwVMTypeError(globalObject, scope);
188
189 return JSValue::encode(castedThis->thisObject(globalObject));
190}
191
192EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameAttributeType(JSGlobalObject* globalObject, CallFrame* callFrame)
193{
194 VM& vm = globalObject->vm();
195 auto scope = DECLARE_THROW_SCOPE(vm);
196
197 JSValue thisValue = callFrame->thisValue();
198 JSJavaScriptCallFrame* castedThis = jsDynamicCast<JSJavaScriptCallFrame*>(vm, thisValue);
199 if (!castedThis)
200 return throwVMTypeError(globalObject, scope);
201
202 return JSValue::encode(castedThis->type(globalObject));
203}
204
205EncodedJSValue JSC_HOST_CALL jsJavaScriptCallFrameIsTailDeleted(JSGlobalObject* globalObject, CallFrame* callFrame)
206{
207 VM& vm = globalObject->vm();
208 auto scope = DECLARE_THROW_SCOPE(vm);
209
210 JSValue thisValue = callFrame->thisValue();
211 JSJavaScriptCallFrame* castedThis = jsDynamicCast<JSJavaScriptCallFrame*>(vm, thisValue);
212 if (!castedThis)
213 return throwVMTypeError(globalObject, scope);
214
215 return JSValue::encode(castedThis->isTailDeleted(globalObject));
216}
217
218} // namespace Inspector
219